You can get a tab delimited output file by using the Hex 09 value for your tab character. In your Output-Record replace the filler by a variable name such as TAB-1. See sample Output-Record below.
01 OUTPUT-RECORD.
03 FIELD-1 PIC X(34).
03 TAB-1 PIC X(1).
03 FIELD-2 PIC 9(4).
03 TAB-2 PIC X(1).
03 FIELD-3 PIC X(30).
03 TAB-3 PIC X(1).
03 FIELD-4 PIC X(02).
In your procedure division simply move the hex value 09 (zero nine) to the Tab-1, Tab-2, Tab-3 fields, like below.
MOVE X09 TO TAB-1.
MOVE X09 TO TAB-2.
MOVE X09 TO TAB-3.
The X in front of the 09 field indicates to COBOL that the value is a hex value. Be sure to enclose the 09 in double quotes.
This should give you a tab delimited file.
Main Topics
Browse All Topics





by: tliottaPosted on 2007-10-16 at 12:02:24ID: 20088090
annetje:
Since no one's picked this up yet...
Without knowing the platform/compiler, it's hard to be certain of some details. Under an i5/OS compiler, you have a bit of difficulty because OUTPUT-RECORD has its fields defined directly beneath the FD entry for the file. The FD entry effectively described the file's I/O buffer rather than a separate WORKING-STORAGE memory area.
This means that simple changes such as adding VALUE clauses to the FILLER items isn't very useful. Each new record image in the buffer will reinitialize the area and overlay the VALUEs.
Ideally, the record image would be built in a WORKING-STORAGE 01-level item. That record image would be populated with your data and the FILLERs could have a fixed VALUE. Then you'd use a WRITE ... FROM to output the records.
By doing the work outside of the buffer you'd take advantage of what the compiler can do to help you, at the cost of a tiny bit of extra coding for data definitions plus a slightly indirect I/O.
Whenever possible, I try to avoid doing actual data manipulation in any buffer area. I always want to isolate anything that I do from what some underlying DBMS or operating system might do for buffering, double-buffering or what have you.
In short, I'd move your 01-level OUTPUT-RECORD to under WORKING-STORAGE. I'd add VALUE '[tab]' to each appropriate FILLER, using whatever the [tab] character is one your platform, possibly a hex value. I'd create a new 01-level item under the FD perhaps named FD-OUTPUT-RECORD. And I'd change my WRITE to be WRITE FD-OUTPUT-RECORD FROM OUTPUT-RECORD.
I'd also take care _not_ to clear the entire 01-level OUTPUT-RECORD but instead only reinitialize the individual 03-level field. Reinitializing the 01-level would wipe out my VALUEs.
At least, that's how I'd do it given what appears to be your starting point. Technically, I probably wouldn't do it this way at all. I'd probably be using STRING to bring all of the elements together, and perhaps a variety of other technique changes.
But that's beyond the scope of your question...
Tom