Page 1 of 1

COBOL declaration

PostPosted: Fri May 17, 2019 10:51 pm
by ravi11081992
Hi,

Today I have seen a code that was written 15 years ago

A variable is declared with pic -----9 to display sqlcode

I have checked in some manuals and also with my colleagues but I couldn't find the reason what happens if a variable is declared with -----9

Please help me with this weird declaration

Thanks

Re: COBOL declaration

PostPosted: Sat May 18, 2019 12:33 am
by Robert Sample
The minus sign in a COBOL PICTURE declaration can be a floating declaration as you've shown. If the value moved to the variable is positive, the minus signs are converted to spaces until the first significant digit. If the value moved to the variable is negative, the character to the left of the first significant digit will contain the minus sign. Code:
WORKING-STORAGE SECTION.                      
 01  WS-VARS.                                  
     05  WS-NE-VAR               PIC -----9.  
 PROCEDURE DIVISION.                          
     MOVE -877                   TO  WS-NE-VAR.
     DISPLAY '-877   >' WS-NE-VAR '<'.        
     MOVE  888                   TO  WS-NE-VAR.
     DISPLAY ' 888   >' WS-NE-VAR '<'.        
     MOVE -123456                TO  WS-NE-VAR.
     DISPLAY '-123456>' WS-NE-VAR '<'.        
     MOVE  123456                TO  WS-NE-VAR.
     DISPLAY ' 123456>' WS-NE-VAR '<'.        
     STOP RUN.                                
produces results of:
-877   >  -877<
 888   >   888<
-123456>-23456<
 123456> 23456<
If you REALLY want to see an unusual PICTURE, try coding -(5)9 and compiling it.