Hi Ralph,
Here's some other info that may be helpful. IBM Manuals are strangely silent on how to process variable and undefined records. I've been thinking about writing a FAQ on this subject, but there are some aspects that I'm not sure of. But here's what I do know.
There are three situations you can find yourself in when attempting to read/write variable records in a COBOL pgm:
1) Each record read contains a Rec type field that indirectly identifies the length of the rec read.
2) Each rec read contains one or more variable tables (they use the ODO clause) that vary the length of the rec. Therefore, you can't determine the exact length of the rec.
3) Each rec read does NOT contain variable tables, but are variable in length.
In all cases there is a dichotomy between the JCL and the program when the rec length/blksize is stated or implied.
Variable recs each contain a 4 byte Record Descriptor Word (RDW). If they are blocked, each block contains a 4 byte Block Descriptor Word (BDW). In each only the 1st 2 bytes contain the length. The other 2 are used for spanned recs.
So what this means is that your JCL rec length will be 4 bytes larger than the rec len stated or implied in the pgm. Similarly, the JCL max blksize will be 8 bytes larger than the Max blksize stated in the pgm.
OK, back to the situations:
In #1 code the FD with
Code:
RECORD CONTAINS x TO y
BLOCK CONTAINS 0 RECORDS.
The FD rec layouts (1 for each rec type) look something like this:
Code:
01 rec-1.
05 rec-typ1 pix x.
yada, yada, yada
01 rec-2.
05 rec-typ2 pix x.
yada, yada, yada
etc, etc.
You code the O/P file in a similar way, just choose names that make sense. I'll assume names prefixed by OP-.
In the PD:
Code:
READ INPUT-FILE
IF REC-TYPE1 = '4'
PERFORM PROC-REC-TYP4
PERFORM WRITE-REC-TYP4
END-IF
PROC-REC-TYP4.
.
.
.
MOVE REC-4 TO OP-REC-4
WRITE OP-REC-4.
Note that the multiple 01s in the FD redefine each other, so referencing any "REC-TYPE" picks up the one just read.
Make sure you determine what rec you read by checking the rec-type. Use the same O/P rec type to write the rec.
Note also that if you want to save the MOVE, use:
WRITE OP-REC-4 from REC-4
In #2 and #3 code the FD with
Code:
RECORD VARYING x TO y DEPENDING ON WS-VLEN
BLOCK CONTAINS 0 RECORDS.
The FD rec layouts look something like this:
Code:
01 VAR-FILE-IP.
05 VAR-BYTES-IP PIC X OCCURS 1 TO X
DEPENDING ON WS-VLEN.
Optionally, you can code other 01s here.
In the WS code:
After you do the read, WS-VLEN will contain the length of the record just read. You use this length if you want to rewrite the record just read keeping the same length. If you want to change the rec length for the write, just recalculate it and move it to WS-VLEN before you perform the write.
Here's the part I'm not sure of:
If with situation #2, each rec read contains more than 1 variable table, I think you HAVE to use what I outlined above. On the otherhand, If the recs contain only one variable length table, you may be able to use the original record definition of the rec and use the ODO object field of that rescription in the FD RECORD VARYING clause. I THINK. I've never used it.
But as I said before, you can use the other approach and just include the additional description after the 1 byte ODO rec description.
The other thing I'm not sure of is whether this approach can be used for undefined (RECFM=U) reords.
Well, there it is. I hope I didn't make the waters muddier.
Regards, Jack.