hi Charlie,
On 1/11/2012 10:19 AM, Versfelt, Charles wrote:
I have a CL program that copies a CSV file an iSeries flat file using
a simple CPYFRMSTMF statement.
CPYFRMSTMF FROMSTMF('/HOME/CHARLIE/ARAMEX.CSV')
TOMBR('qsys.lib/qtemp.lib/IL201UFL.file/IL201UFL.mbr') MBROPT(*REPLACE)
The program then calls an RPG that parses the flat file, using column headings to map.
I think you're saying that you don't use CPYFRMIMPF, but use CPYFRMSTMF
instead because you (or someone you work with) prefer to interpret the
contents of the file yourself in program logic.
When you say "using column headings to map", I assume that means that
your CSV file doesn't correspond directly to a database file layout, but
instead, fields are "mapped" by comparing the column headings to
database file field names. If so, that's a good reason not to use
CPYFRMIMPF, as it does not have that sort of mapping capability.
It works... as long as there are no commas in the data!
But, alas, there are commas in the data. So parsing is an issue...
FWIW (and I'm definitely NOT trying to convince you to stick with
commas, which are clumsy... but...) This is normally solved in CSV by
putting double-quotes around the text fields. For example:
12345,"Klement, Scott", "IT Department"
In this case, the comma in "Klement, Scott" would not be treated as a
field delimiter because of the double-quotes.
I do agree that it's easier to use a delimiter that won't appear in the
data. Using bars (though, I've always heard them called "pipes", but
same thing...) or tabs is a common practice for this.
It was suggested I switch to bar delimiters, but as far as I can tell
CPYFRMSTMF doesn't have that option.
Charlie, you aren't thinking!
CPYFRMSTMF isn't what divides your record into fields! That's handled
by the aforementioned RPG program. All you have to do is change that
RPG program to look for pipes ("bars") instead of commans...
CPYFRMSTMF never divides anything into fields, so it doesn't know about
bars, but it also doesn't know about commas or anything else. You're
using an RPG program to do this, instead... But, you seem to have
forgotten that tidbit!
When I try to do a CPYFRMIMPF instead...
CPYFRMIMPF FROMSTMF('/HOME/CHARLIE/ARAMEX.CSV') TOFILE(QTEMP/IL201UFL
IL201UFL) RCDDLM(*CRLF) FLDDLM('|') RPLNULLVAL(*FLDDFT)
MBROPT(*REPLACE)
It's certainly possible to have CPYFRMIMPF divide your data into fields,
but it has no facility to map fields based on the column headings, so
you'll lose that capability.
I get garbage. I've tried playing with the RCDDLM which has not
helped. Is it not translating the *ASCII to *EBCDIC?
CPYFRMIMPF can certainly translate ASCII/EBCDIC (though that has nothing
to do with RCDDLM... WTF?) I use it to do this without any problems...
you may be doing something wrong.
I guess we could help you troubleshoot that if you want to.,.. but it
seems to me that you're using this becuase you've forgotten that it's
the RPG program that divides the data into fields...
As an Amazon Associate we earn from qualifying purchases.