MOVE
The COBOL statement that copies a value into a field, converting it to fit the receiving field's format.
Also written MOVE statement, MOVE CORRESPONDING, MOVE TO
MOVE copies a value into a field: MOVE WS-AMOUNT TO OUT-AMOUNT. It is the most common statement in COBOL. The value is changed to fit the receiving field, and the rules for how it fits are worth knowing well.
For text fields, the value is placed from the left. If the receiving field is longer, the rest is filled with spaces. If it is shorter, characters are cut off on the right.
For number fields, the value is lined up on the decimal point. Extra places are filled with zeros. If the receiving field has fewer digits before the decimal point, the leftmost digits are cut off, with no warning. Moving 12345 into a field with PIC 999 gives 345. This is a well-known source of wrong totals, so check that receiving fields are big enough.
Moving a group item, one made of several fields, is always treated as a text move, with no conversion. That can leave numeric fields holding characters that are not valid numbers, which later causes an S0C7 abend. MOVE CORRESPONDING moves the fields that have the same names in two groups.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- PICTURE clauseThe COBOL declaration that says what kind of data a field holds and how long it is, written as PIC.
- WORKING-STORAGEThe section of a COBOL program that declares its internal variables: counters, totals, flags and work areas.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.
- Packed decimalA compact way of storing numbers, two digits per byte, used heavily for amounts in business records.
- PROCEDURE DIVISIONThe part of a COBOL program that contains the actual logic, the statements that run.