MOVE Statement
The MOVE
statement transfers data stored in a source location to one or more named target locations.
Format 1
MOVE identifier-1 TO {data-1} …
Format 2
MOVE {CORRESPONDING} src-group-item-1 TO target-group-item-1
{CORR }
Syntax:
identifier-n
is a data element, literal, or data returned from a function call.data-n
is a data item.Src-group-item-n
and target group item n are group data items containing one or more elementary data items.
General Rules:
- A
FORMAT 1 MOVE
statement may name multiple target data fields. - A
FORMAT 1 MOVE
from a group item to another group item is treated as aMOVE
of an alphanumeric data item to an alphanumeric data item. No check of the validity of the moves at the elementary level is made. MOVE
's to and fromUSAGE DISPLAY
data items perform data conversion using theCODEPAGE
module.- The Format 1
MOVE
statement allows for the source of theMOVE
statement to beMOVE
'd to multiple targets. Two sytaxes are supported for aMOVE
to multiple targets. Consider the cases where a variablea
is beingMOVE
'd to three target variablesb
,c
, andd
:MOVE a TO b,c,d.
MOVE a TO b TO c TO d.
The two statements above are functionally equivalent. That is, in each case, the fielda
is the source field for theMOVE
statement, and the value ofa
isMOVE
'd separately to each of the three target variablesb
,c
, andd
.
- A Format 2
MOVE
statement copies the contents of elements insrc-group-item
to elements in target group item which are identified asCORRESPONDING
data elements.- For details on how data items are identified as
CORRESPONDING
, see the Rules for identifying CORRESPONDING data elements section. - A
MOVE CORRESPONDING
statement first identifies allCORRESPONDING
data elements in thesrc-group-item
andtarget-group-item
, and then performs a series ofMOVE
's from the identified data elements in thesrc-group-item
to theirCORRESPONDING
data elements in the target group item. CORRESPONDING
andCORR
are synonyms.
- For details on how data items are identified as
- Rules for justification, space filling, decimal point alignment, and zero filling in the
target-data-element
are described in Rules for Alignment of Data section. - When evaluating the validity of a
MOVE
statement, the compiler assigns data items/literals toPICTURE DATA CATEGORIES
, and then applies certain pre-set rules. - In certain cases, the compiler will report an
“ Error: Invalid MOVE statement ”
, and abort the compilation:ALPHABETIC
data items cannot beMOVE
'd toNUMERIC
orNUMERIC EDITED
data items .NUMERIC
/NUMERIC EDITED
data items be cannot beMOVE
'd toALPHABETIC
data items.ALPHANUMERIC
data items cannot beMOVE
'd toNUMERIC
orNUMERIC EDITED
data items.ALPHANUMERIC EDITED
data items cannot beMOVE
'd toNUMERIC
orNUMERIC EDITED
data items.NUMERIC
non-integer data items cannot beMOVE
'd toALPHANUMERIC
orALPHANUMERIC EDITED
data items.NUMERIC EDITED
data items cannot beMOVE
’d toALPHANUMERIC
data items.
- For details on the different
PICTURE DATA CATEGORIES
, see the Picture Data Categories section. Literals are assignedDATA CATEGORIES
according to the following rules:- Numeric literals are numeric.
- All other literals and figurative contants are alphanumeric, with the following exceptions:
ZERO
is numeric.SPACE
is alphabetic.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. MOVE-1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUMERIC-1 PIC9(5)V9(5) VALUE10.
77 NUMERIC-2 PIC9(5)V9(5) VALUE20.
01 GROUP-1.
03 FLD-1 PIC 99 VALUE 10.
03 FLD-2 PIC 99 VALUE 20.
01 GROUP-2.
03 FLD-1 PIC 99.
03 FLD-2 PIC 99.
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
MOVE NUMERIC-1 TO NUMERIC-2.
MOVE CORRESPONDING GROUP-1 TO GROUP-2.
ACCEPT DUMMY LINE 15 COL 30.
STOP RUN.