A tab delimited file is a PC type file where columns of data (fields) are separated from each other by tabs in the same way that CSV (Comma Separated Variable) files separate the fields with commas.
Tab delimited files aren’t part of the DB2/400 database structure, but you can create a tab delimited version of a physical/logical file in the IFS using the CPYTOIMPF (Copy to Import File) command:
CPYTOIMPF FROMFILE(library/filename) TOSTMF('pathnamefilename.ext') STMFCODP
AG(*PCASCII) RCDDLM(*CRLF) STRDLM('"') FLDDLM(x'05')
The important parameter is the FLDDLM (Field Delimiter) which defaults to ‘,’. In ASCII the tab character is represented by ASCII code x’09’ which is equivalent to EBCDIC code x’05’. You can use the WRKTBL command and look at QASCII to see the conversion tables.
By specifying FLDDLM(x’05’) we’re telling the system to separate the fields with hex code ’05’ which is converted to hex code ’09’ in the resulting stream file.
Hope it helps
To create a tab-delimited file in RPG, use the open() API to create the file, the write() API to write lines to the file and the close() API to close the file. These are among the Integrated File System APIs that have been available for many years.
Basically, you string a bunch of text values together, separated by tab characters, into a long character variable (usually variable length). Then you write() that long variable to the streamfile. When you write an entire line, you’ll add a CR/LF to the end of the variable to mark the end-of-line. If you choose, you can write() each value to the file, individually followed by a write() of the tab character. You still write() the CR/LF when you’re done with the line.
The actual creation and writing of the streamfile is easy. The tricks are all in being sure that you have your CCSIDs properly set up so that your job may run as EBCDIC but the streamfile is handled as ASCII.
You might want to review the <a href=”http://www.redbooks.ibm.com/abstracts/sg245402.html”>”Sorcerer’s Guide (Who Knew You Could Do That With RPG?)” manual</a> that describes these types of RPG programming.