Sunday, July 6, 2008

MOVE Command

MOVE Source$#il TO Destination$#i ...

As we can see from the syntax metalanguage above, the MOVE copies data from the source identifier or literal to one or more destination identifiers.

Although this sounds simple, the actual operation of the MOVE is somewhat more complicated and is governed by a number of rules.

MOVE rules
In most other programming languages, data is assigned from the source item on the right to the destination item on the left (e.g. Qty = 10;) but in COBOL the MOVE assigns data from left to right. The source item is on the left of the word TO and the receiving item(s) is on the right.

The source and destination identifiers can be group or elementary data-items.

When data is moved into an item, the contents of the item are completely replaced.

If the number of characters in the source data-item is less than the number in the destination item, the rest of the destination item is filled with zeros or spaces.

If the source data-item is larger than the destination item, the characters that cannot fit into the destination item will be lost. This is known as truncation.

When the destination item is alphanumeric or alphabetic (PIC X or A), data is copied into the destination area from left to right with space filling or truncation on the right.

When the destination item is numeric, or edited numeric, data is aligned along the decimal point with zero filling or truncation as necessary.

When the decimal point is not explicitly specified in either the source or destination items, the item is treated as if it had an assumed decimal point immediately after its rightmost character.

MOVE examples

MOVE num1 TO num2.
MOVE 1 TO EOFSW.
MOVE 0 TO a b c.

No comments: