This command will copy any DB2/400 file into a CSV file in the IFS and, optionally, insert a column heading row based on the file/field descriptions of the source file. As a prerequisite you must have implemented the ZFFDTOCSV command, which I have previously submitted as a tip.
The command consists of a simple CMD/CLP combination (ZCPYTOCSV) for which I have included the source.
ZCPYTOCSV parameters ...
FROMFILE
--------
Qualified name of DB2 PF/LF which is to be copied to the CSV file.
TOFILE
------
Fully qualified name (including path) of the target CSV file in the IFS. If not found, the file is created. If found, data is added or replaced according to DATAOPT parm value. Note if you wish the target file to have a "csv" extension, you must include it in the file name (this command does NOT add the ".csv").
DATAOPT
-------
Add or replace data in TOFILE. Valid values are *ADD/*REPLACE. Default is *A...
To continue reading for free, register below or login
To read more you must become a member of Search400.com
');
// -->

DD. Note: if *REPLACE is specified the target file will be deleted prior to execution of the CPYTOIMPF command (my quick fix to figuring out how to clear an IFS file).
COLHDG
------
Controls whether or not a column heading row is inserted into the target file. Valid values are the same as those in ZFFDTOCSV plus the value *NONE which is the default and will prevent a column heading row from being inserted.
Processing overview ...
1) If DATAOPT(*REPLACE) is specified the TOFILE in the IFS is deleted using the RMVLNK command.
2) If a value other that *NONE is specified for the COLHDG parm, ZFFDTOCSV is invoked to insert a column heading row into the target file.
3) CPYTOIMPF is used to copy the TOFILE into the target file as a CSV file. Note: if you have modified any of the standard parm defaults for CPYTOIMPF you will have to specify them in this CL program to make sure the proper CSV format is achieved.
That's it ... use this command to send DB2/400 data to your users in a format that's Excel friendly.
Coming soon ... a command that uses ZCPYTOCSV to allow you to dynamically select data (using SQL) and output it to a CSV file.
Code
==================================
MORE INFORMATION ON THIS TOPIC
==================================
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.