MOVE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
MOVE Statement
The MOVE statement transfers data to one or more data areas in accordance
with the rules of editing.
Syntax
The MOVE statement has two general formats:
Parameters
identifier-1 and the sending areas. The special registers, TALLY,
literal-1 TIME-OF-DAY, CURRENT-DATE, and WHEN-COMPILED may be
used as sending items.
identifier-2 and its subsequent occurrences, are the receiving
areas.
CORR an abbreviation for CORRESPONDING. An index data
item cannot be used as an operand of a MOVE
statement.
Description
If you use format 2, both identifiers must be group items. Selected
items are moved from within identifier-1 to selected items within
identifier-2. The results are the same as if you referred to each pair
of corresponding identifiers in separate MOVE statements. The rules
governing correspondence are presented in Chapter 8 under the
heading, "CORRESPONDING Phrase".
If you use format 1, the data designated by literal-1, or by identifier-1
is moved, in turn, to identifier-2. Any subscripting or indexing
associated with identifiers to the right of the keyword TO is evaluated
immediately before the data is moved to the respective data items.
Any subscripting, indexing,[REV BEG] reference modification, or
function[REV END] associated with identifier-1 is evaluated only once,
immediately before the data is moved to the first of the receiving
operands.
For example, the result of the following statement:
MOVE A(B) TO B, C(B)
Is equivalent to the following three statements:
MOVE A(B) TO temp
MOVE temp TO B
MOVE temp TO C(B)
Where temp is an intermediate result item used internally by the
compiler. Note that the move of A(B) to B affects the element of C to
which A(B) is moved. That is, if B is initially one and A(B) is 9, then
after 9 is moved to B, A(1) is moved to C(9). It is not moved to C(1).
Rules For Moving Data
All data is moved according to the rules for moving elementary data items
to elementary data items. This is called an elementary move. Valid and
invalid moves are determined by the categories of the sending and
receiving data items. Refer to "PICTURE Clause" in Chapter 7 for a
description of the various categories.
Any move that is not an elementary move is treated exactly as if it were
a move from one alphanumeric elementary data item to another, except that
there is no conversion from one form of internal representation to
another. In such a move, the receiving data item is filled without
respect to the individual elementary or group items contained in either
the sending or receiving area, except when the sending data item contains
a table whose OCCURS clause uses the DEPENDING ON clause. In this case,
only the area specified by the DEPENDING ON clause is filled or moved.
When a receiving item is a variable length data item and contains the
object of the DEPENDING ON phrase, the maximum length of the item is
used.
If the move is from a group to an elementary item, justification takes
place if specified in the receiving item.
Rules For Elementary Moves
The following rules apply to an elementary move between data items
belonging to one of the five categories of data:
* All numeric literals and the figurative constant ZERO belong to
the numeric category; all nonnumeric literals, and all figurative
constants except SPACE and ZERO belong to the alphanumeric
category; SPACE belongs to the alphabetic category.
* An alphanumeric-edited or alphabetic data item cannot be moved to
a numeric or numeric-edited data item.
* A numeric or numeric-edited data item cannot be moved to an
alphabetic data item.
* A noninteger numeric literal or noninteger numeric data item
cannot be moved to an alphanumeric or alphanumeric-edited data
item.
* All other elementary moves are valid and are performed according
to the rules listed below.
Any necessary conversion from one internal representation to another
takes place during valid elementary moves, as does any editing specified
for, or de-editing implied by, the receiving data item.
Alphanumeric or Alphanumeric-Edited Receiving Item
When an alphanumeric-edited or alphanumeric item is a receiving data
item, alignment and any necessary space filling takes place as defined
under "Data Alignment" in Chapter 4 . If the size of the sending item
is larger than the receiving item, the excess characters are truncated on
the right after the receiving data item is filled.
If the sending item is a signed numeric item, the sign is not moved,
regardless of whether the sign is separate or not. If the sign is
separate, however, the sending item is considered to be one character
shorter than its actual size. If the sending operand is numeric-edited,
no de-editing takes place. If the usage of the sending operand is
different from that of the receiving operand, the sending operand is
converted to the internal representation of the receiving operand. If
the sending operand is numeric and contains the PICTURE symbol 'P', all
digit positions specified with this symbol are considered to have the
value zero and are counted in the size of the sending operand.
Numeric or Numeric-Edited Receiving Item
When a numeric or numeric-edited item is the receiving item, alignment by
decimal point and any necessary zero filling is performed as defined
under "Data Alignment" in Chapter 4 . The exception to this rule is
when zeros are replaced because of editing requirements of the receiving
data item.
For signed numeric receiving items, the sign of the sending item is
placed in the receiving item. An unsigned numeric sending item causes a
positive sign to be generated for the receiving item. Also, any
conversion of the representation of the sign, such as from a zoned
overpunched sign to a separate sign, is done as necessary.
For an unsigned numeric receiving item, the absolute value of the sending
item is moved and no operational sign is generated for the receiving
item.
For an alphanumeric sending item, data is moved as if the sending item
were described as an unsigned numeric integer. The ANSI limit for the
length of a numeric item is 18 digits; however, HP COBOL II extends the
limit to the length of an intermediate result, as defined in the COMPUTE
statement.
When the sending operand is numeric-edited, de-editing is implied to
establish the operand's unedited numeric value, which may be signed;
then the unedited numeric value is moved to the receiving field. This
means that blanks are converted to zeros and insertion characters and
floating characters are stripped. Any sign characters are translated
into the proper internal form of the sign described by the USAGE
clause.
Alphabetic Receiving Item
When a receiving field is described as alphabetic, justification and any
necessary space filling is performed as specified under "Data Alignment"
in Chapter 4 . If the size of the sending data item is larger than
the receiving data item, the excess characters are truncated to the right
after the receiving item is filled.
Table 9-2 summarizes the rules presented above.
Table 9-2. Permissible Moves
Example
FILE SECTION.
FD FILE-IN.
01 FILE-REC.
02 EMP-FIELD.
03 NAME PIC X(20).
03 AGE PIC 99.
03 EMP-NO PIC X(9).
02 LOCALE PIC X(35).
:
WORKING-STORAGE SECTION.
01 FIELD.
02 SUB-F1 PIC BBXX VALUE SPACES.
02 SUB-F2 PIC XX/XX/XX VALUE SPACES.
01 NUM-IN PIC S9(3)V99 VALUE -12099.
01 CARD-NUM PIC S9(3)V99 SIGN IS TRAILING VALUE ZERO.
01 NUM-JUNK PIC S9(5) VALUE -12345
01 INFO-OUT.
02 EMP-FIELD.
03 NAME PIC X(20)BBB VALUE SPACES.
03 AGE PIC XXBBB VALUE SPACES.
03 EMP-NO PIC XXXBXXBXXXXBBB VALUE SPACES.
02 EXEMPTIONS PIC 99 VALUE ZERO.
Given the fields described above, the MOVE statement:
MOVE NUM-IN TO FIELD
gives the result:
1209R_______
A group move is done with no conversion.
The statement, MOVE NUM-JUNK TO SUB-F2, gives the result:
12/34/5_
The space to the right was supplied in order to fill the field, and no
operational sign was moved.
Assuming that the current contents of FILE-REC are in order:
NAME JASON_PENNY_________
AGE AGE
EMP-NO 585241215
LOCALE WASHINGTON_DISTRICT_OF_COLUMBIA____
and the current contents of INFO-OUT are all spaces for NAME, AGE, and
EMP-NO, and zeros for EXEMPTIONS, then the statement MOVE CORRESPONDING
FILE-REC TO INFO-OUT gives the following results in INFO-OUT,
NAME JASON_PENNY____________
AGE 39___
EMP-NO 585_24_1215___
EXEMPTIONS 00
Finally, the MOVE statement:
MOVE NUM-IN TO CARD-NUM
results in the contents of CARD-NUM being 1209R, since R is the zoned
overpunch character for 9 in a negative number.
The following example contains a de-edited MOVE statement.
Given:
01 NUM-ITEM PIC S9(5)V99.
01 EDITED-ITEM PIC $ZZZ,ZZZ.99-.
MOVE -23.00 TO EDITED-ITEM
The following is a valid de-edited MOVE:
MOVE EDITED-ITEM TO NUM-ITEM.
The results of the example above are the same as in the following
example:
MOVE -23.00 TO NUM-ITEM
MPE/iX 5.0 Documentation