Convert any iSeries database file to CSV format July 2, 2006
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /homepages/26/d120742039/htdocs/Norm/iseries/wordpress/wp-content/plugins/technotag.php on line 30
Here is a utility that will convert any iSeries database file to CSV (Comma Seperated Values) format with a delimiter of your choice. You can choose the delimiter
because it is very possible to have a comma in a description. So choose wisely.
I was forced to write this utility and here is why. I had a project to transfer data files from the iSeries 400 to a server that was running California Software Baby 400 system.
Seems simple enough just use the CPYFRMSTMF command or the CPYFRMIMPF right?
Yeah I thought so too. Well as I tried to use these commands as I have used them before and they work just fine if you have a good database file. But IBM did not think of everything
that programmers can do to a database file.
In my case I ran across (and not in just one file) packed numeric data. So what is the problem you ask? The data length of these packed fields were 1 bytes and 2 bytes. Why would you pack a 1 byte numeric field or even a 2 byte numeric field? The above mentioned command did not stop but they did not work either. Can you guess what they did? ……. Ok times up, they took those fields and extended them by 1 byte so the 1 byte packed became 2 bytes and the 2 bytes became 3 bytes. No matter what I did I could not get the file converted correctly on iSeries.
So either I can write a 100 or so programs (which I decided not to do) or write a utility to do all the work for me. Which is what I did and I am sharing this with whoever wants to use it. Feel free to use it and to make what ever changes you need for your use.
All the work is done in QTEMP. The process creates a work file call CVFILEO and a
temporary library with QRPGLESRC and a temporary program called CVPGM. The temp library is the use name with a ‘@’ in front of it. Example: if the user name is kfoland
the library name will be @kfoland.
So we have one work file called CVFILEO.
One command called CVF2CSV. Compiled to call CV0CL.
Two CL programs CV0CL and CV1CL.
Two RPGLE programs CV1 and CV2.
The simple process is as follows:
1. Delete temp files
2. Create duplicate object CVFILEO into QTEMP
3. Display field description on the incoming file into a file called CVFILE
4. Call CV1 to get the record length and call CV1CL to build the flat file with the given
record length.
5. Create the temp library.
6. Create QRPGLESRC in the temp library
7. Add the physical file member CVPGM to QRPGLESRC in the temp library
8. Call CV2 to read the incoming file and to create the temp program CVPGM.
9. Compile CVPGM
10. Call CVPGM
11. Copy the flat file from QTEMP to the out going file.
To get started, compile the file, command and the programs.
Prompt up the command and fill out the parms or just call CV0VL with the following parms.
PARM(&FILE &LIBR &TFILE &TLIBR &DEM)
where
&FILE = database file to be converted
&LIBR = library were the database file is located
&TFILE = name you want for the converted file
&TLIBR = library where the converted file will be
&DEM = the delimiter you want to use. Choose wisely
After the process runs you can check out the temp library and the program that was created in QSYS as the library will get deleted at the beginning of the process. You can change this if you want to delete the library at the end of the process. The process will delete any files or libraries in QTEMP as it runs.
This has help me so I hope it can help others as well.
- Posted in : Programming Languages, RPG ILE
- Author : kafoland

Comments»
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /homepages/26/d120742039/htdocs/Norm/iseries/wordpress/wp-content/plugins/technotag.php on line 30
Thank-you Kevin for a very useful utility! I will be loading Kevin’s utility in a downloadable form soon.