Sorry, Typo ... should read: ... and Y is the maximum length plus 2 ...


Am 14.06.2024 um 13:09 schrieb Bernd Oppolzer:
Hi Martin and Jason,

I agree with Martin that the length / data elements must be processed one at a time.
Some additional remarks:

- the length field must have attribute S9(4) comp, because it is a binary length field

- I would suggest not to use the OCCURS ... DEPENDING clause at all, but unstead work with MOVE with positions, like this: MOVE SOURCE (X:Y) TO TEMP-WORK ... where X is the position in the source string where the length field of the actual element starts and X is the maximum length plus 2. Then you can process the content, using TEMP-WORK, by examining the length field at the start of TEMP-WORK, and then increment X by the
length field plus 2

- is the length of the original source string fixed of variable? Doesn't really matter; when looping over this string, you have to take care to finish processing when the value of X reaches the end of the string.

@Martin: we didn't talk for a long time; I'm now working for more than 4 years with my COBOL/VSE assignment and consider myself a COBOL expert :-) but still working with PL/1 and ASSEMBLER with the other customer.
You know them all ...

HTH, kind regards

Bernd


Am 14.06.2024 um 11:00 schrieb Martin Trübner:
Jason,


try it with this (and use correct numbers- your sample had 0 to 3)


05 LL1             PIC 9(2).
05 TT1             OCCURS 0 TO 3 TIMES
                   DEPENDING ON LL1.
05 REMAIN          PIC X(4)

and in working storage section have this:

01 TEMP-WORK.
05 LL2             PIC 9(2).
05 TT2             OCCURS 0 TO 3 TIMES
                   DEPENDING ON LL2.


An extra MOVE before you touch TT2.


or multiple repeats of the above



Martin



On 14.06.24 09:39, Jason Cai wrote:
Subject: Assistance Needed with COBOL File Reading Structure

Dear [Recipient's Name],

I hope this message finds you well.

I am currently working on a COBOL program to read a file with the following format: length1, content1, length2, content2, and so on. An example of the data in the file is as follows:
```
00F00C0000FFF00F
0110140003156011
```

I intended to use the following copybook to read the data:
```cobol
05 LL1             PIC 9(2).
05 TT1             OCCURS 1 TO 2 TIMES
                    DEPENDING ON LL1.
05 LL2             PIC 9(2).
05 TT2             OCCURS 1 TO 2 TIMES
                    DEPENDING ON LL2.
```
However, I encountered an error:
```
IGYGR1137-S "OCCURS DEPENDING ON" object "LL2" was defined in a variably located area. Execution results are unpredictable.
```

The suggested structure to avoid this error is as follows:
```cobol
05 LL1             PIC 9(1).
05 LL2             PIC 9(1).
05 TT1             OCCURS 1 TO 2 TIMES
                    DEPENDING ON LL1.
    10  TT11        PIC X(1).
05 TT2             OCCURS 1 TO 3 TIMES
                    DEPENDING ON LL2.
    10  TT21        PIC X(1).
```
Unfortunately, this structure does not match the format of the file I need to read. Could you please advise on how to correctly read a file with this structure using COBOL?

Thank you for your any assistance !

Best regards,

Jason Cai

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email [email protected]  with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to