30+High+Paying+JobsMOVE is such a crucial COBOL reserved word. Simple syntax for MOVE is:

MOVE {identifier-1 | literal-1} TO identifier-2 ..

  • We can move smaller field to bigger field
  • We cannot move bigger field to smaller field. If so, value will be truncated.

Alphanumeric Move:

01 var-1 pic x(10) value ‘RAMANA’

01 var-2 pix x(10).

MOVE var-1 to var-2.

Result in var-2=> ‘RAMANA’ [Remaining bytes padded with spaces in right side]

Numeric Move:

Example-1

01 var-1 pic x(10) value ‘1234’

01 var-2 pix x(10).

MOVE var-1 to var-2.

Result in var-2=> ‘1234’ [Remaining bytes padded with spaces in right side]

Example-2

01 var-1 pic 9(10) value 1234

01 var-2 pix 9(10).

MOVE var-1 to var-2.

Result in var-2=> ‘0000001234’ [Left side padded with zeros ]

Decimal Move

01 var-1  pic 9(4)v9(2) value 1234.56

01 var-2  pix 9(4)v9(2).

MOVE var-1 to var-2.

Result in var-2 =>123456 [Because it is assumed decimal value]

How decimal move happens:

1234.56

Before point => Right to left         1<<2<<3<<4

After point ==>Left to right         5>>6

Notes on MOVE statement

  • Use Value clauses to initialize fields in working storage whenever that’s possible.
  • Use Move or Initialize statements to re-initialize fields whenever that’s necessary.
  • Don’t use Initialize statements to initialize large tables or record descriptions that don’t need to be initialized.
Advertisements