SIGN Clause
SIGN Clause
- SIGN clause is used with SIGN data type to store the sign in an additional byte.
- It specifies the position and representation of the sign (positive or negative) for numeric data items.
Syntax -
[SIGN IS
{LEADING|TRAILING} [SEPARATE CHARACTER]]
Note! All statements coded in [ ] are optional.
Parameters -
- LEADING - This specifies that the sign will be at the beginning of the data.
- TRAILING - This denotes that the sign will be at the end of the data.
- SEPARATE - This specifies that the sign is stored as a separate character, either before (for LEADING) or after (for TRAILING) the numeric digits. If SEPARATE isn't specified, the sign will be stored in the zone of the leftmost or rightmost byte, depending on whether LEADING or TRAILING is used.
Note! SIGN occupies an extra 1 byte of storage space. If Nothing of the above parameters is provided with the SIGN clause, it is to SIGN IS TRAILING by default.
Practical Example -
Scenario - Below example describes about the sign data type declaration and usage in COBOL programming.
Code -
----+----1----+----2----+----3----+----4----+----5----+
...
WORKING-STORAGE SECTION.
01 WS-VARS.
05 WS-SIGN-NO-SEP-P PIC S9(03) VALUE +256.
05 WS-SIGN-LS-P PIC S9(03) VALUE +256
SIGN IS LEADING SEPARATE CHARACTER.
05 WS-SIGN-TS-P PIC S9(03) VALUE +256
SIGN IS TRAILING SEPARATE CHARACTER.
05 WS-SIGN-NO-SEP-N PIC S9(03) VALUE -256.
05 WS-SIGN-LS-N PIC S9(03) VALUE -256
SIGN IS LEADING SEPARATE CHARACTER.
05 WS-SIGN-TS-N PIC S9(03) VALUE -256
SIGN IS TRAILING SEPARATE CHARACTER.
...
PROCEDURE DIVISION.
DISPLAY "Sign +ve with no separate: " WS-SIGN-NO-SEP-P.
DISPLAY "Sign +ve leading separate: " WS-SIGN-LS-P.
DISPLAY "Sign +ve trailing separate: " WS-SIGN-TS-P.
DISPLAY " ".
DISPLAY "Sign -ve with no separate: " WS-SIGN-NO-SEP-N.
DISPLAY "Sign -ve leading separate: " WS-SIGN-LS-N.
DISPLAY "Sign -ve trailing separate: " WS-SIGN-TS-N.
...
Output -
Sign +ve with no separate: 25F Sign +ve leading separate: +256 Sign +ve trailing separate: 256+ Sign -ve with no separate: 25O Sign -ve leading separate: -256 Sign -ve trailing separate: 256-