MOVE statement is used to assign a value to one or more variables from another variable or literal. MOVE statement actually transfers the data from one memory location to one or more memory locations.

In MOVE statement, sending data item should be only one. In MOVE statement, receiving data item can be more than one. The sending data item, receiving data item can be a group item or elementary item.

During the MOVE statement execution, the receiving data items data completely replaced by sending data item data. The receiving item is an elementary data item and the sending item is an elementary data item or a literal is called elementary move.

Valid operands belong to one of the following categories -

  • Alphabetic
  • Alphanumeric
  • Alphanumeric-edited
  • External floating-point
  • Internal floating-point
  • Numeric
  • Numeric-edited

Move Types -

MOVE statements are classified into below based on its usage in the program -

  1. Simple MOVE
  2. Group MOVE
  3. Corresponding MOVE
  4. MOVE Referencing Modification

Move Rules -

In some scenarios, data conversion required if the target data item data type is different. The conversion automatically takes place during the MOVE from one form of internal representation to another whenever required.

This includes along with editing in or de-editing implied by the receiving item. The following rules outline the execution of elementary moves when the receiving field is -

Alphabetic -

Alphabetic data alignment is from left to right.If the size of the sending item is less than the size of the receiving item, the receiving item is filled from left to right and the remaining positions are filled with SPACES.

If the size of the sending item is greater than the size of the receiving item, excess characters on the right are truncated after the receiving item is filled.

Alphanumeric or alphanumeric-edited -

If the sending item is a decimal integer item, the sending data is converted to usage DISPLAY and moved to a temporary data item of category alphanumeric with the same number of character positions as the sending item. The resulting alphanumeric data item is treated as the sending item.

Alphanumeric data alignment is from left to right. If the size of the sending item is less than the size of the receiving item, the receiving item is filled from left to right and the remaining positions are filled with SPACES.

If the size of the sending item is greater than the size of the receiving item, excess characters on the right are truncated after the receiving item is filled.

If the initial sending item has sign, the sign ignores and unsigned value is used. If the sign occupies a separate character, the sign character is not moved and the size of the sending item is considered one less character than the actual size.

External floating-point -

For a floating-point sending item, the floating-point value is converted to the usage of the receiving external floating-point item. For other sending items, the numeric value is converted to internal floating-point and then converted to the usage of the receiving external floating-point item.

Internal floating-point -

If the sending operand value is not internal floating-point, the value is converted to internal floating-point format.

Numeric or numeric-edited -

Numeric data alignment is from right to left.

If the receiving item is signed, the sign is placed in the receiving item with any necessary sign conversion. If the sending item is unsigned, a positive operational sign is generated for the receiving item.

If the receiving item is unsigned, no sign is generated for the receiving item and the absolute value is used in the move. When the category of the sending item is alphanumeric, alphanumeric-edited, the data is moved as an unsigned integer.

When the sending item is floating-point, the data is first converted to either a binary or internal decimal representation and then moved. When the receiving item is numeric-edited, editing takes place as defined by the picture character string or BLANK WHEN ZERO clause associated with the receiving item.

When the sending item is numeric-edited, the compiler de-edits the sending data to establish the unedited value and then unedited value is used in the move to the receiving numeric or numeric-edited data item.

Date Fields -

If the sending item is a year-last date field, then all receiving fields must also be year-last date fields with the same date format as the sending item.

If receiving item is a year-last date field, then the sending item must be either a nondate or a year-last date field with the same date format as the receiving item. In both cases, the move is performed as if all items were nondates.

If the sending item is a date field, then the receiving item must be a compatible date field. If the sending and receiving items are both date fields, then they must be compatible (that is, they must have the same date format, except for the year part).

Note-1! If the receiving item is of category alphanumeric, alphanumeric-edited or numeric-edited, the sending field is numeric and any digit positions with picture symbol P in the sending item are considered to have the value zero. Each P is counted in the size of the sending item.

Note-2! If the receiving item is numeric and the sending field is an alphanumeric literal or an ALL literal, all characters of the literal must be numeric characters.

MOVE Combinations -

The below table represents the valid and invalid moves using MOVE statement foreach category. In the table, column headings indicate receiving item categories, row headings indicate sending item categories.

This table represents the data movement from data types (left) to data types (top).
Y = Move is valid, N = Move is invalid.
Alphabetic Alpha-numeric Alpha-numeric edited Numeric Numeric edited External floating-point Internal floating-point
Alphabetic and SPACE Y Y Y N N N N
Alphanumeric Y Y Y Y Y Y Y
Alphanumeric-edited Y Y Y N N N N
Numeric integer and ZERO N Y Y Y Y Y Y
Numeric non-integer N N N Y Y Y Y
Numeric-edited N Y Y Y Y Y Y
Floating-point N N N Y Y Y Y