COBOL ADDRESS OF Register: How to Use in Linkage Section

ADDRESS OF -The ADDRESS OF special register references the address of a data item in the linkage section, the local-storage section, or the working-storage section.

For 01 and 77 level items in the linkage section, the ADDRESS OF special register can be used as either a sending item or a receiving item.

For all other operands, the ADDRESS OF special register can be used only as a sending item. The ADDRESS OF special register is implicitly defined as USAGE POINTER. A function-identifier is not allowed as the operand of the ADDRESS OF special register.

WORKING-STORAGE SECTION.
01 FILLER.
05 WS-PTR USAGE IS POINTER.
05 WS-ADDR-X REDEFINES WS-PTR.
10 WS-ADDR PIC S9(8) COMP.

05 WS-SAVE-POINTER USAGE IS POINTER.
05 WS-SAVE-FULLWORD PIC S9(8) COMP.
05 WS-SAVE-CHAR-4 PIC X(4).

01 WS-DATA-AREA-1 PIC X(100).
01 WS-DATA-AREA-2 PIC X(200).

LINKAGE SECTION.
01 LINK-CALL-AREA.
05 LINK-DATA-ADDR PIC S9(8) COMP.

01 LINK-DATA-AREA PIC X(100).

PROCEDURE DIVISION USING LINK-CALL-AREA
LINK-DATA-AREA.

MOVE LINK-DATA-ADDR TO WS-ADDR.
SET ADDRESS OF LINK-DATA-AREA TO WS-PTR.

SET WS-PTR TO ADDRESS OF WS-DATA-AREA-1.
SET ADDRESS OF LINK-DATA-AREA TO WS-PTR.

SET WS-SAVE-POINTER TO WS-PTR.
MOVE WS-ADDR TO WS-SAVE-FULLWORD.
MOVE WS-ADDR-X TO WS-SAVE-CHAR-4.

SET ADDRESS OF LINK-DATA-AREA
TO ADDRESS OF WS-DATA-AREA-2.

*********** THIS WILL NOT COMPILE
*** MOVE ADDRESS OF WS-DATA-AREA-2 TO WS-ADDR.


SET ADDRESS OF LINK-DATA-AREA TO WS-PTR.

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.