How to find the offset of a variable?
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Application Programming

#1: How to find the offset of a variable? Author: rgk PostPosted: Tue Feb 18, 2003 6:30 am
    —
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

#2:  Author: Mike TebbLocation: Yorkshire, England PostPosted: Tue Feb 18, 2003 7:18 am
    —
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))


#3:  Author: rgk PostPosted: Tue Feb 18, 2003 7:26 am
    —
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

#4:  Author: DibakarLocation: USA PostPosted: Tue Feb 18, 2003 7:41 am
    —
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.

#5:  Author: Mike TebbLocation: Yorkshire, England PostPosted: Tue Feb 18, 2003 7:48 am
    —
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.



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group