Subprograms: CALL and USING
CALL and USING
CALL runs another compiled program. USING passes data items by reference by default, so the called program sees the caller's storage, not a copy:
CALL "PAYCALC" USING WS-HOURS WS-RATE WS-PAY.
The LINKAGE SECTION
The called program declares its parameters in the LINKAGE SECTION of DATA DIVISION. No VALUE clause and no storage is allocated here: the caller owns the memory:
DATA DIVISION.
LINKAGE SECTION.
01 LS-HOURS PIC 9(3)V99.
01 LS-PAY PIC 9(7)V99.
CANCEL
CANCEL unloads a subprogram so the next CALL reloads it fresh, which clears any state it kept in WORKING-STORAGE. GOBACK returns from a subprogram; STOP RUN ends the whole run unit.
The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.
Article author: Arthur Isaev