MOVE is COBOL reserved word. The Simple syntax for MOVE is:
MOVE {identifier-1 | literal-1} TO identifier-2 ..
Subscribe to Get blog posts to your email box.
Top Benefits of COBOL ‘MOVE’ Reserved Word
- We can move a smaller field to a bigger field
- We cannot move a bigger field to a smaller field. If so, the value will be truncated.
#1: How to Move Alphanumeric Value
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]
#2: How to Move Numeric Value
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 ]
#3: How to Move Decimal Value
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.
Related Posts