2021-10-27

Array processing and Table handling with packed decimal in COBOL

I was practicing array processing and table handling and there's this output of my program that I don't understand.

01  TABLE-VALUES.                      
    05 TABLE-ELEMENTS OCCURS 2 TIMES. 
       10 A-A PIC X(5).                
       10 A-B PIC S9(5)V99 COMP-3.     
01  WS-STRING PIC X(10).               
01  S PIC 99.                          
01  WS-COUNT PIC 99.                   
...
PROCEDURE DIVISION.                                       
0000-MAIN.                                                
    DISPLAY 'HELLO WORLD'                                 
    MOVE '1234567890ABCDEFGHI' TO TABLE-VALUES            
    DISPLAY 'TABLE VALUES ' TABLE-VALUES                  
    MOVE 0 TO WS-COUNT                                    
    INSPECT TABLE-VALUES TALLYING WS-COUNT FOR CHARACTERS 
    DISPLAY WS-COUNT                                      
    PERFORM 1000-PARA VARYING S FROM 1 BY 1 UNTIL S > 2  
    STOP RUN.                                             
1000-PARA.                                                
    MOVE 'A-A(&&) = ' TO WS-STRING                        
    INSPECT WS-STRING REPLACING FIRST '&&' BY S           
    DISPLAY WS-STRING A-A(S)  
    MOVE 'A-B(&&) = ' TO WS-STRING              
    INSPECT WS-STRING REPLACING FIRST '&&' BY S 
    DISPLAY WS-STRING A-B(S).                   

The output turned out to be:

HELLO WORLD                                                                     
TABLE VALUES 1234567890ABCDEFGHI                                                
18                                                                              
A-A(01) = 12345                                                                 
A-B(01) =  6 7 8                                                                
A-A(02) = 0ABCD                                                                 
A-B(02) =  5 6 7 

I don't understand how A-B(1) and A-B(2) turned out like that. Why are there spaces in between? Where did digit 9 go to?



from Recent Questions - Stack Overflow https://ift.tt/3bgKD1j
https://ift.tt/eA8V8J

No comments:

Post a Comment