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.
Possible Related Links
Input-Output Strategies May 15, 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
I came across an interesting and thought provoking post by Max Harris on his blog From Here to Modernity, where questions about I-O Strategies (when dealing with a critical table) evoked responses from more than 90 iSeries professionals.
Four options were presented as follows:
- Replacing F-specs in RPG program with SQL in all the programs or modules that use the table ( Embedded SQL ).
- Move I-O to a SRVPGM and have a procedure return the record format.
- Move I-O to a SRVPGM and have several procedures which return various data structures.
- Move I-O to a SRVPGM and have field getters and field setters (JAVA).
We all know that first option is not very efficient, but read the post and related comments and arrive at your own conclusion.
Possible Related Links
QSHELL on iSeries April 14, 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
Ever wondered about QSHELL? It is a UNIX shell on iSeries. To access QSHELL, type in STRQSH on the command line. But before you go any further, head out to Thibault Dambrine’s tutorial : Exploring iSeries QSHELL: Concepts & Tutorial.
This tutorial explains in simple language the syntax of Unix commands, where to find help, how permissions work, and the basics of how to write a QShell script.
Some background on QSHELL: To be fully Java compliant, IBM needed to supply a JDK (Java Development Kit) on its iSeries eServer that could run standard Java commands such as Java, Javac or Javadoc, the same way other (UNIX) systems could. There was only one snag, OS/400 was NOT ’a flavor of’ UNIX. The OS/400 IBM team resolved this hurdle by supplying a new ‘UNIX style shell‘ on the iSeries and appropriately named it ‘QSHELL‘.
Possible Related Links
Open Source iSeries Toolkit April 11, 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
While searching for an open source software for my other project, I came across Open Source iSeries Toolkit. For those of you new to Open Source Software, it is a program in which the source code is available to the general public for use and/or modification from its original design free of charge. Open source code is typically created as a collaborative effort in which programmers improve upon the code and share the changes within the community. Open source sprouted in the technological community as a response to proprietary software owned by corporations. Learn more about it at opensource.org.
iSeries Toolkit is a bag of utilities that support Dynamic SQL, Messaging, IFS file access, User spaces, User indexes, Dynamic Native File Access, XML, and Source Generation. These RPGIV ILE and Java tools work on most recent releases of the iSeries and AS/400.
Get Involved
Apart from being a user of this toolkit, you can get involved as a developer. You can actually help developing the iSeries Toolkit by either fixing the bugs reported or adding / enhancing the utilities by checking the features requested. This open source project has a very active community that is constantly working on improving the toolkit. You can download the toolkit and try it yourself.
Here are some of the features requested:
- UDF suggestion for dates
- Include a complete list of subprocedures
- DMPSQL data from a table.
- ILE Module Information
- New feature in Seq().
- UserSpace Viewer.
- Add support for the Qp0lGetAttr API
- Update Debug info in CHGOBJ Command
- New SAVZIP Command
Are you ready to accept these challenging tasks?
If you have any comments or opinions, please click on "Comment" link below this article.
Possible Related Links