Problem : convert as 400 .mbr file to flat file

Problem : convert as 400 .mbr file to flat file

I need to convert multiple .mbr files to a flat file that can be imported into a sql database


 

Solution: convert as 400 .mbr file to flat file

If you want 9 stream files in the example above (a streaming file is something else), you’d execute the CPYTIOMPF command nine times, once for each member.  A stream file is a file that is just a stream of characters, with no inherent organization.

You can create a folder in the IFS for your stream files using the green-screen command:

MD ‘/myfoldername’

Don’t forget the quotes.

You’ll need to know the names of all the files you want (WRKF command can help there), and the names of all the members in each file.  You can get a list of all the members in a file with the command:

DSPFD FILE(yourfile) TYPE(*MBRLIST) or
DSPFD FILE(yourfile) TYPE(*MBRLIST) OUTPUT(*PRINT)

Once you have created a folder, you can start dumping stream files into it:

CPYTOIMPF FROMFILE(LIBRARY1/CUSTOMER COMPANY1) TOSTMF(‘/myfoldername/CUSTOMER_COMPANY1.TXT’) STMFCODPAG(*PCASCII) …

Specify all of the options you want for delimiters, decimals, and dates.

In case you aren’t too familiar with the AS/400 command interface, I’ll give you a couple of tips:

  • Instead of typing all of this out, type the command (WRKF, MD, DSPFD, CPYTOIMPF) all by itself on the command line, and press F4 for the prompter.  then just fill in the blanks.
  • If you need help, put the cursor in the prompt field and press F1 for detailed help on each parameter.
  • Once you have executed the command once, press F9 to pull it back up again (press repeatedly to scroll through earlier commands), and you can prompt the command, edit it, and re-run it without all that pesky typing.

If you have a LOT of files to do, or if you expect to do this repeatedly, you might want to see if you can find a friendly programmer to write you a CL program to do this for you.