× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



It works in embedded SQL
... but since it is my example, I'd always suggest to wrap the SQL Statement
in a view.
... and then you can handle the view like any table
... even in CL.

Mit freundlichen Grüßen / Best regards

Birgitta Hauser


"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)


-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Gad
Miron
Sent: Montag, 5. Juli 2021 12:47
To: midrange-l@xxxxxxxxxxxxxxxxxx
Subject: Re: SQL to read CSV file

Thanks Joep, Alan

STRSQL it was.

Tried ACS and it works fine .

Now, will it work in SQLRPGLE program, CLLE with RUNSQL program?


Thanks
Gad


date: Mon, 5 Jul 2021 11:35:11 +0300
from: Gad Miron <gadmiron@xxxxxxxxx>
subject: Re: SQL to read CSV file

Hello guys

Testing IFS_READ_UTF8 / IFS_READ
when issuing
select * from table(IFS_READ('/GAD/ABC.txt')) I get *POINTER *POINTER
*POINTER *POINTER etc.

What am I doing wrong?

TIA
Gad



date: Sat, 19 Jun 2021 12:41:48 +0200
from: "Birgitta Hauser" <Hauser@xxxxxxxxxxxxxxx>
subject: RE: SQL to read CSV file

Hi Justin,

So in your example the IFS_READ will return multiple rows depending
on
how
many CRLF characters are in your IFS File.
The SPLIT() Function splits at the passed delimiter, it does not
check whether the delimiter is embedded in double quotes or not.
If your *.CSV file consists only of "strings" you may pass the
delimiter ","
to the SPLIT functions. In this case also the leading and trailing
double quotes are removed.
If you need to check if the delimiter is embedded in a "string" or
not,
you
may (as others already suggested) do a reverse engineering, and
retrieve the source code for the SPLIT function (it is not
obfuscated), modify it and create your own SPLIT-Function.

Here is an example how you can read a *.csv file directly from the
IFS
and
split the result into columns. It even removes the leading and
trailing double quotes from a string and converts a few columns into
non-character data types.
... but it uses the original SPLIT function.
With x as (Select * from
Table(IFS_READ_UTF8('/home/YourDir1/YourDir2/YourCsvFile.csv'))),
y as (Select x.*, Ordinal_Position ColKey,
Trim(B '"' from Element) as ColInfo
from x cross join Table(Split(Line, ','))) Select
Line_Number,
Min(Case When ColKey = 1 Then ColInfo End) Your1Col,
Min(Case When ColKey = 2 Then ColInfo End) Your2Col,
Min(Case When ColKey = 3 Then ColInfo End) Your3Col,
Min(Case When ColKey = 4 Then Date(ColInfo) End) Your4Col,
Min(Case When ColKey = 5 Then Dec(ColInfo, 11, 2) End) Your5Col,
Min(Case When ColKey = 6 Then ColInfo End) Your6Col,
Min(Case When ColKey = 7 Then ColInfo End) Your7Col
From y
Group By Line_Number
Order By Line_Number

Mit freundlichen Gr??en / Best regards

Birgitta Hauser





------------------------------

message: 3
date: Mon, 5 Jul 2021 10:43:07 +0200
from: Joep Beckeringh via MIDRANGE-L <midrange-l@xxxxxxxxxxxxxxxxxx>
subject: Re: SQL to read CSV file

Using 5250 / STRSQL. Try Run SQL Scripts (ACS).

Joep Beckeringh


Op 5-7-2021 om 10:35 schreef Gad Miron:
Hello guys

Testing IFS_READ_UTF8 / IFS_READ
when issuing
select * from table(IFS_READ('/GAD/ABC.txt')) I get *POINTER
*POINTER *POINTER *POINTER etc.

What am I doing wrong?

TIA
Gad


date: Sat, 19 Jun 2021 12:41:48 +0200
from: "Birgitta Hauser" <Hauser@xxxxxxxxxxxxxxx>
subject: RE: SQL to read CSV file

Hi Justin,

So in your example the IFS_READ will return multiple rows depending
on
how
many CRLF characters are in your IFS File.
The SPLIT() Function splits at the passed delimiter, it does not
check whether the delimiter is embedded in double quotes or not.
If your *.CSV file consists only of "strings" you may pass the
delimiter ","
to the SPLIT functions. In this case also the leading and trailing
double
quotes are removed.
If you need to check if the delimiter is embedded in a "string" or
not,
you
may (as others already suggested) do a reverse engineering, and
retrieve the source code for the SPLIT function (it is not
obfuscated), modify it and create your own SPLIT-Function.

