Saturday, June 8, 2024

Data overlay caused by COBOL reference modification

If the length of the target field in a MOVE statement is greater than or equal to the length of the source field, and the source field has reference modification, and the length of the source field is provided through a variable, and the length of the reference modification is greater than the length of the target field, it will result in data overlay in the subsequent fields of the target field.

By supplying a value of 15 in the SYSIN card for the length field in the program below, we can observe the occurrence of data overlay. 

        IDENTIFICATION DIVISION.               
        PROGRAM-ID. HELLO.                     
        DATA DIVISION.                         
        WORKING-STORAGE SECTION.               
        01 GRP-A.                              
           05 WS-X   PIC X(05) VALUE '12345'.  
           05 FILLER PIC X(05) VALUE 'ABCDE'.  
           05 FILLER PIC X(05) VALUE 'FGHIJ'.  
        01 GRP-B.                              
           05 WS-A    PIC X(05).               
           05 WS-B    PIC X(10).               
        01 WS-LEN     PIC 9(02).               
        PROCEDURE DIVISION.                    
           MOVE SPACES TO WS-B                 
           DISPLAY 'WS-B: ' WS-B.              
           ACCEPT WS-LEN 
           MOVE WS-X (1:WS-LEN) TO WS-A        
           DISPLAY 'WS-B: ' WS-B. 
           STOP RUN.    

Output of the above program

 WS-B:               
 WS-B: ABCDEFGHIJ    

This issue is observed in IBM Enterprise COBOL for z/OS  6.3.0. 

If the length of the target field is less than the length of the source field, then this iissue wont occur


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.