Page 1 of 1

Spaces To assumed decimal variable.

PostPosted: Mon Oct 10, 2016 7:37 pm
by Shanthi_Palani
Hello Experts,

I would need your help in understanding a behaviour in a code.One of an application processes like below (PFA the snapshot of the process and the sysout details.)
Added the process below as well. Could anyone kindly share info on why am i getting the last zero when the WS-VAR2 is moved to WS-VAR3? I can understand the reason for the first three zeroes but unable to get any idea on the last Zero.


WORKING-STORAGE SECTION.
   01 WS-VAR1              PIC 9(13).9(5) VALUE SPACES.
   01 WS-VAR2              PIC 9(16)V9(2).              
   01 WS-VAR3              PIC 9(16)V9(2).
             
PROCEDURE DIVISION.
                           
1000-DISPLAY-PARA.
                             
    DISPLAY 'INITIAL DISPLAY OF THE VARIABLES:'        
    DISPLAY 'WS-VAR1      :' WS-VAR1                    
    DISPLAY 'WS-VAR2      :' WS-VAR2                    
    DISPLAY 'WS-VAR3      :' WS-VAR3    
               
    DISPLAY 'AFTER MOVING WS-VAR1 TO WS-VAR2:'          
    MOVE WS-VAR1      TO WS-VAR2                        
    DISPLAY 'WS-VAR1      :' WS-VAR1                    
    DISPLAY 'WS-VAR2      :' WS-VAR2                    
    DISPLAY 'WS-VAR3      :' WS-VAR3  
                 
    DISPLAY 'AFTER MOVING WS-VAR2 TO WS-VAR3:'          
    MOVE WS-VAR2      TO WS-VAR3                        
    DISPLAY 'WS-VAR2      :' WS-VAR2                    
    DISPLAY 'WS-VAR3      :' WS-VAR3  
    GOBACK.
 
 
Sysout Details:

INITIAL DISPLAY OF THE VARIABLES:          

WS-VAR1      :                              
WS-VAR2      :                              
WS-VAR3      :                              

AFTER MOVING WS-VAR1 TO WS-VAR2:    
       
WS-VAR1      :                              
WS-VAR2      :000                          
WS-VAR3      :                              

AFTER MOVING WS-VAR2 TO WS-VAR3:    
       
WS-VAR2      :000                          
WS-VAR3      :000            0        

(This fourth zero is in the last position of the decimal in  9(16)v9(2),Please refer attachment , it clearly states the details)                
             
Thanks a ton in advance!

Coded

Re: Spaces To assumed decimal variable.

PostPosted: Mon Oct 10, 2016 7:48 pm
by Robert Sample
You get the last zero because COBOL is making sure the value is unsigned by changing the X'40' to X'F0' (unsigned) in the last byte of the value. If you look at the pseudo-assembler generated by COBOL, you'll see this.

Attachments are discouraged on this forum due to viruses and many companies don't allow them to be downloaded. Use the Code button to place what you wanted to attach in your post.

Re: Spaces To assumed decimal variable.

PostPosted: Tue Nov 01, 2016 12:40 am
by Terry Heinze
Shanthi_Palani,
Why would you assign a numeric PICTURE an initial value of SPACES?

Re: Spaces To assumed decimal variable.

PostPosted: Tue Nov 01, 2016 11:50 am
by enrico-sorichetti
Why would you assign a numeric PICTURE an initial value of SPACES?


because that' s the requirement/because it is in the specifications,
what else !? ;)

Re: Spaces To assumed decimal variable.

PostPosted: Tue Nov 01, 2016 4:36 pm
by BillyBoyo
It is a numeric-edited field, and a VALUE of SPACE is entirely valid. I'd not do it myself, but some people use it for print output where the value optionally appears (and then set the whole print line to space for the second record... or do the once-only line different from the normal way...).

However, with Enterprise COBOL that code would not produce that output. So you are not using Enterprise COBOL or you have some other code affecting the values which you have not shown.

So, which compiler are you using, and which operating system?

Don't you feel that calling things "VAR1" and the like are an absolutely dumb way writing programs (in any language)? I hope it is just for the demonstration...