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-nis a data element, literal, or data returned from a function call.data-nis a data item.Src-group-item-nand target group item n are group data items containing one or more elementary data items.
General Rules:
- A
FORMAT 1 MOVEstatement may name multiple target data fields. - A
FORMAT 1 MOVEfrom a group item to another group item is treated as aMOVEof 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 DISPLAYdata items perform data conversion using theCODEPAGEmodule.- The Format 1
MOVEstatement allows for the source of theMOVEstatement to beMOVE'd to multiple targets. Two sytaxes are supported for aMOVEto multiple targets. Consider the cases where a variableais 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 fieldais the source field for theMOVEstatement, and the value ofaisMOVE'd separately to each of the three target variablesb,c, andd.
- A Format 2
MOVEstatement copies the contents of elements insrc-group-itemto elements in target group item which are identified asCORRESPONDINGdata elements.- For details on how data items are identified as
CORRESPONDING, see the Rules for identifying CORRESPONDING data elements section. - A
MOVE CORRESPONDINGstatement first identifies allCORRESPONDINGdata elements in thesrc-group-itemandtarget-group-item, and then performs a series ofMOVE's from the identified data elements in thesrc-group-itemto theirCORRESPONDINGdata elements in the target group item. CORRESPONDINGandCORRare 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-elementare described in Rules for Alignment of Data section. - When evaluating the validity of a
MOVEstatement, 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:ALPHABETICdata items cannot beMOVE'd toNUMERICorNUMERIC EDITEDdata items .NUMERIC/NUMERIC EDITEDdata items be cannot beMOVE'd toALPHABETICdata items.ALPHANUMERICdata items cannot beMOVE'd toNUMERICorNUMERIC EDITEDdata items.ALPHANUMERIC EDITEDdata items cannot beMOVE'd toNUMERICorNUMERIC EDITEDdata items.NUMERICnon-integer data items cannot beMOVE'd toALPHANUMERICorALPHANUMERIC EDITEDdata items.NUMERIC EDITEDdata items cannot beMOVE’d toALPHANUMERICdata items.
- For details on the different
PICTURE DATA CATEGORIES, see the Picture Data Categories section. Literals are assignedDATA CATEGORIESaccording to the following rules:- Numeric literals are numeric.
- All other literals and figurative contants are alphanumeric, with the following exceptions:
ZEROis numeric.SPACEis 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.