typestar

MOVE semantics in COBOL

MOVE fits the sender to the receiver: padding with spaces one way, cutting the other.

IDENTIFICATION DIVISION.
PROGRAM-ID. MOVE-SEMANTICS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LONG-NAME   PIC X(12) VALUE "Persephone".
01 WIDE-NAME   PIC X(16).
01 SHORT-NAME  PIC X(6).
PROCEDURE DIVISION.
*> MOVE fits the sender to the receiver: pad with spaces, or cut.
    MOVE LONG-NAME TO WIDE-NAME
    MOVE LONG-NAME TO SHORT-NAME
    DISPLAY "Padded:    [" WIDE-NAME "]"
    DISPLAY "Truncated: [" SHORT-NAME "]"
    STOP RUN.

How it works

  1. Three alphanumeric fields differ only in width: 12, 16, and 6 characters.
  2. Moving into the wider field left-justifies and pads with trailing spaces.
  3. Moving into the narrow field keeps the left six characters and drops the rest.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
416
Tokens
50
Three-star pace
40 tpm

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

Type this snippet

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

← Previous Next →