FLAT file AS400

How to read a flat file and get data in as400??
kishore murarisettyAsked:
Who is Participating?
 
shalomcCTOCommented:
Is the flat file in a library?
Is it in IFS?
Is it a fixed format or a delimited file?

I guess that the Copy From Import File (CPYFRMIMPF) command is what you are looking for.

Example to copy a comma separated file with column names:
CPYFRMIMPF   FROMSTMF('/uploads/somefile.csv') TOFILE(mylibrary/myfile)  FLDDLM(',') STRDLM(*DBLQUOTE) RMVCOLNAM(*YES)

Open in new window

0
 
MurpheyApplication ConsultantCommented:
Hi kishore murarisetty;

A flatfile is just a file without a layout definition, as Shalomc stated, it can be stored on different places.
The way to read is depending on the place where it is stored.
In libararies, you can read it the standard RPG or CL way.
When it is on the IFS, most of the times you will use an API,
in some cases you an copy it to an Flatfile in a library and process it from there.

Good luck
1
 
shalomcCTOCommented:
Alternatively, you may want to access flat file in IFS from a program.
Scott Klement wrote an ebook about IFS processing, here is a link to the chapter dealing with reading flat files from IFS in RPGIV.
https://www.scottklement.com/rpg/ifs_ebook/textreading.html
0
 
Gary PattersonVP Technology / Senior Consultant Commented:
Short answer:  it depends.

It depends on the format of the flat file, and the format of the AS/400 target.  If the flat file was specifically designed to "match" an IBM i DB2 table, you may be able to just use CPYFRMIMPF to directly import.

But if the flat file wasn't specifically designed to match, or if it needs to be extracted to multiple tables, or if there is complex data conversion that needs to happen, then you may have to write a program.  Or maybe you don't need to populate a table at all - you didn't provide much information for us to go on.

It would be useful if you could provide a sample of the flat file, any documentation relevant to the layout of the flat file, and the layout of the target IBM i DB2 table(s) that you want to populate from the flat file, or a description of what you need to do with the flat file, including what programming language (if any) you plan to use for any coding.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.