MainframeMaster

COBOL Tutorial

COBOL SIGN Clause - Quick Reference

Progress0 of 0 lessons

Overview

The SIGN clause is used to control sign handling in numeric data items in COBOL. It specifies how signs are positioned and represented in numeric data, ensuring consistent sign handling across different systems and applications.

Purpose and Usage

  • Sign position control - Control where signs are positioned
  • Sign representation - Control how signs are represented
  • Data consistency - Ensure consistent sign handling
  • System compatibility - Ensure compatibility between systems
  • Financial accuracy - Ensure accurate financial calculations

Syntax

The SIGN clause is used in the DATA DIVISION for numeric data definition.

Basic Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
* Basic SIGN syntax 01 data-name PIC numeric-picture SIGN IS sign-position. * Complete example IDENTIFICATION DIVISION. PROGRAM-ID. SIGN-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 SIGNED-AMOUNT-1 PIC S9(7)V99 SIGN IS LEADING. 01 SIGNED-AMOUNT-2 PIC S9(7)V99 SIGN IS TRAILING. 01 SIGNED-AMOUNT-3 PIC S9(7)V99 SIGN IS LEADING SEPARATE. 01 SIGNED-AMOUNT-4 PIC S9(7)V99 SIGN IS TRAILING SEPARATE. PROCEDURE DIVISION. MAIN-LOGIC. MOVE 1234.56 TO SIGNED-AMOUNT-1 MOVE -567.89 TO SIGNED-AMOUNT-2 DISPLAY "Amount 1: " SIGNED-AMOUNT-1 DISPLAY "Amount 2: " SIGNED-AMOUNT-2 STOP RUN.

SIGN controls sign position and representation.

Practical Examples

Examples of using the SIGN clause in different scenarios.

Leading Sign

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
* Leading sign position 01 LEADING-SIGN-AMOUNT PIC S9(7)V99 SIGN IS LEADING. 01 LEADING-SIGN-INTEGER PIC S9(5) SIGN IS LEADING. PROCEDURE DIVISION. PROCESS-LEADING-SIGN. MOVE 1234.56 TO LEADING-SIGN-AMOUNT MOVE -567 TO LEADING-SIGN-INTEGER DISPLAY "Leading sign amount: " LEADING-SIGN-AMOUNT DISPLAY "Leading sign integer: " LEADING-SIGN-INTEGER * Sign appears at the beginning of the number * Example: +1234.56, -00567

SIGN IS LEADING places sign at the beginning.

Trailing Sign

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
* Trailing sign position 01 TRAILING-SIGN-AMOUNT PIC S9(7)V99 SIGN IS TRAILING. 01 TRAILING-SIGN-INTEGER PIC S9(5) SIGN IS TRAILING. PROCEDURE DIVISION. PROCESS-TRAILING-SIGN. MOVE 1234.56 TO TRAILING-SIGN-AMOUNT MOVE -567 TO TRAILING-SIGN-INTEGER DISPLAY "Trailing sign amount: " TRAILING-SIGN-AMOUNT DISPLAY "Trailing sign integer: " TRAILING-SIGN-INTEGER * Sign appears at the end of the number * Example: 1234.56+, 00567-

SIGN IS TRAILING places sign at the end.

Separate Sign

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
* Separate sign representation 01 SEPARATE-LEADING PIC S9(7)V99 SIGN IS LEADING SEPARATE. 01 SEPARATE-TRAILING PIC S9(7)V99 SIGN IS TRAILING SEPARATE. PROCEDURE DIVISION. PROCESS-SEPARATE-SIGN. MOVE 1234.56 TO SEPARATE-LEADING MOVE -567.89 TO SEPARATE-TRAILING DISPLAY "Separate leading: " SEPARATE-LEADING DISPLAY "Separate trailing: " SEPARATE-TRAILING * Sign is in a separate character position * Example: +1234.56, 567.89-

SIGN IS SEPARATE uses separate character for sign.

Best Practices

Understanding best practices ensures effective use of the SIGN clause.

Best Practices

  • Choose appropriate sign position - Select sign position based on requirements
  • Consider system compatibility - Ensure compatibility with other systems
  • Use consistent sign handling - Maintain consistency across the application
  • Test sign handling - Test with positive and negative values
  • Document sign conventions - Document sign handling conventions

Test Your Knowledge

1. What is the primary purpose of the SIGN clause in COBOL?

  • To sign documents
  • To control sign handling in numeric data
  • To sign programs
  • To sign files

2. In which COBOL division is the SIGN clause typically used?

  • IDENTIFICATION DIVISION
  • ENVIRONMENT DIVISION
  • DATA DIVISION
  • PROCEDURE DIVISION

3. What does the SIGN clause control in numeric data?

  • Data validation
  • Sign position and representation
  • Data type
  • Data size

4. Can SIGN be used with all numeric data types?

  • Yes, with all numeric types
  • No, only with COMP data
  • No, only with DISPLAY data
  • Only with specific data types

5. What is the relationship between SIGN and PICTURE clauses?

  • They are the same thing
  • SIGN controls sign handling, PICTURE controls format
  • SIGN is obsolete, PICTURE is modern
  • They cannot be used together

Frequently Asked Questions