COBOL declaration

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

COBOL declaration

Postby ravi11081992 » Fri May 17, 2019 10:51 pm


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

Posts: 19
Joined: Mon Apr 30, 2018 5:47 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL declaration

Postby Robert Sample » Sat May 18, 2019 12:33 am

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<
If you REALLY want to see an unusual PICTURE, try coding -(5)9 and compiling it.
Robert Sample
Global moderator
Posts: 3706
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 277 times

Return to IBM Cobol


  • Related topics
    Last post