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.
SPECIAL-NAMES is an optional paragraph in the CONFIGURATION SECTION of the ENVIRONMENT DIVISION. It allows you to:
SPECIAL-NAMES provides portability and flexibility, allowing programs to adapt to different environments without code changes.
The SPECIAL-NAMES paragraph follows this general structure:
123456789ENVIRONMENT 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.
The currency symbol definition specifies which character represents currency in PICTURE clauses. The syntax is:
1CURRENCY SIGN IS literal [WITH PICTURE SYMBOL literal]
123456789101112131415ENVIRONMENT 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.
You can use a different character in PICTURE clauses while defining a different display symbol:
123456789101112131415ENVIRONMENT 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 "€".
The DECIMAL-POINT IS COMMA clause swaps the roles of period and comma in numeric formatting, useful for European number formats.
12345678910DATA 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.
12345678910111213141516ENVIRONMENT 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:
Alphabet names define custom collating sequences (sorting orders) for character data. This is useful for specialized sorting requirements.
1234567891011121314151617181920ENVIRONMENT 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:
Class names define sets of characters for use in class condition tests (IS NUMERIC, IS ALPHABETIC, etc.). This is useful for data validation.
1234567891011121314151617181920ENVIRONMENT 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:
COBOL provides standard class names:
12345678910111213141516171819DATA 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 allows you to define symbolic names for hardware or software switches, useful for conditional behavior and debugging.
12345678910111213141516171819202122232425262728293031ENVIRONMENT 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:
Here's a complete example combining multiple SPECIAL-NAMES definitions:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455IDENTIFICATION 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.
Follow these best practices when using SPECIAL-NAMES:
Document why you're using each SPECIAL-NAMES definition:
123456789SPECIAL-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".
Choose descriptive names for alphabets, classes, and switches:
Be aware that some SPECIAL-NAMES features may not be supported in all COBOL implementations. Test thoroughly and document any implementation-specific behavior.
Organize SPECIAL-NAMES definitions logically:
123SPECIAL-NAMES. CURRENCY SIGN IS "€" DECIMAL-POINT IS COMMA.
1234SPECIAL-NAMES. CLASS VALID-ALPHANUMERIC IS "A" THRU "Z", "0" THRU "9".
1234SPECIAL-NAMES. SWITCH-1 IS DEBUG-MODE ON STATUS IS DEBUG-ON OFF STATUS IS DEBUG-OFF.
Think of SPECIAL-NAMES like customizing your computer settings:
SPECIAL-NAMES lets you tell COBOL "this is how I want things to work in my program" - like setting preferences!
Complete these exercises to reinforce your understanding:
Create a program that defines the euro symbol (€) as currency and displays formatted amounts. Test with different currency values.
Create a program using DECIMAL-POINT IS COMMA. Test with numeric literals and formatted output to verify comma is used as decimal point.
Define a custom class for product codes that allows letters, digits, and hyphens. Create a validation routine that checks if input matches this class.
Define a custom alphabet and use it in a SORT operation. Compare the results with standard sorting to see the difference.
Implement a debug switch that controls debug output throughout your program. Test with the switch both on and off.
1. Where is the SPECIAL-NAMES paragraph located?
2. What does DECIMAL-POINT IS COMMA do?
3. What is the purpose of alphabet names in SPECIAL-NAMES?
4. How do you define a currency symbol?
5. What are class names used for?
6. Can you have multiple definitions in SPECIAL-NAMES?