FLAT file AS400

How to read a flat file and get data in as400??
kishore murarisettyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shalom CarmelCTOCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Theo KouwenhovenApplication 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
Shalom CarmelCTOCommented:
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.
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.