Reputation: 401
I have a COBOL indexed file that was built without COBOL. Now I have to create an FD to open and read the records in COBOL.
A record has a key-part that has a fixed length. I also have a data-part. Two fields have a variable length. The length of this field is stored in an other field of the record.
The file description looks like this :
FD ind-file
01 FD-REC.
03 FD-KEY.
05 key1 PIC 9.
05 key2 PIC 9.
03 FD-DATA.
05 data-length1 PIC9(03).
05 data1 ???? (length depending on data-length1)
05 data-length2 PIC9(03).
05 data2 ???? (length depending on data-length2)
Obviously this doesn't work. Does anybody have any idea how I should configure this file to make it possible to open it?
Should I define these variable record size in the file-control?
Upvotes: 2
Views: 686
Reputation: 13076
FD ind-file
01 FD-REC.
03 FD-KEY.
05 key1 PIC 9.
05 key2 PIC 9.
03 FD-DATA.
05 data-length1 PIC 9(03).
05 data1.
07 FILLER OCCURS 0 TO 999 TIMES
DEPENDING ON data-length1.
09 FILLER PIC X.
05 data-length2 PIC 9(03).
05 data2.
07 FILLER OCCURS 0 TO 999 TIMES
DEPENDING ON data-length2.
09 FILLER PIC X.
That should do for your definition. Sort of.
The problem is that data-length2 is "variably located". Which is stupid. It should be in the fixed part of the record.
So, for a COBOL compiler which conforms to the 1985 Standard for OCCURS DEPENDING ON you are stuck. You should get the record-layout changed.
If for some outlandish reason that is not possible, then you need to define a new field (in WORKING-STORAGE or LOCAL-STORAGE) which you MOVE data-length2 to.
Obviously in the example above, you replace the FILLER PIC Xs by whatever definition you need for the table items, and the maximum for the TIMES (I've just used the maximum possible given your PIC 9(3).)
Indenting and spacing your code makes it more easily readable.
Upvotes: 3