On Fri, Aug 16, 2013 at 1:42 AM, Luis Rodriguez <luisro58@xxxxxxxxx> wrote:
I had never thought of using SQL in order to read a stream file until I saw
your posts. I have to admit that the idea looks very interesting and hope
to get a little free time in order to check it out.
Birgitta's article (which I've only briefly skimmed) seems
well-written and informative, as I think most of us have come to
expect from her. However, it's not something you can check out if you
only have "a little free time" as it's quite long and detailed. Which
is also to be expected, given the nature of the tools being used.
If you really only have a *little* free time, I seriously recommend
looking at Python instead. iSeriesPython is free, easily installable,
doesn't require any interaction with PASE (at least as far as you are
concerned), and crucially: handles both IFS stream and QSYS.LIB files
effortlessly. The latter can be manipulated via SQL or native RLA.
And for the specific task of parsing CSVs, it has the added cherry on
top of including a CSV library so you don't have to roll your own.
Don't forget that you have to beware of delimiter characters embedded
in the literal data (which is kind of how this thread started), and if
the CSV comes from Excel (or programs that use Excel's conventions),
you have to be careful about handling quotes as well as field
delimiters. Python's CSV module takes care of all of that for you.
If all your fields happen to be text, I can give you iSeriesPython
code to copy CSV to PF right here, in 7 lines:
import csv
pf = File400('OUTPUTPF', 'a')
with open('input.csv', 'r') as f:
for row in csv.reader(f):
for i in range(pf.fieldCount()):
pf.set(i, row[i])
pf.write()
That's it! It's not hard to extend that to check the PF field types
and coerce the CSV values accordingly.
John
As an Amazon Associate we earn from qualifying purchases.