Tab delimited file

pts.
Tags:
Application development
RPG
RPGLE
I have been asked to produce a file in an RPG program. The file is being used in some kind of interface and needs to be 'tab delimited' What is tab delimited? How do I create a tab-delimited file? Thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi

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

Jonathan

=======================================================

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 <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/unix2.htm”>Integrated File System APIs</a> 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.

Tom

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • NarasimhaReddy
    Hi, Can any body help me, How can I view this stream file ! I am not finding my stream file anywhere in IFS after creating using CPYTOIMPF cmd. Thanks Reddy
    225 pointsBadges:
    report
  • astradyne
    What path are you using to store the file in the IFS and does the path exist? You use the WRKLNK command to browse the IFS and it's possible that your default "current" directory is not the root folder in which case use WRKLNK '/*' to view the contents of the root folder and navigate from there. If that doesn't help, have you checked the joblog after the CPYTOIMPF has run to make sure there are no errors? Let me know if you need more help. Jonathan
    370 pointsBadges:
    report
  • Gilly400
    Hi, If you have client access and MS Office, you could also transfer your data from a DDS described file to MS Excel and then save as a text file with tab delimiting. Cheers, Martin Gilbert.
    23,730 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following