typestar

CALL and LINKAGE in COBOL

Two programs in one file: CALL passes fields through the LINKAGE SECTION.

*> Two programs in one file: CALL passes data through LINKAGE.
IDENTIFICATION DIVISION.
PROGRAM-ID. DRIVER.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SPAN-FT   PIC 9(3) VALUE 24.
01 PLANKS    PIC 9(4).
PROCEDURE DIVISION.
    CALL "PLANK-COUNT" USING SPAN-FT PLANKS
    DISPLAY "A " SPAN-FT " ft footbridge needs " PLANKS " planks"
    STOP RUN.
END PROGRAM DRIVER.

IDENTIFICATION DIVISION.
PROGRAM-ID. PLANK-COUNT.
DATA DIVISION.
LINKAGE SECTION.
01 IN-SPAN    PIC 9(3).
01 OUT-COUNT  PIC 9(4).
PROCEDURE DIVISION USING IN-SPAN OUT-COUNT.
*> The called side declares its parameters in the LINKAGE SECTION.
    COMPUTE OUT-COUNT = IN-SPAN * 4 + 2
    GOBACK.
END PROGRAM PLANK-COUNT.

How it works

  1. CALL "PLANK-COUNT" USING SPAN-FT PLANKS passes both fields by reference.
  2. The called program declares its parameters in the LINKAGE SECTION, not storage.
  3. PROCEDURE DIVISION USING ... binds them in order, and GOBACK returns.

Keywords and builtins used here

The run, in numbers

Lines
24
Characters to type
665
Tokens
87
Three-star pace
40 tpm

At the three-star pace of 40 tokens a minute, this run takes about 130 seconds.

Type this snippet

Step 3 of 3 in Functions & calls, step 24 of 27 in Language basics.

← Previous Next →