typestar

INITIALIZE in COBOL

One INITIALIZE wipes a whole record: numbers to zero, text to spaces.

IDENTIFICATION DIVISION.
PROGRAM-ID. INITIALIZE-FIELDS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TALLY-CARD.
   05 GOOD-CRATES  PIC 999  VALUE 42.
   05 BAD-CRATES   PIC 999  VALUE 3.
   05 GRADE-STAMP  PIC X(5) VALUE "AA-1".
PROCEDURE DIVISION.
    DISPLAY "Before: " GOOD-CRATES " " BAD-CRATES " " GRADE-STAMP
*> INITIALIZE resets numbers to zero and text to spaces.
    INITIALIZE TALLY-CARD
    DISPLAY "After:  " GOOD-CRATES " " BAD-CRATES " " GRADE-STAMP
    STOP RUN.

How it works

  1. The TALLY-CARD group starts with live values in all three fields.
  2. The first DISPLAY proves the starting state.
  3. INITIALIZE TALLY-CARD resets by category — numeric to zeros, alphanumeric to spaces.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
451
Tokens
57
Three-star pace
40 tpm

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

Type this snippet

Step 2 of 3 in Moving data, step 8 of 27 in Language basics.

← Previous Next →