Spaces To assumed decimal variable.



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Spaces To assumed decimal variable.

Postby Shanthi_Palani » Mon Oct 10, 2016 7:37 pm

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
You do not have the required permissions to view the files attached to this post.
Shanthi_Palani
 
Posts: 10
Joined: Mon Oct 10, 2016 3:08 pm
Has thanked: 6 times
Been thanked: 0 time

Re: Spaces To assumed decimal variable.

Postby Robert Sample » Mon Oct 10, 2016 7:48 pm

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.

These users thanked the author Robert Sample for the post:
Shanthi_Palani (Tue Oct 11, 2016 6:39 pm)
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Spaces To assumed decimal variable.

Postby Terry Heinze » Tue Nov 01, 2016 12:40 am

Shanthi_Palani,
Why would you assign a numeric PICTURE an initial value of SPACES?
.... Terry
Terry Heinze
 
Posts: 239
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 12 times
Been thanked: 11 times

Re: Spaces To assumed decimal variable.

Postby enrico-sorichetti » Tue Nov 01, 2016 11:50 am

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 !? ;)
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: Spaces To assumed decimal variable.

Postby BillyBoyo » Tue Nov 01, 2016 4:36 pm

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...
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post