Rational Developer for System z
COBOL for Windows, Version 7.5, Language Reference


MOVE statement

The MOVE statement transfers data from one area of storage to one or more other areas.

Format 1
Read syntax diagramSkip visual syntax diagram                               .--------------.  
                               V              |  
>>-MOVE--+-identifier-1-+--TO----identifier-2-+----------------><
         '-literal-1----'                        
 

Format 2
Read syntax diagramSkip visual syntax diagram>>-MOVE--+-CORRESPONDING-+--identifier-1--TO--identifier-2-----><
         '-CORR----------'                                  
 

CORR is an abbreviation for, and is equivalent to, CORRESPONDING.

identifier-1, literal-1
The sending area.
identifier-2
The receiving areas. identifier-2 must not reference an intrinsic function.

When format 1 is specified:

When format 2 is specified:

Data items described with the following types of usage cannot be specified in a MOVE statement:

A data item defined with a usage of INDEX, POINTER, FUNCTION-POINTER, PROCEDURE-POINTER, or OBJECT REFERENCE can be part of an alphanumeric group item that is referenced in a MOVE CORRESPONDING statement; however, no movement of data from those data items takes place.

The evaluation of the length of the sending or receiving area can be affected by the DEPENDING ON phrase of the OCCURS clause (see OCCURS clause).

If the sending field (identifier-1) is reference-modified or subscripted, or is an alphanumeric or national function-identifier, the reference-modifier, subscript, or function is evaluated only once, immediately before data is moved to the first of the receiving operands.

Any length evaluation, subscripting, or reference-modification associated with a receiving field (identifier-2) is evaluated immediately before the data is moved into that receiving field.

For example, the result of the statement:

MOVE A(B) TO B, C(B).

is equivalent to:

MOVE A(B) TO TEMP.
MOVE TEMP TO B.
MOVE TEMP TO C(B).

where TEMP is defined as an intermediate result item. The subscript B has changed in value between the time that the first move took place and the time that the final move to C(B) is executed.

For further information about intermediate results, see the COBOL for Windows Programming Guide.

After execution of a MOVE statement, the sending fields contain the same data as before execution.

Note: Overlapping operands in a MOVE statement can cause unpredictable results.

Elementary moves

An elementary move is one in which the receiving item is an elementary data item and the sending item is an elementary data item or a literal.

Valid operands belong to one of the following categories:

Elementary move rules

Any necessary conversion of data from one form of internal representation to another takes place during the move, along with any specified editing in, or de-editing implied by, the receiving item. The code page used for conversion to or from alphanumeric characters is the code page applicable to the specific data item at run time.

The following rules outline the execution of valid elementary moves. When the receiving field is:

Alphabetic:

Alphanumeric or alphanumeric-edited:

DBCS:

External floating-point:

Internal floating-point:

National or national-edited:

Numeric or numeric-edited:

Notes:

  1. If the receiving item is of category alphanumeric, alphanumeric-edited, numeric-edited, national, or national-edited and the sending field is numeric, any digit positions described 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.
  2. If the receiving item is numeric and the sending field is an alphanumeric literal, a national literal, or an ALL literal, all characters of the literal must be numeric characters.

Valid and invalid elementary moves

The following table shows valid and invalid elementary moves for each category. In the table:

Table 46. Valid and invalid elementary moves
  Alpha- betic Alpha- numeric Alpha- numeric edited Numeric Numeric- edited External floating- point Internal floating- point DBCS1 National, national- edited
Alphabetic and SPACE sending item Yes Yes Yes No No No No No Yes
Alphanumeric sending item2 Yes Yes Yes Yes3 Yes3 Yes8 Yes8 No Yes
Alphanumeric-edited sending item Yes Yes Yes No No No No No Yes
Numeric integer and ZERO sending item4 No Yes Yes Yes Yes Yes Yes No Yes
Numeric noninteger sending item5 No No No Yes Yes Yes Yes No No
Numeric-edited sending item No Yes Yes Yes Yes Yes Yes No Yes
Floating-point sending item6 No No No Yes Yes Yes Yes No No
DBCS sending item7 No No No No No No No Yes Yes
National sending item9 No No No Yes Yes Yes Yes No Yes
National-edited sending item No No No No No No No No Yes
  1. Includes DBCS data items.
  2. Includes alphanumeric literals.
  3. Figurative constants and alphanumeric literals must consist only of numeric characters and will be treated as numeric integer fields.
  4. Includes integer numeric literals.
  5. Includes noninteger numeric literals.
  6. Includes floating-point literals, external floating-point data items (USAGE DISPLAY or USAGE NATIONAL), and internal floating-point data items (USAGE COMP-1 or USAGE COMP-2).
  7. Includes DBCS data-items, DBCS literals, and figurative constant SPACE.
  8. Figurative constants and alphanumeric literals must consist only of numeric characters and will be treated as numeric integer fields. The ALL literal cannot be used as a sending item.
  9. Includes national data items, national literals, national functions, and figurative constants ZERO, SPACE, QUOTE, and ALL national literal.

Moves involving date fields

If the sending item is specified as 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 a year-last date field is specified as a receiving item, 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 then performed as if all items were nondates.

Moves involving date fields (Table 47) describes the behavior of moves involving non-year-last date fields. 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, which can be windowed or expanded.

This table uses the following terms to describe the moves:

Normal
The move is performed with no date-sensitive behavior, as if the sending and receiving items were both nondates.
Expanded
The windowed date field sending item is treated as if it were first converted to expanded form, as described under Semantics of windowed date fields.
Invalid
The move is not allowed.

Table 47. Moves involving date fields

Nondate receiving item Windowed date field receiving item Expanded date field receiving item
Nondate sending item Normal Normal Normal
Windowed date field sending item Invalid Normal Expanded
Expanded date field sending item Invalid Normal1 Normal
  1. A move from an expanded date field to a windowed date field is, in effect, a “windowed” move, because it truncates the century component of the expanded date field. If the move is alphanumeric, it treats the receiving windowed date field as if its data description specified JUSTIFIED RIGHT. This is true even if the receiving windowed date field is a group item, for which the JUSTIFIED clause cannot be specified.

Moves involving file record areas

The successful execution of an OPEN statement for a given file makes the record area for that file available. You can move data to or from the record description entries associated with a file only when the file is in the open status. Execution of an implicit or explicit CLOSE statement removes a file from open status and makes the record area unavailable.

Group moves

A group move is any move in which an alphanumeric group item is a sending item or a receiving item, or both. The following are group moves:

A group move is treated as though it were an alphanumeric-to-alphanumeric elementary move, except that there is no conversion of data from one form of internal representation to another. In a group move, the receiving area is filled without consideration for the individual elementary items contained within either the sending area or the receiving area, except as noted in the OCCURS clause. (See OCCURS clause.)


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)