typestar

REDEFINES in COBOL

REDEFINES lays a second layout over the same bytes: one date, two views.

IDENTIFICATION DIVISION.
PROGRAM-ID. REDEFINES-VIEWS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STAMP-RAW    PIC X(8) VALUE "20260802".
01 STAMP-PARTS REDEFINES STAMP-RAW.
   05 STAMP-YEAR  PIC 9(4).
   05 STAMP-MONTH PIC 99.
   05 STAMP-DAY   PIC 99.
PROCEDURE DIVISION.
*> REDEFINES lays a second layout over the same bytes.
    DISPLAY "Raw stamp: " STAMP-RAW
    DISPLAY "Year " STAMP-YEAR ", month " STAMP-MONTH ", day " STAMP-DAY
    STOP RUN.

How it works

  1. STAMP-RAW holds eight characters of date, 20260802.
  2. STAMP-PARTS REDEFINES STAMP-RAW re-reads those bytes as year, month, and day.
  3. No data moves anywhere: both names describe the same storage.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
429
Tokens
53
Three-star pace
40 tpm

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

Type this snippet

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

← Previous Next →