Sign Data Type
Sign Data Type
- Sign data type is used to declare the numeric variable with the sign to capture the negative values. i.e., sign data type always comes up with numeric data type.
- Sign data type uses the character "S" to declare the variable with a sign.
- Sign value doesn't require any additional byte to store, and it always overpunches on the last digit of the value if the SIGN clause is not coded.
The below table represents how the numbers appear if the SIGN is 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 is coded, the sign requires an additional byte to store the sign value.
Examples -
Scenario - Testing for Positive Value.
WORKING-STORAGE SECTION.
01 WS-SALARY PIC S9(5) VALUE +10000.
...
PROCEDURE DIVISION.
DISPLAY "WS-SALARY: " WS-SALARY.
Output -
WS-SALARY: 1000{
In the above example, + sign overpunches on 0. So the symbol { is displayed.
Sign Clause -
The SIGN clause sets in the declaration when the sign needs to be stored in an additional byte.
Syntax -
[SIGN IS
{LEADING|TRAILING} SEPARATE CHARACTER]
Note! All statements coded in [ ] are optional.
Parameters -
- LEADING SEPARATE - specifies that the sign is stored as a separate character before the value.
- TRAILING SEPARATE - specifies that the sign is stored as a separate character, after the value.
Note! If SEPARATE isn't specified, the sign is punched on tops of the leftmost or rightmost byte, depending on LEADING or TRAILING keyword.
Examples -
Scenario1 - Displaying SIGN leading separate.
WORKING-STORAGE SECTION.
01 WS-SIGN-LS-P PIC S9(03) VALUE +256
SIGN IS LEADING SEPARATE CHARACTER.
...
PROCEDURE DIVISION.
DISPLAY "Sign +ve leading separate: " WS-SIGN-LS-P.
Output -
Sign +ve leading separate: +256
Scenario2 - Displaying SIGN trailing separate.
WORKING-STORAGE SECTION.
01 WS-SIGN-TS-N PIC S9(03) VALUE -256
SIGN IS TRAILING SEPARATE CHARACTER.
...
PROCEDURE DIVISION.
DISPLAY "Sign -ve trailing separate: " WS-SIGN-TS-N.
Output -
Sign -ve trailing separate: 256-