The MOVE Statement

The MOVE statement transfers data, in accordance with the rules of editing, to one or more data areas.

General Formats for Format 1


Syntax for format 1 of the MOVE statement

General Formats for Format 2


Syntax for format 2 of the MOVE statement

Directives

  1. In addition to Compiler directives which provide flagging and modify the reserved word list, the following directives may impact either the syntax or the semantics described in this section.
    • BYTE-MODE-MOVE - impacts the behavior of MOVE statements in which the sending and receiving items share a part of their storage (that is, overlapping moves).
    • DBCS (DBSPACE) - impacts what characters are used for space-filling DBCS receiving items.
    • DE-EDIT - controls whether the value of numeric-edited sending fields is determined by their PICTURE clause or not.
    • TRUNC - determines whether truncation occurs based on the storage available or the PICTURE clause, when the sending item includes a value larger than a binary receiving value's size.

Syntax Rules for All Formats

  1. Identifier-1 and literal represent the sending area; identifier-2 represents the receiving area.
  2. An index-name or an index data item may not be specified as an operand of a MOVE statement.
  3. MF If the sending or receiving item is a pointer data item or an ADDRESS OF operand, then the other operands of the MOVE statement must also be pointer data items or ADDRESS OF operands or, in the case of the sending item, NULL.
  4. MF If the sending or receiving item is an object reference, a program-pointer, an entry-pointer, a monitor-pointer, a mutex-pointer, a semaphore-pointer or a thread-pointer, then all other operands of the MOVE statement must be of the same type or, in the case of the sending item, NULL.
  5. VSC2MF If either the sending or receiving item is a DBCS (USAGE DISPLAY-1) item, then both must be DBCS items. The figurative constant SPACE can be the DBCS sending item.

Syntax Rules for Format 1

  1. OSVSVSC2MF When Format 1 is specified, all identifiers can reference alphanumeric group items, national group items

    ENTMF , UTF-8 group items

    , or elementary items. The data in the sending area is moved into the data item referenced by each identifier-2 in the order in which it is specified.
  2. MF Identifier-1 may be a numeric function-identifier.
  3. If identifier-1 is a data item described with USAGE BINARY-CHAR, USAGE BINARY-SHORT, USAGE BINARY-LONG or USAGE BINARY-DOUBLE, identifier-2 must be a numeric or numeric-edited item; otherwise, see Table 1, MOVE Statement Data Categories, below which specifies the validity of the move.

Syntax Rules for Format 2

  1. CORR is an abbreviation for CORRESPONDING.
  2. When the CORRESPONDING phrase is used, all identifiers must be group items.
  3. The following items can be part of a group that is referenced in a MOVE CORRESPONDING statement; however, no movement of this item takes place:
    • VSC2MF POINTER, PROCEDURE-POINTER
    • ENTMF POINTER-32
    • ISO2002MF  OBJECT-REFERENCE, PROGRAM-POINTER
    • MF  EVENT-POINTER, MONITOR-POINTER, MUTEX-POINTER, SEMAPHORE-POINTER, THREAD-POINTER.

