Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing a comma delimited file 2

Status
Not open for further replies.

RASI

Programmer
Aug 29, 1998
29
0
0
US
Need to produce a comma delimited file. Nothing new about this old file type - would just like to get more ideas how other programmers use cobol to produce this file ..

Using Realia 4.2 cobol for this project.

Thanks for you logic thoughts...


 
I've done this a few times. I use a string statement with a pointer something like this:

First set the pointer to the beginning of your comma delimited record.
MOVE 1 TO PTR.

Build a record by repeating as needed:
Case type of variable to be include
when string
STRING QUOTE DELIMITED BY SIZE
STRING-VAR DELIMITED BY " " in case string contains blanks
QUOTE DELIMITED BY SIZE
INTO COMMA-DELIM-REC
WITH POINTER PTR.
when integer
STRING INT-VALUE DELIMITED BY SIZE
INTO COMMA-DELIM-REC
WITH POINTER PTR.
when decimal number
STRING INTEGER-PORTION
"."
DECIMAL-PORTION DELIMITED BY SIZE
INTO COMMA-DELIM-REC
WITH POINTER PTR.
end case
If this is not the last entry
STRING "," DELIMITED BY SIZE
INTO COMMA-DELIM-REC
WITH POINTER PTR.
endif
end repeat

That's it more or less. Of course, you could get fancy and take off the leading zeros with an inspect and some reference modification, same for trailing zeros on the decimals, but most applications that would read the file would handle them, so removing them is probably optional.. Betty Scherber
Brainbench MVP for COBOL II
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top