MainframeMaster
MainframeMaster

COBOL Tutorial

Progress0 of 0 lessons

COBOL SPECIAL-NAMES

The SPECIAL-NAMES paragraph in the ENVIRONMENT DIVISION allows you to customize system-specific features and define symbolic names for various COBOL elements. It provides a standardized way to configure currency symbols, decimal point notation, alphabet names for collating sequences, class names for data validation, switch status, and other environment-specific settings. Understanding SPECIAL-NAMES is essential for creating portable, configurable COBOL programs that can adapt to different environments and requirements.

What is SPECIAL-NAMES?

SPECIAL-NAMES is an optional paragraph in the CONFIGURATION SECTION of the ENVIRONMENT DIVISION. It allows you to:

  • Define currency symbols: Specify which character represents currency in PICTURE clauses
  • Configure decimal point: Swap period and comma roles for international formats
  • Define alphabet names: Create custom collating sequences for sorting
  • Define class names: Specify character sets for validation
  • Set switch status: Define symbolic names for hardware/software switches
  • Configure other system features: Various environment-specific settings

SPECIAL-NAMES provides portability and flexibility, allowing programs to adapt to different environments without code changes.

SPECIAL-NAMES Syntax

The SPECIAL-NAMES paragraph follows this general structure:

cobol
1
2
3
4
5
6
7
8
9
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. [currency-definition] [decimal-point-definition] [alphabet-definition] [class-definition] [switch-definition] [other-definitions].

Each definition is independent and optional. You can include any combination of definitions based on your needs.

Currency Symbol Definition

The currency symbol definition specifies which character represents currency in PICTURE clauses. The syntax is:

cobol
1
CURRENCY SIGN IS literal [WITH PICTURE SYMBOL literal]

Basic Currency Definition

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. CURRENCY SIGN IS "$". DATA DIVISION. WORKING-STORAGE SECTION. 01 AMOUNT PIC $,$$$,$$$.99. PROCEDURE DIVISION. MAIN-PARA. MOVE 1234.56 TO AMOUNT DISPLAY AMOUNT *> Output: $1,234.56 STOP RUN.

In this example, the "$" character is defined as the currency symbol. When you use "$" in PICTURE clauses, it will display as a dollar sign.

Currency with Picture Symbol

You can use a different character in PICTURE clauses while defining a different display symbol:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. CURRENCY SIGN IS "€" WITH PICTURE SYMBOL "$". DATA DIVISION. WORKING-STORAGE SECTION. 01 EURO-AMOUNT PIC $,$$$,$$$.99. PROCEDURE DIVISION. MAIN-PARA. MOVE 1234.56 TO EURO-AMOUNT DISPLAY EURO-AMOUNT *> Output: €1,234.56 (uses € but PICTURE uses $) STOP RUN.

This allows you to use "$" in your PICTURE clauses (for compatibility) while displaying the euro symbol "€".

Decimal Point Definition

The DECIMAL-POINT IS COMMA clause swaps the roles of period and comma in numeric formatting, useful for European number formats.

Standard Decimal Point (Default)

cobol
1
2
3
4
5
6
7
8
9
10
DATA DIVISION. WORKING-STORAGE SECTION. 01 AMOUNT PIC 9(5)V99. PROCEDURE DIVISION. MAIN-PARA. MOVE 1234.56 TO AMOUNT DISPLAY AMOUNT *> Output: 01234.56 (period as decimal point) STOP RUN.

European Decimal Point (COMMA)

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. DECIMAL-POINT IS COMMA. DATA DIVISION. WORKING-STORAGE SECTION. 01 AMOUNT PIC 9(5)V99. PROCEDURE DIVISION. MAIN-PARA. MOVE 1234,56 TO AMOUNT DISPLAY AMOUNT *> Output: 01234,56 (comma as decimal point) *> Note: In literals, use comma instead of period STOP RUN.

When DECIMAL-POINT IS COMMA is specified:

  • In numeric literals: Use comma as decimal point (1234,56)
  • In PICTURE clauses: Comma represents decimal position
  • In display: Numbers show comma as decimal separator
  • Period becomes: Thousands separator (when used in editing)

Alphabet Names

Alphabet names define custom collating sequences (sorting orders) for character data. This is useful for specialized sorting requirements.

