Format 6: SET for procedure-pointer and function-pointer data items
When this format of the SET statement is executed, the current value of the receiving field is replaced by the address value specified by the sending field.
At run time, function-pointers and procedure-pointers can reference the address of the primary entry point of a COBOL program, an alternate entry point in a COBOL program, or an entry point in a non-COBOL program; or they can be NULL.
COBOL function-pointers are more easily used than procedure-pointers for interoperation with C functions.
- procedure-pointer-data-item-1 , procedure-pointer-data-item-2
- Must be described as USAGE IS PROCEDURE-POINTER. procedure-pointer-data-item-1 is a receiving field; procedure-pointer-data-item-2 is a sending field.
- function-pointer-data-item-1 , function-pointer-data-item-2
- Must be described as USAGE IS FUNCTION-POINTER. function-pointer-data-item-1 is a receiving field; function-pointer-data-item-2 is a sending field.
- identifier-8
- Must be defined as an alphabetic or alphanumeric item such that the value can be a program name. For more information, see PROGRAM-ID paragraph. For entry points in non-COBOL programs, identifier-8 can contain the characters @, #, and, $.
- literal-1
- Must be alphanumeric and must conform to the rules for formation of program-names. For details
on formation rules, see the discussion of program-name under PROGRAM-ID paragraph.
identifier-8 or literal-1 must refer to one of the following types of entry points:
- The primary entry point of a COBOL program as defined by the PROGRAM-ID paragraph. The PROGRAM-ID must reference the outermost program of a compilation unit; it must not reference a nested program.
- An alternate entry point of a COBOL program as defined by a COBOL ENTRY statement.
- An entry point in a non-COBOL program.
The program-name referenced by the SET ... TO ENTRY statement can be affected by the PGMNAME compiler option. For details, see PGMNAME in the Enterprise COBOL Programming Guide.
- NULL, NULLS
- Sets the receiving field to contain the value of an invalid address.
- pointer-data-item-3
- Must be defined with USAGE POINTER. You must set pointer-data-item-3 in a non-COBOL program to point to a valid program entry point.
Example of SET for procedure-pointer and function-pointer data items
The following example shows how to use the SET statement to assign values to a function-pointer (FP) and a procedure-pointer (PP), allowing for dynamic calls to different subprograms ("subp1" and "subp2") based on the assigned pointer references.
IDENTIFICATION DIVISION.
PROGRAM-ID DEMO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FP USAGE FUNCTION-POINTER.
01 PP USAGE PROCEDURE-POINTER.
PROCEDURE DIVISION.
SET FP to Entry "subp1"
CALL FP
SET PP to Entry "subp2"
CALL PP