I have a requirement to re-format records if a PS file. I know that building a sort card is the easiest way. But, I do not want to create 500+ Sort cards for each file that I had to reformat. When I do not have to sort a file, but only re-format fields in a record where each record can have 3000+ fields, which one is effective? A COBOL PGM OR A SORT CARD?
Generally, the total amount of code to be created for SORT utility should be seriously less than verbose COBOL code.
1. Need to create the “record description” as SYMNAMES member for SORT. It is functionally equivalent to COBOL copybook for the same record. If copybooks already do exist, it’s not a big deal to create a REXX script converting them from COBOL format to SYMNAMES format.
Code:
* SYMNAMES COPYBOOK FOR XXXXXXX_RECORD
$RDWLEN,BI,*,2 record length if RECFM=VB
$RDWFLAG,BI,*,2 flag field if RECFM=VB
FIELDaaa,CH,*,30 from PIC X(30)
FIELDbbb,PD,*,5 from PIC S9(7)V99 COMP-3
FIELDccc,FI,*,2 from PIC S9(4) COMP-1
FIELDddd,ZD,*,9 from PIC S9(7)V99
. . . etc . . .
2. Need to use required conversion in any of BUILD parameters of SORT control statements
While not using any tool daily a lot of syntax tricks are missing from my mind.
The correct syntax must be
1.
Code:
* SYMNAMES COPYBOOK FOR XXXXXXX_RECORD
$RDWLEN,*,2,BI record length if RECFM=VB
$RDWFLAG,*,2,BI flag field if RECFM=VB
FIELDaaa,*,30,CH from PIC X(30)
FIELDbbb,*,5,PD from PIC S9(7)V99 COMP-3
FIELDccc,*,2,FI from PIC S9(4) COMP-1
FIELDddd,*,9,ZD from PIC S9(7)V99
. . . etc . . .
I have a requirement to re-format records if a PS file. I know that building a sort card is the easiest way. But, I do not want to create 500+ Sort cards for each file that I had to reformat. When I do not have to sort a file, but only re-format fields in a record where each record can have 3000+ fields, which one is effective? A COBOL PGM OR A SORT CARD?
How do you intend to write one program fits all 500+ formats ? It’s a less efforts if you do by SORT., use option copy if you don’t want to sort, that’s okay.
Short answer: I recommend using sort with SYMNAMES.
Long winded answer:
Several years ago a wrote a COBOL program to do this. It was before SYMNAMES were a thing. It wasn't a trivial program to create. But it works well. Since SYMNAMES didn't exist, I also wrote a program to convert copybooks to basically a metadata file that performs the same function as symnames only for COBOL.
The way it works is you must either have a one of these meta data files for each file layout and pass the metadata information into the COBOL program so it knows the layout of the input and output files.
The field names in the metadata file need to be the same on the input and output layouts.
You need to code a conversion paragraph for each combination of input and output field formats. I coded it so that if a new combination was encountered it abended so you could create the new paragraph. After about a month we had all of the combinations we deal with.
It's pretty trivial from there because all you need to do is create the metadata file if you get a new layout.
To the question of "how do you create a cobol program that handles all of those layouts?". Combination of some kind of logic that can detect if it's new and abend so you can add logic for the new layout, and using REC EQUALS 0. By the way you can use REC EQUALS 0 for the output, too, but you have to allow linking after return code = 8. For this reason I have a version that write out an lrecl that's longer than needed.
Since I already have that process, I prefer to use it most of the time. However, if SYMNAMES existed at the time, I would have used them. And I recommend people use SYMNAMES now.