Page 1 of 1

MOVE in COBOL, no abend.

Posted: Mon May 11, 2015 4:54 pm
by ramesh kulkarni
Hi,

I'm using IBM Enterprise COBOL and working with the below code for testing:.I expected a compilation error or an abend but nothing of that sort happened. Can someone tell why this happens?

Code: Select all

IDENTIFICATION DIVISION.        
PROGRAM-ID. TESTPGM.            
ENVIRONMENT DIVISION.          
DATA DIVISION.                  
WORKING-STORAGE SECTION.        
01 WS-VAR-A  PIC  X(05).        
01 WS-VAR-B  PIC S9(05) COMP.  
PROCEDURE DIVISION.            
MAIN-PARA.                      
    MOVE 'ABCDE' TO WS-VAR-A.  
    DISPLAY WS-VAR-A.          
    MOVE WS-VAR-A TO WS-VAR-B. 
    DISPLAY WS-VAR-B.          
GOBACK.


The result is:

WS-VAR-A - ABCDE
WS-VAR-B - 12345

Re: MOVE in COBOL, no abend.

Posted: Mon May 11, 2015 5:58 pm
by Robert Sample
I'm not sure why you would expect a compile error since the COBOL Language Reference manual explicitly states that your MOVE is valid. Furthermore, you would not get any ABEND from the code, either. If you were expecting a S0C7 ABEND, you won't get one from what you did. Converting characters from A to Z into numeric data will not get a S0C7 since the removing the zones leaves valid numbers. If you don't understand why, you need to read the manual on internal formats for zoned decimal, packed decimal, and alphanumeric variables.

Re: MOVE in COBOL, no abend.

Posted: Mon May 11, 2015 6:40 pm
by William Collins
A PIC X field of any length is "alphanumeric". The is no problem with the language definition in a MOVE of an alphanumeric field to a numeric (PIC 9) field.

If you want a compile-error, define your field as PIC A(5). From my experience, it is very rare that you will see PIC A fields.

When an alphanumeric field is MOVEd to a numeric field, the data will be "packed", which means all the zone bits (the left-half of all bytes, if any, except the rightmost) will be ignored. The right-most byte instead of a zone, has four bits representing the sign, which must be, in hex, A through F. All the remaining bits (the right-most four bits in each byte) must be 0-9.

To get a S0C7 Data Exception, you need to disobey the rule about the sign or the numbers or both. No value in the zone bits will ever contribute to a S0C7.

Instead of "ABCDE" try "....." and "ABCD." and "....E" for instance.