Consider the following example:
01 EMPLOYEE-RECORD.
10 EMP-ID-CODE PIC 9(02).
10 EMP-BDAY PIC 9(08).
10 EMPLOYEE-NO PIC 9(10).
01 WS-EMP-NBR PIC 9(18).
01 WS-EMP-RECORD PIC X(20).
I don't need the EMP-ID-CODE. Just their birthday and employee number. So I
MOVE EMPLOYEE-RECORD TO WS-EMP-NBR.
Thinking that it will eliminate EMP-ID-CODE since WS-EMP-NBR is shorter than the value being moved and should cut off the value from the left since the receiving data field is defined as numeric.
If EMPLOYEE-RECORD contains
And I was expecting after the move statement to be
But instead
To sum it all up, avoid moving group data field, like the one above, in numeric data field for it will not truncate the value from the left as I have expected. Move the group data field first into elementary data field, same as the solution that I did which is also shown below, to come up with just the employee's birthday and employee number. Also, always check the output if it's what you really want the outcome to be. So below is what I did;
MOVE EMPLOYEE-RECORD TO WS-EMP-RECORD.
MOVE WS-EMP-RECORD TO WS-EMP-NBR.
Just also want to add that PIC 9(18) is the maximum allowable size for numeric data field. In excess of this will cause an error.
No comments:
Post a Comment