typestar

WORKING-STORAGE in COBOL

Three level 01 items declare the lighthouse's data before any statement runs.

IDENTIFICATION DIVISION.
PROGRAM-ID. WORKING-STORAGE-TOUR.
DATA DIVISION.
WORKING-STORAGE SECTION.
*> Level 01 items declare a name, a picture, and often a value.
01 STATION-NAME  PIC X(12) VALUE "Gull Rock".
01 LAMP-TURNS    PIC 9(3)  VALUE 148.
01 OIL-GALLONS   PIC 9(2)V9 VALUE 6.5.
PROCEDURE DIVISION.
    DISPLAY "Station: " STATION-NAME
    DISPLAY "Turns tonight: " LAMP-TURNS
    DISPLAY "Oil on hand: " OIL-GALLONS " (V marks an unseen point)"
    STOP RUN.

How it works

  1. DATA DIVISION. and WORKING-STORAGE SECTION. open the data half of the program.
  2. Each 01 item pairs a name with a PIC picture and an optional starting VALUE.
  3. 9(2)V9 stores digits only — the V marks a decimal point that is never written.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
450
Tokens
48
Three-star pace
40 tpm

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

Type this snippet

Step 2 of 3 in The program shape, step 2 of 27 in Language basics.

← Previous Next →