MOVE in COBOL, no abend.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
ramesh kulkarni
New Member
Posts: 2
Joined: Thu Sep 25, 2014 12:10 pm

MOVE in COBOL, no abend.

Post 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
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: MOVE in COBOL, no abend.

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: MOVE in COBOL, no abend.

Post 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.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”