View previous topic :: View next topic |
Author |
Message |
rgk Beginner
Joined: 11 Feb 2003 Posts: 6 Topics: 3
|
Posted: Tue Feb 18, 2003 6:30 am Post subject: How to find the offset of a variable? |
|
|
Is there any way to find the offset of a variable within its group. For example in the following code
Code: |
01 WS-GROUP.
05 WS-VAR1 PIC X(5).
05 WS-VAR2 PIC X(6).
05 WS-VAR3 PIC X(7).
05 WS-COUNT PIC 9(1).
05 WS-VAR4 OCCURS 1 To 10 TIMES DEPENDING ON WS-COUNT
10 WS-VAR5 PIC X(6).
05 WS-VAR6 PIC X(6).
|
If in the above code, the value of ws-count is 3, then the offset of the variable var6 will be 38 as follows.
5 + 6 + 7 + 1 + ( 6 * 3 ) = 37
Is there any way to find this offset dynamically without hardcoding the lengths of the variables.
Thanks in advance
Regards,
Kannan RG |
|
Back to top |
|
|
Mike Tebb Beginner
Joined: 02 Dec 2002 Posts: 20 Topics: 0 Location: Yorkshire, England
|
Posted: Tue Feb 18, 2003 7:18 am Post subject: |
|
|
Code: |
01 WS-GROUP.
05 WS-GRP1.
10 WS-VAR1 PIC X(5).
10 WS-VAR2 PIC X(6).
10 WS-VAR3 PIC X(7).
10 WS-COUNT PIC 9(1).
05 WS-VAR4 OCCURS 1 TO 10 TIMES DEPENDING ON WS-COUNT.
10 WS-VAR5 PIC X(6).
05 WS-VAR6 PIC X(6).
01 WS-OFFSET PIC S9(3) COMP-3 VALUE 0.
COMPUTE WS-OFFSET = (LENGTH OF WS-GRP1 +
(LENGTH OF WS-VAR4*WS-COUNT))
|
_________________ Cheers - Mike |
|
Back to top |
|
|
rgk Beginner
Joined: 11 Feb 2003 Posts: 6 Topics: 3
|
Posted: Tue Feb 18, 2003 7:26 am Post subject: |
|
|
Thanks for your reply Mike.
But then i have a problem here. We also thought of this solution.
But in a later stage if we include one more occurs depending on clause before var6, then i need to change the formula for calculating the offset.
We do not want this. Just by giving the name of the variable can we get its offset within its group?
Regards,
Kannan RG |
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 699 Topics: 63 Location: USA
|
Posted: Tue Feb 18, 2003 7:41 am Post subject: |
|
|
Kannan,
Mike Tebb's answer with slight modification might solve your purpose with original code -
Code: |
01 WS-GROUP.
05 WS-VAR1 PIC X(5).
05 WS-VAR2 PIC X(6).
05 WS-VAR3 PIC X(7).
05 WS-COUNT PIC 9(1).
05 WS-VAR4 OCCURS 1 To 10 TIMES DEPENDING ON WS-COUNT
10 WS-VAR5 PIC X(6).
05 WS-VAR6 PIC X(6).
|
Calculating offset:
Code: |
COMPUTE WS-OFFSET = (LENGTH OF WS-GROUP - LENGTH OF WS-VAR6)
|
Diba. |
|
Back to top |
|
|
Mike Tebb Beginner
Joined: 02 Dec 2002 Posts: 20 Topics: 0 Location: Yorkshire, England
|
Posted: Tue Feb 18, 2003 7:48 am Post subject: |
|
|
Or, if fields are going to exist after WS-VAR6 then try:
Code: |
01 WS-GROUP.
05 WS-GRP1.
10 WS-VAR1 PIC X(5).
10 WS-VAR2 PIC X(6).
10 WS-VAR3 PIC X(7).
10 WS-COUNT PIC 9(2).
10 WS-VAR4 OCCURS 1 TO 10 TIMES DEPENDING ON WS-COUNT.
15 WS-VAR5 PIC X(6).
05 WS-VAR6 PIC X(6).
05 WS-VAR7 etc....
01 WS-OFFSET PIC S9(3) COMP-3 VALUE 0.
COMPUTE WS-OFFSET = LENGTH OF WS-GRP1
|
Just make sure that any new occurs fields are within WS-GRP1.
P.S. Also realised that WS-COUNT needs to be 2 bytes. _________________ Cheers - Mike |
|
Back to top |
|
|
|
|