Dealing with Pointers in Cobol


 

In Micro Focus COBOL, you can only use the ADDRESS OF operator to obtain the address of a data item in the LINKAGE SECTION. Pointers to items must be passed from other programs. To get around this limitation, a sub-program may be written to which an empty pointer and a data item is passed. Since the pointer is in the called program's linkage section, the called program can set the pointer for the calling program.

 

*********************************************************************

* Subprogram to obtain the address of an item *

*********************************************************************

 

identification division.

 

program-id.

 

getadd.

 

data division.

 

 

 

linkage section.

 

01 data-item pic x(1).

 

01 block-pointer pointer.

 

 

 

procedure division using data-item, block-pointer.

 

set block-pointer to address of data-item

 

exit program.

 

end program getadd.

 

 



Sunaccess Reference Interface Data Types Upgrading from Prior Versions