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 ..
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.