I have a physical file present in my development library on the IBM I box and I want to create a CSV file out of it and place it in IFS so that from there I can FTP it to the desktop in the CSV format. How do I create a comma-separated values (CSV) file in IFS?
To create a CSV file in as400, we can use the command CPYTOIMPF. But, before creating a CSV file, we should at least know what a CSV file is. CSV file is a comma-separated values stream file. CSV files hold data from IBM i files, such as SQL tables or DDS physical files, which are separated by commas. CSV file data:
CSV files are mostly used when we transfer data between two different systems. CSV files are supported by several spreadsheet programs, such as Microsoft Excel and Google spreadsheets. Data on IBM i support EBCDIC format and CSV files in an integrated file system (IFS) must contain ASCII data before exporting it to a Windows computer. Let’s see how to create a CSV file in as400 ifs using the CPYTOIMPF command:
First, create a physical file or SQL table.
Fill some records into the file or SQL table.
Run command CPYTOIMPF from the command line to copy data from the file and stream the file in ifs.
This creates a stream file in the IFS home directory “/home/developer/file11.CSV” using the data from the physical file FILE1 in the library TESTLIB copy.
Work with Links using the command WRKLNK to browse CSV files created in ifs.
Take option 5 to display CSV file data.
As you can see, there is a comma between each field. We see blank spaces between separated column values according to each column field size since the Remove Blank parameter on command CPYTOIMPF was set to *NONE.