I have a COBOL program that call a Assembly module. This module returns a Pointer to some data (I'll call it 'buffer') obtained inside this module. How can I address a variable in my working storage to this pointer and use the data?
In my COBOL caller I have something like:
Working Storage:
01 WK-MOD-AREA.
03 WK-MOD-PTR PIC 9(09) COMP VALUE 0.
01 WK-BUFFER-PTR USAGE POINTER.
01 FILLER REDEFINES WK-BUFFER-PTR.
03 WK-BUFFER-PTR-COMP PIC 9(09) COMP.
01 WK-BUFFER-DATA PIC X(5656) VALUE SPACES.
Procedure Division:
CALL 'MYMOD' USING WK-MOD-AREA.
MYMOD returns an address in WK-MOD-PTR.
I just tryed address the data using:
MOVE WK-MOD-PTR TO WK-BUFFER-PTR-COMP.
SET ADDRESS OF WK-BUFFER-PTR TO WK-BUFFER.
But it gives me the compiller error:
==000657==> IGYPS2161-S "ADDRESS OF" operand "WRK-BUFFER"
was found as the receiving operand of a "SET" statement,
but was not a level-01 or level-77 "LINKAGE SECTION" item.
The statement was discarded.
Thanks in advance.
You can do what you want but you can't change the address of an item in WORKING-STORAGE SECTION
, these items have a fixed address and are allocated when the program is activated for the first time.
As your compiler told you already you can do this with items in LINKAGE SECTION
as these have no fixed address and aren't allocated.
And depending on your actual use you may pass the POINTER
directly to the program instead of an intermediate variable:
Working-Storage SECTION.
01 WK-BUFFER-PTR USAGE POINTER.
LINKAGE SECTION.
01 WK-BUFFER-DATA PIC X(5656) VALUE SPACES.
Procedure Division.
CALL 'MYMOD' USING WK-BUFFER-PTR.
SET ADDRESS OF WK-BUFFER-DATA TO WK-BUFFER-PTR.
Notes:
WK-BUFFER-DATA (1:actual-length)
or a table with variable size DEPENDING ON
(especially useful with OCCURS UNBOUNDED
).