Defining an Alphabet

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. ALPHABET CUSTOM-ALPHABET IS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" " -.,". DATA DIVISION. WORKING-STORAGE SECTION. 01 SORT-FILE. 05 SORT-KEY PIC X(10). PROCEDURE DIVISION. SORT-EXAMPLE. *> Use custom alphabet for sorting SORT SORT-FILE ON ASCENDING KEY SORT-KEY COLLATING SEQUENCE IS CUSTOM-ALPHABET END-SORT.

Alphabet names allow you to:

  • Define custom order: Specify exact character sequence
  • Case-insensitive sorting: Treat uppercase and lowercase the same
  • Special character ordering: Control how special characters sort
  • International sorting: Support locale-specific collation

Class Names

Class names define sets of characters for use in class condition tests (IS NUMERIC, IS ALPHABETIC, etc.). This is useful for data validation.

Defining a Class

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. CLASS VALID-ID-CHARS IS "A" THRU "Z", "0" THRU "9", "-". DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-ID PIC X(10). PROCEDURE DIVISION. VALIDATE-ID. *> Check if ID contains only valid characters IF CUSTOMER-ID IS VALID-ID-CHARS DISPLAY 'Valid customer ID format' ELSE DISPLAY 'Invalid characters in ID' END-IF.

Class definitions can include:

  • Character ranges: "A" THRU "Z" (all letters)
  • Individual characters: "-", ".", etc.
  • Combinations: Mix of ranges and individual characters

Using Standard Classes

COBOL provides standard class names:

  • NUMERIC: Digits 0-9
  • ALPHABETIC: Letters A-Z and a-z
  • ALPHANUMERIC: Letters and digits
cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
DATA DIVISION. WORKING-STORAGE SECTION. 01 ACCOUNT-NUMBER PIC X(10). PROCEDURE DIVISION. VALIDATE-ACCOUNT. IF ACCOUNT-NUMBER IS NUMERIC DISPLAY 'Valid numeric account number' ELSE DISPLAY 'Account number must be numeric' END-IF IF ACCOUNT-NUMBER IS ALPHABETIC DISPLAY 'Contains only letters' END-IF IF ACCOUNT-NUMBER IS ALPHANUMERIC DISPLAY 'Contains letters and/or digits' END-IF.

Switch Status

Switch status allows you to define symbolic names for hardware or software switches, useful for conditional behavior and debugging.

Defining Switches

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. SWITCH-1 IS DEBUG-MODE ON STATUS IS DEBUG-ON OFF STATUS IS DEBUG-OFF. DATA DIVISION. WORKING-STORAGE SECTION. 01 DEBUG-FLAG PIC X. PROCEDURE DIVISION. MAIN-PARA. IF DEBUG-ON DISPLAY 'DEBUG: Entering main procedure' DISPLAY 'DEBUG: Processing data...' END-IF PERFORM PROCESS-DATA IF DEBUG-ON DISPLAY 'DEBUG: Exiting main procedure' END-IF STOP RUN. PROCESS-DATA. IF DEBUG-ON DISPLAY 'DEBUG: Processing data step 1' END-IF *> Process data here.

Switch status is useful for:

  • Debugging: Conditional debug output
  • Feature flags: Enable/disable features
  • Environment detection: Different behavior in different environments
  • Testing: Test mode vs. production mode

Complete SPECIAL-NAMES Example

Here's a complete example combining multiple SPECIAL-NAMES definitions:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
IDENTIFICATION DIVISION. PROGRAM-ID. SPECIAL-NAMES-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. *> Currency symbol CURRENCY SIGN IS "$" *> European decimal notation DECIMAL-POINT IS COMMA *> Custom alphabet for sorting ALPHABET CUSTOM-SORT IS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" *> Custom class for validation CLASS VALID-CODE IS "A" THRU "Z", "0" THRU "9", "-", "_" *> Debug switch SWITCH-1 IS DEBUG-MODE ON STATUS IS DEBUG-ON OFF STATUS IS DEBUG-OFF. DATA DIVISION. WORKING-STORAGE SECTION. 01 AMOUNT PIC $,$$$,$$$.99. 01 PRODUCT-CODE PIC X(10). 01 SORT-DATA PIC X(20). PROCEDURE DIVISION. MAIN-PARA. *> Use currency formatting MOVE 1234,56 TO AMOUNT DISPLAY 'Amount: ' AMOUNT *> Output: Amount: $1,234,56 *> Validate product code MOVE 'PROD-123' TO PRODUCT-CODE IF PRODUCT-CODE IS VALID-CODE DISPLAY 'Valid product code' ELSE DISPLAY 'Invalid product code' END-IF *> Conditional debug output IF DEBUG-ON DISPLAY 'Debug mode is ON' END-IF STOP RUN.

