Summary -

In this topic, we described about the Sign Data Type with detailed example.

Sign data type allows to declare the numeric data item with sign to capture the negative values. Sign can specify for numeric values. i.e. sign data types can come up with numeric data type.

Sign data type uses character "S" to declare the data item with sign. Sign value doesn’t require any additional storage to store in the memory and it always over punching on the last digit if SIGN clause not specified.

Below table represents the how the numbers represent if the SIGN over punched on it -

Numbers Number +ve sign Number -ve sign Number No sign
0 { } 0
1 A J 1
2 B K 2
3 C L 3
4 D M 4
5 E N 5
6 F O 6
7 G P 7
8 H Q 8
9 I R 9

If SIGN Clause specified, the sign requires additional byte to store the sign value.


Practical Example -

Scenario - Below example describes about the sign data type declaration and usage in COBOL programming.

Code -

Sign Data Type Program Code
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
****** ***************************** Top of Data ******************************
000001        IDENTIFICATION DIVISION.                                         
000002        PROGRAM-ID. SIGNDT.                                              
000003        AUTHOR. MTH.                                                     
000004                                                                         
000005        DATA DIVISION.                                                   
000006        WORKING-STORAGE SECTION.                                         
000007        01 WS-VARS.                                                      
000008           05 WS-SIGN-NO-SEP-P       PIC S9(03) VALUE +256.              
000009           05 WS-SIGN-LS-P           PIC S9(03) VALUE +256               
000010                 SIGN IS LEADING SEPARATE CHARACTER.                     
000011           05 WS-SIGN-TS-P           PIC S9(03) VALUE +256               
000012                 SIGN IS TRAILING SEPARATE CHARACTER.                    
000013           05 WS-SIGN-NO-SEP-N       PIC S9(03) VALUE -256.              
000014           05 WS-SIGN-LS-N           PIC S9(03) VALUE -256               
000015                 SIGN IS LEADING SEPARATE CHARACTER.                     
000016           05 WS-SIGN-TS-N           PIC S9(03) VALUE -256               
000017                 SIGN IS TRAILING SEPARATE CHARACTER.                    
000018                                                                         
000019        PROCEDURE DIVISION.                                              
000020                                                                         
000021            DISPLAY "SIGN +VE WITH NO SEPARATE :  " WS-SIGN-NO-SEP-P.    
000022            DISPLAY "SIGN +VE LEADING SEPARATE :  " WS-SIGN-LS-P.        
000023            DISPLAY "SIGN +VE TRAILING SEPARATE : " WS-SIGN-TS-P.        
000024            DISPLAY " ".                                                 
000025                                                                         
000026            DISPLAY "SIGN -VE WITH NO SEPARATE :  " WS-SIGN-NO-SEP-N.    
000027            DISPLAY "SIGN -VE LEADING SEPARATE :  " WS-SIGN-LS-N.        
000028            DISPLAY "SIGN -VE TRAILING SEPARATE : " WS-SIGN-TS-N.        
000029                                                                         
000030            STOP RUN.                                                    
****** **************************** Bottom of Data ****************************

Output -

Sign Data Type Program Output