MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to find the offset of a variable?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
rgk
Beginner


Joined: 11 Feb 2003
Posts: 6
Topics: 3

PostPosted: Tue Feb 18, 2003 6:30 am    Post subject: How to find the offset of a variable? Reply with quote

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
View user's profile Send private message
Mike Tebb
Beginner


Joined: 02 Dec 2002
Posts: 20
Topics: 0
Location: Yorkshire, England

PostPosted: Tue Feb 18, 2003 7:18 am    Post subject: Reply with quote

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
View user's profile Send private message
rgk
Beginner


Joined: 11 Feb 2003
Posts: 6
Topics: 3

PostPosted: Tue Feb 18, 2003 7:26 am    Post subject: Reply with quote

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
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 699
Topics: 63
Location: USA

PostPosted: Tue Feb 18, 2003 7:41 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Mike Tebb
Beginner


Joined: 02 Dec 2002
Posts: 20
Topics: 0
Location: Yorkshire, England

PostPosted: Tue Feb 18, 2003 7:48 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group