TRAILING-SIGN is set with the SIGN IS TRAILING clause to place the sign at the end of a numeric item. Use the S symbol in PICTURE to allow a sign.
Define signed numeric items with PICTURE and specify sign position.
12345678910* Signed item with trailing sign DATA DIVISION. WORKING-STORAGE SECTION. 01 AMOUNT PIC S9(6)V99 SIGN IS TRAILING. 01 AMOUNT-DISP PIC $$,$$9.99 SIGN IS TRAILING. PROCEDURE DIVISION. MOVE -1234.56 TO AMOUNT MOVE AMOUNT TO AMOUNT-DISP DISPLAY "Amount: " AMOUNT-DISP STOP RUN.
Negative values appear with a minus at the rightmost position of the item.
123456* Compare leading and trailing sign 01 LEAD-AMT PIC S9(5)V99 SIGN IS LEADING. 01 TRAIL-AMT PIC S9(5)V99 SIGN IS TRAILING. MOVE -123.45 TO LEAD-AMT TRAIL-AMT DISPLAY "Leading: " LEAD-AMT DISPLAY "Trailing: " TRAIL-AMT
Aspect | Description | Example |
---|---|---|
Signed | Use S in PICTURE | PIC S9(6)V99 |
Position | SIGN IS TRAILING | PIC S9(6) SIGN IS TRAILING |
Edited | Use $, comma, Z | PIC $$,$$9.99 SIGN IS TRAILING |
1. What does SIGN IS TRAILING specify?
2. Which symbol enables signed numeric data in a PICTURE clause?
3. Which clause explicitly sets sign position?
4. How are negative values shown for a TRAILING sign?
5. Which best practice helps avoid ambiguity when printing signs?