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.

Sign Clause -

The SIGN clause specifies the position and representation mode of the sign. The SIGN clause codes in declaration when the sign required to store the sign value in additional byte.

Syntax -

Sign Clause Syntax

  • LEADING Specifies that the sign is at the beginning of the data item.
  • TRAILING Specifies that the sign is at the end of the data item.
  • SEPARATE Specifies that the sign is not over punched on last/first char of the data item and sign separately occupies the first or last character of the data item.

The SIGN clause can be specified only for the following items -

  • An elementary numeric data item of usage DISPLAY.
  • A group item that contains at least one such elementary entry as a subordinate item.

When the SIGN clause is specified without the SEPARATE phrase, USAGE DISPLAY must be specified explicitly or implicitly. When SIGN IS SEPARATE is specified, USAGE DISPLAY can be specified.

If the SEPARATE CHARACTER phrase is not specified, then -

  • The sign is presumed to be associated with the LEADING or TRAILING digit position.
  • The character 'S' in the PICTURE character string is not counted in determining the size of the item.

If the SEPARATE CHARACTER phrase is specified, then -

  • The operational sign is presumed to be the LEADING or TRAILING character position. This character position is not a digit position.
  • The character 'S' in the PICTURE character string is counted in determining the size of the data item.
    + is the character used for the positive operational sign.
    - is the character used for the negative operational sign.

The SEPARATE CHARACTER phrase cannot be specified for a date field.

Note! SIGN(S) occupies extra 1 byte of storage space.If Nothing of the above parameters provided with SIGN clause, by default it is to SIGN IS TRAILING.

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