Top
NetCOBOL V11.0 Syntax Samples
FUJITSU Software

1.5 Pointer

The pointer data item is used to reference data based on a specific memory address. In this case, the data attribute and offset is defined using a based-storage section.

The pointer data item is often used in cases where an address is used as an interface such as when calling a C program.

000010 @OPTIONS MAIN
000020*----------------------------------------------------------------------
000030* The pointer enables data to be referenced using a memory address.
000040*----------------------------------------------------------------------
000050 IDENTIFICATION     DIVISION.
000060 PROGRAM-ID.        SAMPLE.
000070 DATA               DIVISION.
000080*----------------------------------------------------------------------
000090* An item that is to be references using a pointer reference is 
000095* declared in based-storage section. 
000100*----------------------------------------------------------------------
000110 BASED-STORAGE      SECTION.
000120 01 TYPE-DATE.
000130    02              PIC X(8).
000140    02 CR-HOUR      PIC 9(2).
000150    02 CR-MINUTE    PIC 9(2).
000160    02 CR-SEC       PIC 9(2).
000170*----------------------------------------------------------------------
000180 WORKING-STORAGE    SECTION.
000190 01 CR-DATE         PIC X(21).
000200 01 PTR             POINTER.
000210 PROCEDURE          DIVISION.
000220     MOVE FUNCTION CURRENT-DATE TO CR-DATE.
000230*----------------------------------------------------------------------
000240* The starting address of the actual data item is set in the pointer 
000245* item and the data is pointed to and referenced using a pointer 
000250* reference.
000260*----------------------------------------------------------------------
000270     MOVE FUNCTION ADDR (CR-DATE) TO PTR.
000280     DISPLAY "The current time is " PTR->CR-HOUR " hours, " 
000290                                    PTR->CR-MINUTE " minutes, " 
000300                                    PTR->CR-SEC " seconds."
000310*----------------------------------------------------------------------
000320 END PROGRAM SAMPLE.