MOVE Rules

MOVE copies and converts data according to the categories of the sending and receiving items.

12.1 The MOVE statement

MOVE copies and converts data according to the categories of the sending and receiving items.

MOVE source TO target-1 target-2 ...
           MOVE "ACME" TO WS-COMPANY
           MOVE ZERO TO WS-TOTAL WS-COUNT
           MOVE SPACES TO OUTPUT-LINE
           MOVE CORRESPONDING IN-REC TO OUT-REC

12.2 Category rules

Sending → Receiving Alphanumeric → alphanumeric Left-justified; padded with spaces on the right; truncated on the right if too long (unless JUSTIFIED RIGHT) Numeric → numeric

Aligned on the decimal point; padded with zeros; high-order integer digits and low-order decimals are truncated (no error!); sign handled Numeric → numeric-edited

Aligned and edited per the PICTURE (Chapter 8) Numeric (integer) → alphanumeric

Treated as an unsigned integer string of digits Alphanumeric → numeric

Treated as an unsigned integer; non-digits produce invalid data (avoid; use NUMVAL) Numeric-edited → numeric

De-editing: the numeric value is recovered (COBOL-85+) Group → anything / anything → group

Plain alphanumeric byte copy with no conversion — beware of packed or binary fields

12.3 Examples

(GnuCOBOL warns at compile time that some literals will be truncated — that is the point of the demo.) Note that WS-NUM-A displays as 12345 because V is an *implied* decimal point; 1234 moved to PIC 99 silently becomes 34; and −42 moved to an unsigned field loses its sign. These silent truncations are among the most common COBOL bugs — size your fields generously and use ON SIZE ERROR in arithmetic.

01  WS-SHORT              PIC X(5).
       01  WS-RIGHT              PIC X(8) JUSTIFIED RIGHT.
       01  WS-NUM-A              PIC 9(3)V99.
       01  WS-NUM-B              PIC 9(5)V9.
       01  WS-SMALL              PIC 99.
       01  WS-UNSIGNED           PIC 9(3).
      * ...
           MOVE "ABCDEFGH" TO WS-SHORT      *> "ABCDE"
           MOVE "ABC"      TO WS-RIGHT      *> "     ABC"
           MOVE 123.456    TO WS-NUM-A      *> 123.45, displays 12345
           MOVE WS-NUM-A   TO WS-NUM-B      *> 00123.4, displays 001234
           MOVE 1234       TO WS-SMALL      *> 34 - high digits lost!
           MOVE -42        TO WS-UNSIGNED   *> 042 - sign lost

12.4 MOVE CORRESPONDING

Moves each elementary item whose name matches in both groups (here CUST-ID and CUST-NAME). Convenient but can hide data flow; many shops ban it.

01  IN-REC.
           05  CUST-ID          PIC 9(6).
           05  CUST-NAME        PIC X(20).
           05  CUST-PHONE       PIC X(12).
       01  OUT-REC.
           05  CUST-NAME        PIC X(30).
           05  FILLER           PIC X(2) VALUE SPACES.
           05  CUST-ID          PIC Z(5)9.
      * ...
           MOVE CORRESPONDING IN-REC TO OUT-REC