Can I write more than one structure in file?

99 Views Asked by At

I have FD

   FD  CR1
       LABEL RECORD IS STANDARD
       DATA RECORDS ARE FIRSTSTR, SECONDSTR, THIRDSTR.

and 3 structures

   01  FIRSTSTR.
       05 FIRSTFIVE       PIC X(05).
       05 SECONDFIVE       PIC X(05).

   01  SECONDSTR.
       05 FIRSTTWO       PIC X(02).
       05 SECONDONE       PIC X(01).
       05 THIRDFOUR       PIC X(04).

   01  THIRDSTR.
       05 FIRSTTHREE       PIC X(03).
       05 SECONDTHREE       PIC X(03).
       05 THIRDTHREE       PIC X(03).

Can I write all info in file like this:

WRITE FIRSTSTR, SECONDSTR, THIRDSTR.

And read from file in 3 structures like this:

READ CR1 INTO FIRSTSTR, SECONDSTR, THIRDSTR AT END
1

There are 1 best solutions below

0
On BEST ANSWER

Yes, you can write more than one type of record to a file, but no, you can't do it the way you want to.

The record-definitions (structures) under the FD all occupy the same storage, meaning the all the 01-levels start at the same byte address. The individual records cannot simultaneously contain different data.

This is called an "implicit REDEFINES".

The READ ... INTO ... is to read and at the same time copy the current record to the INTO item (singular) that you specify. The INTO item would usually be in the WORKING-STORAGE (although they could also be in LOCAL-STORAGE). It would be exotic to use the LINKAGE SECTION and very, very, odd to use something in the FILE SECTION as a target for a READ ... INTO....

You only READ one record at a time. Unless you file has a set, fixed-in-stone, sequence of different records, we'd usually READ the file, identify the record, and then process that particular type of record.

You can only specify one receiving item for READ ... INTO ... and only one source item for WRITE ... FROM ....