Here is an example how you can read a *.csv file directly from the
IFS
and
split the result into columns. It even removes the leading and
trailing double quotes from a string and converts a few columns
into
non-character
data types.
... but it uses the original SPLIT function.
With x as (Select * from
Table(IFS_READ_UTF8('/home/YourDir1/YourDir2/YourCsvFile.csv'))),
y as (Select x.*, Ordinal_Position ColKey,
Trim(B '"' from Element) as ColInfo
from x cross join Table(Split(Line, ','))) Select
Line_Number,
Min(Case When ColKey = 1 Then ColInfo End) Your1Col,
Min(Case When ColKey = 2 Then ColInfo End) Your2Col,
Min(Case When ColKey = 3 Then ColInfo End) Your3Col,
Min(Case When ColKey = 4 Then Date(ColInfo) End) Your4Col,
Min(Case When ColKey = 5 Then Dec(ColInfo, 11, 2) End)
Your5Col,
Min(Case When ColKey = 6 Then ColInfo End) Your6Col,
Min(Case When ColKey = 7 Then ColInfo End) Your7Col
From y
Group By Line_Number
Order By Line_Number

Mit freundlichen Gr??en / Best regards

Birgitta Hauser





------------------------------

message: 4
date: Mon, 5 Jul 2021 08:44:49 +0000
from: Alan Shore via MIDRANGE-L <midrange-l@xxxxxxxxxxxxxxxxxx>
subject: RE: [EXTERNAL] Re: SQL to read CSV file

This looks familiar
Are you running this under strsql or in ACS sql scripts?
I am guessing strsql
Probably need to use ACS




Sent via the Samsung GALAXY S? 5, an AT&T 4G LTE smartphone


-------- Original message --------
From: Gad Miron <gadmiron@xxxxxxxxx>
Date: 7/5/21 04:36 (GMT-05:00)
To: midrange-l@xxxxxxxxxxxxxxxxxx
Subject: [EXTERNAL] Re: SQL to read CSV file

Hello guys

Testing IFS_READ_UTF8 / IFS_READ
when issuing
select * from table(IFS_READ('/GAD/ABC.txt')) I get *POINTER *POINTER
*POINTER *POINTER etc.

What am I doing wrong?

TIA
Gad



date: Sat, 19 Jun 2021 12:41:48 +0200
from: "Birgitta Hauser" <Hauser@xxxxxxxxxxxxxxx>
subject: RE: SQL to read CSV file

Hi Justin,

So in your example the IFS_READ will return multiple rows depending
on
how
many CRLF characters are in your IFS File.
The SPLIT() Function splits at the passed delimiter, it does not
check whether the delimiter is embedded in double quotes or not.
If your *.CSV file consists only of "strings" you may pass the
delimiter ","
to the SPLIT functions. In this case also the leading and trailing
double quotes are removed.
If you need to check if the delimiter is embedded in a "string" or
not,
you
may (as others already suggested) do a reverse engineering, and
retrieve the source code for the SPLIT function (it is not
obfuscated), modify it and create your own SPLIT-Function.

Here is an example how you can read a *.csv file directly from the
IFS
and
split the result into columns. It even removes the leading and
trailing double quotes from a string and converts a few columns into
non-character data types.
... but it uses the original SPLIT function.
With x as (Select * from
Table(IFS_READ_UTF8('/home/YourDir1/YourDir2/YourCsvFile.csv'))),
y as (Select x.*, Ordinal_Position ColKey, Trim(B '"' from Element)
as ColInfo from x cross join Table(Split(Line, ','))) Select
Line_Number, Min(Case When ColKey = 1 Then ColInfo End) Your1Col,
Min(Case When ColKey = 2 Then ColInfo End) Your2Col, Min(Case When
ColKey = 3 Then ColInfo End) Your3Col, Min(Case When ColKey = 4 Then
Date(ColInfo) End) Your4Col, Min(Case When ColKey = 5 Then
Dec(ColInfo, 11, 2) End) Your5Col, Min(Case When ColKey = 6 Then
ColInfo End) Your6Col, Min(Case When ColKey = 7 Then ColInfo End)
Your7Col
From y
Group By Line_Number
Order By Line_Number

Mit freundlichen Gr??en / Best regards

Birgitta Hauser



--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l<
https://lists.midrange.com/mailman/listinfo/midrange-l>
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l<
https://archive.midrange.com/midrange-l>.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com<https://amazon.midrange.com>


------------------------------

Subject: Digest Footer

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) digest
list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


------------------------------

End of MIDRANGE-L Digest, Vol 20, Issue 939
*******************************************

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.