Simple MOVE Statement
Simple MOVE Statement
- It is used to move the value of the sending item(s) is moved to the receiving item.
- The sending and receiving data items should be declared with compatible data type to avoid data transferring errors.
- The simple MOVE operation is one of the most basic data manipulation statements in the COBOL language, and it's helpful in transferring values.
Syntax -
MOVE source-item TO destination-item-1
[destination-item-2 ...]
Note! All statements coded in [ ] are optional.
Parameters -
- source-item - Refers the source data item from which we wish to move the data.
- destination-item-1, destination-item-2, ... - One or more destination items to which we wish to move the data.
Notes -
- The sending item can be a numeric, alphabetic, alphanumeric, literal, or figurative constant.
- The receiving item should be a numeric, alphabetic, alphanumeric, but not a literal or a figurative constant.
- MOVE statement can have one or more receiving items.
Practical Example -
Scenario - Simple MOVE statement coding in COBOL program.
Code -
----+----1----+----2----+----3----+----4----+----5----+
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-VAR1 PIC 9(04) VALUE 2561.
05 WS-VAR2 PIC 9(06).
05 WS-VAR3 PIC 9(02).
PROCEDURE DIVISION.
MOVE WS-VAR1 TO WS-VAR2
WS-VAR3.
DISPLAY 'WS-VAR1: ' WS-VAR1.
DISPLAY 'WS-VAR2: ' WS-VAR2.
DISPLAY 'WS-VAR3: ' WS-VAR3.
...
Output -
WS-VAR1: 2561 WS-VAR2: 002561 WS-VAR3: 61