Friday, November 18, 2011

MOVE Statement


It is used to transfer data between internal storage areas defined in either file section or working storage section.

Syntax:
MOVE identifier1/literal1/figurative-constant TO identifier2 (identifier3)
Multiple move statements can be separated using comma, semicolons, blanks or the keyword THEN.

Numeric move rules:
A numeric or numeric-edited item receives data in such a way that the decimal point is aligned first and then filling of the receiving field takes place.
Unfilled positions are filled with zero. Zero suppression or insertion of editing symbols takes places according to the rules of editing pictures.
If the receiving field width is smaller than sending field then excess digits, to the left and/or to the right of the decimal point are truncated.

Alphanumeric Move Rules:
Alphabetic, alphanumeric or alphanumeric-edited data field receives the data from left to right. Any unfilled field of the receiving filed is filled with spaces.
When the length of receiving field is shorter than that of sending field, then receiving field accepts characters from left to right until it is filled. The unaccomodated characters on the right of the sending field are truncated.
When an alphanumeric field is moved to a numeric or numeric-edited field, the item is moved as if it were in an unsigned numeric integer mode.
          CORRESPONDING can be used to transfer data between items of the same names belonging to different group-items by specifying the names of group-items to which they belong.
          MOVE CORRESPONDING group-1 TO group-2

 


Group Move rule

When MOVE statement is used to move information at group level, the movement of data takes place as if both sending and receiving fields are specified as alphanumeric items. This is regardless of the description of the elementary items constituting the group item.

Samples for understanding MOVE statement (MOVE A TO B)


Picture of A
Value of A
Picture of B
Value of B after Move
PIC 99V99
12.35
PIC 999V99
012.35
PIC 99V99
12.35
PIC 9999V9999
0012.3500
PIC 99V999
12.345
PIC 9V99
2.34
PIC9(05)V9(03)
54321.543
PIC 9(03)V9(03)
321.543
PIC 9(04)V9(02)
23.24
PIC ZZZ99.9
23.2
PIC 99V99
00.34
PIC $$$.99
$.34
PIC X(04)
MUSA
XBXBXB
M U S

ARITHMETIC VERBS

All the possible arithmetic operations in COBOL using ADD, SUBTRACT, MULTIPLY and DIVIDE are given below:

Arithmetic Operation
A
B
C
D
ADD A TO B
A
A+B


ADD A B C TO D
A
B
C
A+B+C+D
ADD A B C GIVING D
A
B
C
A+B+C
ADD A TO B C
A
A+B
A+C

SUBTRACT A FROM B
A
B-A


SUBTRACT A B FROM C
A
B
C-(A+B)

SUBTRACT A B FROM C GIVING D
A
B
C
C-(A+B)
MULTIPLY A BY B
A
A*B


MULTIPLY A BY B GIVING C
A
B
A*B

DIVIDE A INTO B
A
B/A


DIVIDE A INTO B GIVING C
A
B
B/A

DIVIDE A BY B GIVING C
A
B
A/B

DIVIDE A INTO B GIVING C REMAINDER D
A
B
Integer (B/A)
Integer remainder

GIVING is used in the following cases:
          1.To retain the values of operands participating in the operation.
          2.The resultant value of operation exceeds any of the operand size

No comments:

Post a Comment