SPECIAL-NAMES Best Practices

Follow these best practices when using SPECIAL-NAMES:

1. Document Your Choices

Document why you're using each SPECIAL-NAMES definition:

cobol
1
2
3
4
5
6
7
8
9
SPECIAL-NAMES. *> Use euro symbol for European market CURRENCY SIGN IS "€" *> European number format (comma as decimal) DECIMAL-POINT IS COMMA *> Custom sorting for product codes ALPHABET PRODUCT-SORT IS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".

2. Use Meaningful Names

Choose descriptive names for alphabets, classes, and switches:

  • Use names that indicate purpose (VALID-ID-CHARS, not CLASS1)
  • Follow naming conventions
  • Make names self-documenting

3. Consider Portability

Be aware that some SPECIAL-NAMES features may not be supported in all COBOL implementations. Test thoroughly and document any implementation-specific behavior.

4. Group Related Definitions

Organize SPECIAL-NAMES definitions logically:

  • Currency and decimal point together (formatting)
  • Alphabets together (sorting)
  • Classes together (validation)
  • Switches together (control)

Common SPECIAL-NAMES Patterns

Pattern 1: International Formatting

cobol
1
2
3
SPECIAL-NAMES. CURRENCY SIGN IS "€" DECIMAL-POINT IS COMMA.

Pattern 2: Data Validation

cobol
1
2
3
4
SPECIAL-NAMES. CLASS VALID-ALPHANUMERIC IS "A" THRU "Z", "0" THRU "9".

Pattern 3: Debugging Support

cobol
1
2
3
4
SPECIAL-NAMES. SWITCH-1 IS DEBUG-MODE ON STATUS IS DEBUG-ON OFF STATUS IS DEBUG-OFF.

Explain Like I'm 5: SPECIAL-NAMES

Think of SPECIAL-NAMES like customizing your computer settings:

  • Currency symbol is like choosing your country's money symbol ($, €, £)
  • Decimal point is like choosing how to write numbers (1,234.56 vs 1.234,56)
  • Alphabet names are like choosing how to sort things (A-Z or custom order)
  • Class names are like defining what characters are "allowed" in a field
  • Switch status is like an on/off button you can check in your program

SPECIAL-NAMES lets you tell COBOL "this is how I want things to work in my program" - like setting preferences!

Practice Exercises

Complete these exercises to reinforce your understanding:

Exercise 1: Currency Configuration

Create a program that defines the euro symbol (€) as currency and displays formatted amounts. Test with different currency values.

Exercise 2: European Number Format

Create a program using DECIMAL-POINT IS COMMA. Test with numeric literals and formatted output to verify comma is used as decimal point.

Exercise 3: Custom Class Validation

Define a custom class for product codes that allows letters, digits, and hyphens. Create a validation routine that checks if input matches this class.

Exercise 4: Custom Alphabet Sorting

Define a custom alphabet and use it in a SORT operation. Compare the results with standard sorting to see the difference.

Exercise 5: Debug Switch

Implement a debug switch that controls debug output throughout your program. Test with the switch both on and off.

Test Your Knowledge

1. Where is the SPECIAL-NAMES paragraph located?

  • DATA DIVISION
  • PROCEDURE DIVISION
  • ENVIRONMENT DIVISION
  • WORKING-STORAGE SECTION

2. What does DECIMAL-POINT IS COMMA do?

  • Makes commas illegal
  • Swaps the roles of period and comma in numeric formatting
  • Forces all numbers to use commas
  • Has no effect

3. What is the purpose of alphabet names in SPECIAL-NAMES?

  • To name variables
  • To define custom collating sequences for sorting
  • To store alphabetic data
  • To define file names

4. How do you define a currency symbol?

  • CURRENCY = "$"
  • CURRENCY SIGN IS "$"
  • SET CURRENCY TO "$"
  • DEFINE CURRENCY "$"

5. What are class names used for?

  • Object-oriented programming
  • Defining sets of characters for validation
  • Naming classes of data
  • Grouping programs

6. Can you have multiple definitions in SPECIAL-NAMES?

  • No, only one definition allowed
  • Yes, multiple independent definitions
  • Only if they are the same type
  • Only in certain COBOL versions

Related Concepts

Related Pages