typestar

REDEFINES en COBOL

REDEFINES tiende una segunda estructura sobre los mismos bytes: una fecha, dos vistas.

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.

Cómo funciona

  1. STAMP-RAW guarda ocho caracteres de fecha, 20260802.
  2. STAMP-PARTS REDEFINES STAMP-RAW relee esos bytes como año, mes y día.
  3. Ningún dato se mueve a ninguna parte: ambos nombres describen el mismo almacenamiento.

Palabras clave y builtins usados aquí

El intento, en números

Líneas
14
Caracteres a escribir
429
Tokens
53
Ritmo de tres estrellas
40 tpm

Al ritmo de tres estrellas de 40 tokens por minuto, este intento toma unos 80 segundos.

Escribe este fragmento

Paso 3 de 3 en Mover datos; paso 9 de 27 en Fundamentos del lenguaje.

← Anterior Siguiente →