MainframeMaster

COBOL Tutorial

COBOL TRAILING-SIGN - Quick Reference

Progress0 of 0 lessons

Overview

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.

Key Elements

  • Signed data - PICTURE contains S to allow a sign
  • Position - SIGN IS LEADING or SIGN IS TRAILING
  • Edited output - Combine with Z, $, comma for printable forms
  • Defaults - Be explicit to avoid platform differences

Syntax and Usage

Define signed numeric items with PICTURE and specify sign position.

Basic Signed Item

cobol
1
2
3
4
5
6
7
8
9
10
* 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.

Leading vs Trailing Sign

cobol
1
2
3
4
5
6
* 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

Best Practices

  • Be explicit - Always specify SIGN position for portability
  • Test formatting - Validate printed and displayed forms
  • Use edited pictures - For user-facing values
  • Handle zeros - Use BLANK WHEN ZERO when needed

TRAILING-SIGN Quick Reference

AspectDescriptionExample
SignedUse S in PICTUREPIC S9(6)V99
PositionSIGN IS TRAILINGPIC S9(6) SIGN IS TRAILING
EditedUse $, comma, ZPIC $$,$$9.99 SIGN IS TRAILING

Test Your Knowledge

1. What does SIGN IS TRAILING specify?

  • That the sign is stored separately from the number
  • That the sign appears at the rightmost position of the numeric item
  • That the number is unsigned
  • That the sign appears in leading position only

2. Which symbol enables signed numeric data in a PICTURE clause?

  • S
  • V
  • Z
  • 9

3. Which clause explicitly sets sign position?

  • JUSTIFIED
  • SIGN IS LEADING/TRAILING
  • USAGE COMP
  • BLANK WHEN ZERO

4. How are negative values shown for a TRAILING sign?

  • With parentheses around the number
  • With a minus symbol at the rightmost character of the item
  • With a minus symbol at the leftmost character only
  • They cannot be represented

5. Which best practice helps avoid ambiguity when printing signs?

  • Omit the S in PICTURE
  • Always rely on compiler defaults
  • Specify SIGN IS LEADING/TRAILING and test output formatting
  • Avoid signs entirely

Frequently Asked Questions