MOVE Statement COBOL

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

Format 1:Move…To

Move…To

Format 2:Move Corresponding

Move Corresponding

literal-1 or the data item referenced by identifier-1 represents the sending area; identifier-2 (. . .) represents the receiving area (or areas).

An index data item must not appear as an operand of a MOVE statement.

The data designated by literal-1 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 length evaluation or subscripting associated with identifier-2 is evaluated immediately before the data is moved to the respective data item.Any length evaluation or subscripting associated with identifier-1is evaluated only once, immediately before data is moved to the first of the receiving operands.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).

Any move in which the receiving operand is an elementary item and the sending operand is either a literal or an elementary item is an elementary move.Every elementary item belongs to one of the following categories:numeric, alphabetic, alphanumeric, numeric edited or alphanumeric edited.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, when moved to a numeric or numeric edited item, belongs to the category numeric; in all other cases, it belongs to the category alphanumeric. 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 literal, the figurative constant ZERO, a numeric data item or a numeric edited data item must not be moved to an alphabetic data item.
  3. A noninteger numeric literal or a noninteger numeric data item must not be moved to an alphanumeric or alphanumeric edited data item.
  4. All other elementary moves are legal and are performed according to the rules given below.

Any necessary conversion of data from one form of internal representation to another takes place during legal elementary moves, along with any de-editing implied by the sending data item or editing specified for 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 discussion of standard alignment rules.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, 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).If the sending item is numeric edited, no de-editing takes place.If the usage of the sending operand is different from that of the receiving operand, conversion of the sending operand to the internal representation of the receiving operand takes place.If the PICTURE character-string of the sending operand contains the symbol “P”, all digit positions specified with this symbol are considered to contain the value zero and are counted in the size of the sending item.
  2. When a numeric or numeric edited item is the receiving item, alignment by decimal point and any necessary zero filling takes place (see the discussion of standard alignment rules) where zeroes are replaced because of editing requirements. When a signed item is the receiving item, the sign of the sending item is placed in the receiving item (see the discussion of 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.
  3. 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 the sending operand is described as being alphanumeric, data is moved as if the sending operand were described as an unsigned numeric integer.

    When a numeric edited data item is the sending item, conversion is implied to establish the unedited numeric value of the operand, which may be signed; then the unedited numeric value is moved to the receiving field.The implied conversion deletes all characters other than the decimal digits 0, 1, . . . 9, sets the operational sign negative if a minus sign is present in the sending item or positive otherwise, and sets the scale according to the rightmost decimal point present in the sending item or to the scale of the sending data item otherwise.The representation of the decimal point used in this conversion is a period unless the DECIMAL POINT IS COMMA clause is specified in the source program, in which case a comma is used.In this conversion, any decimal digit 0 that matches an inserted character 0 in the sending item is excluded from the resulting unedited numeric value.

  4. When a receiving field is described as alphabetic, justification and any necessary space-filling takes place.

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.

Any move that is not an elementary move is treated exactly as if 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 such a move, the receiving area is filled without regard for the individual elementary or group items contained within either the sending or receiving area, except as noted in the OCCURS clause.When a group item is moved to an elementary item described with the JUSTIFIED RIGHT clause, right justification occurs. When a sending and receiving item share a part of their storage areas, the result of the execution of such a statement is undefined.

Table summarizes the legality of the various types of MOVE statements.

Types of MOVE Statements and Their Legality

Types of MOVE Statements and Their Legality

CORRESPONDING Phrase

CORRESPONDING Phrase

When the CORRESPONDING phrase is specified, all identifiers must refer to group items.When a MOVE statement with a CORRESPONDING phrase specifies more than one receiving group item (identifier-2), the effect is the same as if multiple MOVE statements with CORRESPONDING phrases had been written, one for each of the receiving group items (identifier-2), and each having the same sending group item (identifier-1).

For the MOVE statement with the CORRESPONDING phrase:

  • The description of identifier-1 and identifier-2 must not contain level-number 66, 77, 78, or 88 or the USAGE IS INDEX clause.
  • Neither identifier-1 nor identifier-2 may be reference modified.
  • identifier-1 or identifier-2 may be described with the OCCURS or REDEFINES clauses or may be subordinate to data items described with the OCCURS or REDEFINES clauses.If identifier-1 or identifier-2
    is a table element, then the required subscripting must be specified as part of identifier-1 or identifier-2.The
    specified subscripting will be applied to the selected subordinate corresponding data items, respectively, for identifier-1 and identifier-2.

For each individual MOVE statement with a CORRESPONDING phrase, subordinate data item pairs are selected, one from the sending group item and one from the receiving group item.Then for each such selected pair, data movement occurs from the data item that is subordinate to the sending group item to the data item that is subordinate to the receiving group item.The data movement that occurs is the same as if individual MOVE statements had been written for each of the selected pairs.

The rules that govern the selection of eligible subordinate data item pairs are as follows:

  1. The data items are not designated by the keyword FILLER and have the same data-name and the same qualifiers up to but not including the original group items, identifier-1 and identifier-2.
  2. At least one of the data items is an elementary data item and the resulting move is legal according to the move rules.
  3. A data item that is subordinate to identifier-1 or identifier-2 and contains a REDEFINES, OCCURS, USAGE IS INDEX, or USAGE IS POINTER clause is ignored, as well as those data items subordinate to the data item that contains the REDEFINES, OCCURS, USAGE IS INDEX, or USAGE IS POINTER clause.
  4. The name of each data item that satisfies the above conditions must be unique after application of the implied qualifiers.

When multiple receiving group identifiers (id entifier-2, . . .) are listed, all corresponding items in the first identifier-2 are moved prior to moving corresponding items in the second and any subsequent receiving group identifiers.

CORRESPONDING and CORR are synonymous.

MOVE Statement Examples


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics