codegurukool.com · Free coding tutorials & online compiler

Home › COBOL Tutorial › COBOL MOVE

COBOL MOVE

Copy values into variables.

MOVE source TO target copies a value. Text is cut or padded to fit the target. Numbers are aligned on the decimal point, and digits that do not fit on the left are lost (truncation), so always make a PIC big enough.

Example code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MOVES.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 A       PIC 99 VALUE 10.
       01 B       PIC 99.
       01 NAME-1  PIC X(10).
       PROCEDURE DIVISION.
           MOVE A TO B.
           DISPLAY B.
           MOVE "Hello" TO NAME-1.
           DISPLAY FUNCTION TRIM(NAME-1).
           MOVE 123 TO B.
           DISPLAY B.
           STOP RUN.

Run this code in the online editor

← COBOL variables and PICTURECOBOL strings: STRING, INSPECT and slices →