General Rules for All Formats

  1. MF If identifier-1 is a numeric function-identifier, then identifier-2 must be either a numeric or numeric-edited item.
  2. The data designated by the literal or identifier-1 is moved to the data item referenced by each identifier-2, in the order in which it is specified. The rules referring to identifier-2 also apply to the other receiving areas. Any subscripting or indexing associated with identifier-2, is evaluated immediately before the data is moved to the respective data item.

    ANS85 If identifier-1 is reference modified, subscripted, or is a function-identifier, the reference modifier, subscript, or function-identifier is evaluated only once, immediately before data is moved to the first of the receiving operands.

    ANS85 The result of the statement:

    ANS85 
     MOVE a(b) TO b, c(b)

    ANS85 is equivalent to:

    ANS85 
     MOVE a(b) TO temp MOVE temp TO b MOVE temp TO c(b)

    ANS85 where temp is an intermediate result item provided by your COBOL system.

  3. Any MOVE in which the sending and receiving items are both elementary items is an elementary move. Every elementary item belongs to one of the following categories: numeric, alphabetic, alphanumeric, numeric-edited, alphanumeric-edited

    ISO2002MF national, national-edited, boolean

    ENTMF , UTF-8,

    OSVSVSC2MF or floating-point.

    These categories are described in the PICTURE clause. Numeric literals belong to the category numeric, and nonnumeric literals belong to the category alphanumeric. The figurative constant ZERO belongs to the category numeric when moved to a numeric or numeric-edited item. The figurative constant ZERO belongs to the category alphanumeric in all other cases. The figurative constant SPACE belongs to the category alphabetic. All other figurative constants belong to the category alphanumeric.

    The following rules apply to an elementary move between these categories:

    1. The figurative constant SPACE, or an alphanumeric-edited, or alphabetic data item must not be moved to a numeric or numeric-edited data item.
    2. A numeric-edited data item must not be moved to a numeric or numeric-edited data item

      ISO2002MF , or boolean

      .

      ANS85 This restriction is removed.

    3. A numeric literal, the figurative constant ZERO, a numeric data item or a numeric-edited data item

      ISO2002MF , or a boolean data item

      must not be moved to an alphabetic data item.
    4. A non-integer numeric literal or a non-integer numeric data item must not be moved to an alphanumeric or alphanumeric-edited data item

      ISO2002MF , or boolean data item

      .
    5. ISO2002MF If identifier-2 is a boolean data item, it can only receive figurative constants whose associated characters are boolean characters.
    6. ISO2002MF An alphabetic, alphanumeric-edited, numeric, or national data item must not be moved to a boolean data item.
    7. ISO2002MF A boolean data item must not be moved to a national data item.
    8. ENTMF When moving non-UTF-8 items to a UTF-8 item, the sending characters are converted to UTF-8. They are converted as if moved to temporary data items of category UTF-8 and with sufficient length to not cause any padding or truncation. The resulting category UTF-8 item is treated as the sending data item.
    9. ENTMF If sending an item of class UTF-8 to another item of class UTF-8, no conversion is performed during the move.
    10. ENTMF Due to any alignment and any padding or truncation that may occur during a UTF-8 move, the programmer is responsible for ensuring that multiple encoding units that together form a graphic character are not split by truncation.
    11. ENTMF  If the receiving item is a dynamic-length elementary item, its length is set to the minimum of the length of the sender or the explicit or implied value of the LIMIT phrase. If the sending item's length is greater than that of the receiving item, truncation of the excess characters on the right occurs.
    12. All other elementary moves are legal and are performed according to the rules given in General Rule 5.
  4. Any necessary conversion of data from one form of internal representation to another takes place during legal elementary moves, along with any editing specified for

    ANS85 , or de-editing implied by,

    the receiving data item:
    1. When an alphanumeric-edited or alphanumeric item is a receiving item, alignment and any necessary space-filling takes place as defined in the topic Standard Alignment Rules in the chapter Concepts of the COBOL Language. If the size of the sending item is greater than the size of the receiving item, the excess characters are truncated on the right after the receiving item is filled. If the sending item is described as being signed numeric, the operational sign is not moved; if the operational sign occupies a separate character position (see the topic The SIGN Clause), that character is not moved and the size of the sending item is considered to be one less than its actual size (in terms of standard data format characters).
    2. When a numeric or numeric-edited item is the receiving item, alignment by decimal point and any necessary zero-filling takes place as defined in the section Standard Alignment Rules in the chapter Concepts of the COBOL Language, except where zeros are replaced because of editing requirements.

      ANS85 When the sending operand is numeric-edited, de-editing is implied to establish the operand's unedited numeric value, which can be signed; then the unedited numeric value is moved to the receiving field. The effect of de-editing depends on the setting of the DE-EDIT Compiler directive

      When a signed numeric item is the receiving item, the sign of the sending item is placed in the receiving item. (See the topic The SIGN Clause.) Conversion of the representation of the sign takes place as necessary. If the sending item is unsigned, a positive sign is generated for the receiving item.

      When an unsigned numeric item is the receiving item, the absolute value of the sending item is moved and no operational sign is generated for the receiving item.

      When a data item described as alphanumeric is the sending item, data is moved as if the sending item were described as an unsigned numeric integer.

      When the receiving item is numeric or numeric-edited and the sending item is defined as alphanumeric, if the content of the sending item is not an integer, the results of the move are undefined. If the alphanumeric sending item is a literal whose contents do not represent an integer, an error is reported, and zero moved to the target. (See the topic Incompatible Data in the chapter Procedure Division.)

      ANS85 When the numeric data item is the sending item the action of the move is such that a reverse of the move would cause the same value to appear in the numeric-edited field (except for truncation). If the data item contains data which does not conform to the edited picture, zero is moved to the target.

    3. When a receiving field is described as alphabetic, justification and any necessary space-filling takes place as defined in the topic Standard Alignment Rules in the chapter Concepts of the COBOL Language. If the size of the sending item is greater than the size of the receiving item, the excess characters are truncated on the right after the receiving item is filled.
    4. OSVSVSC2MF When the receiving field is floating-point, the sending item is converted first to internal floating-point and then moved. When data is moved to or from an external floating-point item, the data is converted first to or from its equivalent internal floating-point value.
    5. VSC2MF When the receiving field is non-NCHAR DBCS, the sending item must be DBCS or national; no conversion takes place. If the sending and receiving items are not the same size the data item is either truncated or padded with DBCS spaces on the right.
  5. Any move that is not an elementary move is treated exactly as if it were an alphanumeric to alphanumeric elementary move, except that no conversion of data from one form of internal representation to another takes place. In such a move, the receiving area is filled without consideration for the individual elementary or group items contained in either the sending or receiving area, except as noted in the General Rules of the OCCURS clause.
  6. Table 1 below summarizes the legality of the various types of MOVE statements. The general rule reference indicates the rule that prohibits the move or the behavior of a legal move.
  7. ISO2002MF When the receiving field is boolean, the boolean value of the sending item is moved, with conversion of data representation if necessary, and any necessary alignment and zero filling as defined in the topic Standard Alignment Rules in the sectionConcepts of the COBOL Language. If the sending field is not boolean, it is treated as if it were a boolean data item with the same usage and number of character positions as the sending field. If the content of the sending field would result in a false value in a boolean class condition, an error is reported (see the topic Incompatible Data in the section Procedure Division.)
  8. The following table shows a summary of permissible moves, with reference to more detailed explanations within this topic:
    Category of Sending Item Category of Receiving Data Items (the relevant rule number is quoted in these columns)
    Alphabetic Alphanumeric-Edited/ Alpha-numeric Numeric Integer/Non-Integer Numeric-Edited External/Internal Floating Point National Non-NCHAR DBCS NCHAR DBCS Boolean UTF-8
    Alphabetic Yes/4c Yes/4a No/3a No/3a Yes No/4e Yes No/3f Yes
    Alphanumeric Yes/4c Yes/4a Yes/4b Yes/4b Yes No/4e Yes Yes/3e Yes
    Alphanumeric-Edited Yes/4c Yes/4a No/3a No/3a Yes No/4e Yes No/3f Yes
    Numeric Integer No/3c Yes/4a Yes/4b Yes/4b Yes No/4e Yes No/3f No
    Numeric Non-Integer No/3c No/3c Yes/4b Yes/4b No No/4e No No/3f No
    Numeric-Edited No/3c Yes/4a Yes/4b Yes/4b Yes No/4e Yes No/3f Yes
    National No No Yes Yes Yes Yes Yes No Yes
    Non-NCHAR DBCS No/4e No/4e No/4e No/4e Yes Yes/4e Yes No/3f No
    NCHAR DBCS Yes Yes No No Yes Yes/4e Yes No No
    Boolean No/3c Yes/4a No/3b No/3b No No/3g No Yes/4f No
    UTF-8 No No No No Yes No No No Yes
    Note: An error is reported if a non-integer alphanumeric literal sending item is used

    For more information on NCHAR DBCS support, refer to Micro Focus Extensions for Double-byte Character Set Support, and for more information on non-NCHAR DBCS support, refer to Double-byte Character Set Support.

General Rules for Format 1

  1. ENTMF When either identifier references a national group item and the other operand references an alphanumeric group item, the national group is processed as a group item; in all other cases, the national group item is processed as an elementary data item of category national.
  2. ENTMF When either identifier references a UTF-8 group item and the other operand references an alphanumeric group item, the UTF-8 group is processed as a group item; in all other cases, the UTF-8 group item is processed as an elementary data item of category UTF-8.
  3. ENTMF UTF-8 group items are processed as group items, and not as elementary data items of category UTF-8.

General Rules for Format 2

  1. If the CORRESPONDING phrase is used, selected items in identifier-1 are moved to selected items in identifier-2, according to the rules given in The CORRESPONDING Phrase in the chapter Procedure Division. The results are the same as if you had referred to each pair of corresponding identifiers in separate MOVE statements.

    OSVSVSC2 The process is repeated for each destination group.

  2. ENTMF  Dynamic-length group items can not be moved to or from another group item.