View previous topic :: View next topic
|
Author |
Message |
ashimprodhan
New User
Joined: 08 Dec 2006 Posts: 12 Location: Kolkata
|
|
|
|
Hi All,
I need to write a program/function say OFFSET which will return a value equal to the number of used bytes that precede the data-name in the logical record in which data-name is defined.
Eg.
01 TEST-VARIABLE1.
02 WS-VAR1 PIC X(2).
02 WS-VAR2 PIC 9(5).
02 WS-VAR3 PIC X(6)
02 WS-VAR4 PIC X(10) VALUE 'ASHIM'.
02 WS-VAR5 PIC S9(2).
02 WS-VAR6 PIC 9(2) COMP.
the OFFSET(WS-VAR1) will return 0
WS-VAR2 will return 2
WS-VAR3 will return 7 like this..
If its an elementary level then it will return zero. Whenever the OFFSET of a variable is to be calculated this function will be called.
Please suggest me the logic or is there any intrisic function which can do that......
True Regards, |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I don't think it can be done in COBOL at all -- COBOL ADDRESS OF only applies to 01 or 77 level items. If you write an Assembler subroutine and pass BY REFERENCE you should be able to use the addresses of the fields to calculate differences, but I haven't tested this so it's not guaranteed. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
If COBOL II:
Write a cobol sub-modul that is CALLed USING <FIELD>, <signed Binary 4/8? I forget>
SUB-MODULE:
Code: |
PROCEDURE DIV USING <area>, <pointer>
set <pointer> to address of <area>
goback. |
If Enterprise COBOL you can set a pointer in working-storage to the address of <something>. Redefine the pointers as <signed Binary 4/8? I forget>.
the fields defined as binary can be used in length calculations. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Once you have the offset, how will it be used?
How do you plan to handle redefines, renames, and arrays? |
|
Back to top |
|
|
|