COBOL SPECIAL-NAMES Clause - Quick Reference
The SPECIAL-NAMES clause in COBOL is used to define special names, conditions, alphabet names, class names, and currency symbols. It provides a way to customize system-specific features and create mnemonic names for various COBOL elements.
Primary Use
Define special names and system features
Division
ENVIRONMENT DIVISION
Section
CONFIGURATION SECTION
Status
Optional clause
Overview
The SPECIAL-NAMES clause is part of the CONFIGURATION SECTION in the ENVIRONMENT DIVISION. It allows you to define custom names for various system features, conditions, and special identifiers. This includes alphabet names for custom character sets, class names for data validation, condition names for system status, and currency symbols for international applications.
Syntax
1234567891011121314151617ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. [ALPHABET alphabet-name IS {STANDARD-1 | STANDARD-2 | NATIVE | literal-1}] [CLASS class-name IS {literal-2 | THROUGH | THRU literal-3}] [CONDITION condition-name IS {mnemonic-name | ON STATUS IS condition-1 | OFF STATUS IS condition-2}] [CURRENCY SIGN IS literal-4] [DECIMAL-POINT IS COMMA] [SYMBOLIC CHARACTERS {symbolic-character-1 | symbolic-character-2} IN alphabet-name]. * Examples: SPECIAL-NAMES. ALPHABET CUSTOM-ALPHABET IS "ABCDEFGHIJKLMNOPQRSTUVWXYZ". CLASS VALID-NUMBERS IS "0" THROUGH "9". CONDITION FILE-ERROR IS "30" ON STATUS IS 30. CURRENCY SIGN IS "$". DECIMAL-POINT IS COMMA.
Practical Examples
Basic SPECIAL-NAMES Usage
12345678910111213141516171819202122* Basic SPECIAL-NAMES clause example IDENTIFICATION DIVISION. PROGRAM-ID. SPECIAL-NAMES-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. CURRENCY SIGN IS "$" DECIMAL-POINT IS COMMA. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-AMOUNT PIC 9(7)V99 VALUE 1234567,89. 01 WS-CURRENCY-FIELD PIC $9(7),99. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Amount: " WS-AMOUNT DISPLAY "Currency: " WS-CURRENCY-FIELD DISPLAY "Decimal point is comma" DISPLAY "Currency sign is $" STOP RUN.
Explanation: This example demonstrates basic usage of the SPECIAL-NAMES clause. The program defines a custom currency sign ($) and decimal point (comma) for European-style number formatting. The CURRENCY SIGN IS "$" allows the $ symbol to be used in PICTURE clauses, and DECIMAL-POINT IS COMMA changes the decimal separator from period to comma for display purposes.
Alphabet and Class Definitions
12345678910111213141516171819202122232425262728293031323334353637383940414243* SPECIAL-NAMES with alphabet and class definitions IDENTIFICATION DIVISION. PROGRAM-ID. ALPHABET-CLASS-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. ALPHABET CUSTOM-ALPHABET IS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" CLASS VALID-NUMBERS IS "0" THROUGH "9" CLASS VALID-LETTERS IS "A" THROUGH "Z". DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-INPUT-FIELD PIC X(10). 01 WS-NUMERIC-FIELD PIC 9(5). 01 WS-ALPHA-FIELD PIC A(10). PROCEDURE DIVISION. MAIN-LOGIC. MOVE "ABC123XYZ" TO WS-INPUT-FIELD * Check if field contains only numbers IF WS-INPUT-FIELD IS NUMERIC DISPLAY "Field contains only numbers" ELSE DISPLAY "Field contains non-numeric characters" END-IF * Check if field contains only letters IF WS-INPUT-FIELD IS ALPHABETIC DISPLAY "Field contains only letters" ELSE DISPLAY "Field contains non-alphabetic characters" END-IF * Use custom alphabet for comparison IF WS-INPUT-FIELD IS CUSTOM-ALPHABET DISPLAY "Field matches custom alphabet" ELSE DISPLAY "Field does not match custom alphabet" END-IF STOP RUN.
Explanation: This example shows how to define custom alphabets and classes using SPECIAL-NAMES. The CUSTOM-ALPHABET defines a specific character set, while VALID-NUMBERS and VALID-LETTERS define classes for numeric and alphabetic validation. These definitions can be used in conditional statements to validate data content and perform custom character set comparisons.
Condition Names and Status Codes
1234567891011121314151617181920212223242526272829303132333435363738394041424344* SPECIAL-NAMES with condition names and status codes IDENTIFICATION DIVISION. PROGRAM-ID. CONDITION-NAMES-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. CONDITION FILE-ERROR IS "30" ON STATUS IS 30 CONDITION FILE-NOT-FOUND IS "35" ON STATUS IS 35 CONDITION FILE-ACCESS-DENIED IS "37" ON STATUS IS 37. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-FILE-STATUS PIC XX. 01 WS-ERROR-MESSAGE PIC X(50). PROCEDURE DIVISION. MAIN-LOGIC. * Simulate different file status conditions MOVE "30" TO WS-FILE-STATUS PERFORM CHECK-FILE-STATUS MOVE "35" TO WS-FILE-STATUS PERFORM CHECK-FILE-STATUS MOVE "37" TO WS-FILE-STATUS PERFORM CHECK-FILE-STATUS STOP RUN. CHECK-FILE-STATUS. EVALUATE TRUE WHEN FILE-ERROR MOVE "File error occurred" TO WS-ERROR-MESSAGE DISPLAY "Status: " WS-FILE-STATUS " - " WS-ERROR-MESSAGE WHEN FILE-NOT-FOUND MOVE "File not found" TO WS-ERROR-MESSAGE DISPLAY "Status: " WS-FILE-STATUS " - " WS-ERROR-MESSAGE WHEN FILE-ACCESS-DENIED MOVE "File access denied" TO WS-ERROR-MESSAGE DISPLAY "Status: " WS-FILE-STATUS " - " WS-ERROR-MESSAGE WHEN OTHER DISPLAY "Unknown file status: " WS-FILE-STATUS END-EVALUATE.
Explanation: This example demonstrates how to define condition names for file status codes using SPECIAL-NAMES. The condition names FILE-ERROR, FILE-NOT-FOUND, and FILE-ACCESS-DENIED are mapped to specific status codes (30, 35, 37). This makes the code more readable and maintainable by using descriptive names instead of numeric codes. The EVALUATE statement can then use these condition names for clearer error handling.
International Currency and Decimal Handling
12345678910111213141516171819202122232425262728293031323334353637383940414243* SPECIAL-NAMES for international applications IDENTIFICATION DIVISION. PROGRAM-ID. INTERNATIONAL-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. CURRENCY SIGN IS "€" DECIMAL-POINT IS COMMA ALPHABET EUROPEAN-ALPHABET IS "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜß". DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-EURO-AMOUNT PIC €9(7),99 VALUE 1234567,89. 01 WS-GERMAN-TEXT PIC X(20) VALUE "Müllerstraße". 01 WS-FRENCH-AMOUNT PIC 9(7),99 VALUE 9876543,21. 01 WS-FORMATTED-OUTPUT. 05 WS-CURRENCY-LINE PIC X(30) VALUE "Amount: €". 05 WS-AMOUNT-DISPLAY PIC €9(7),99. 05 WS-DECIMAL-NOTE PIC X(20) VALUE " (comma decimal)". PROCEDURE DIVISION. MAIN-LOGIC. * Display European currency format MOVE WS-EURO-AMOUNT TO WS-AMOUNT-DISPLAY DISPLAY WS-CURRENCY-LINE WS-AMOUNT-DISPLAY WS-DECIMAL-NOTE * Display German text with special characters DISPLAY "German text: " WS-GERMAN-TEXT * Check if text uses European alphabet IF WS-GERMAN-TEXT IS EUROPEAN-ALPHABET DISPLAY "Text uses European alphabet characters" ELSE DISPLAY "Text contains non-European characters" END-IF * Display French amount format DISPLAY "French amount: " WS-FRENCH-AMOUNT DISPLAY "International formatting complete" STOP RUN.
Explanation: This example shows SPECIAL-NAMES usage for international applications. The program defines a Euro currency symbol (€), uses comma as decimal point for European number formatting, and creates a custom alphabet that includes German umlauts and special characters. This allows the program to handle European-style currency display, number formatting, and text validation with special characters commonly used in European languages.
Best Practices and Considerations
Important Considerations
- SPECIAL-NAMES is optional and can be omitted if not needed
- Use consistent naming conventions for custom definitions
- Consider portability when defining system-specific features
- Test alphabet and class definitions thoroughly
- Document custom currency and decimal point definitions
Advantages
- Provides customization for system-specific features
- Enables internationalization support
- Improves code readability with mnemonic names
- Supports custom character sets and validation
- Allows flexible currency and decimal handling
Limitations
- Optional clause that may be omitted
- System-specific features may not be portable
- Requires careful testing of custom definitions
- May not be supported in all COBOL implementations
- Can add complexity to program maintenance
Best Practices
- • Use descriptive names for custom definitions
- • Document all SPECIAL-NAMES definitions
- • Test custom alphabets and classes thoroughly
- • Consider portability when defining system features
- • Use consistent naming conventions
Test Your Knowledge
1. What is the primary purpose of the SPECIAL-NAMES clause in COBOL?
- To define program variables
- To define special names, conditions, and system-specific features
- To specify file names
- To define data types
2. In which COBOL division is the SPECIAL-NAMES clause typically used?
- IDENTIFICATION DIVISION
- ENVIRONMENT DIVISION
- DATA DIVISION
- PROCEDURE DIVISION
3. What can be defined using the SPECIAL-NAMES clause?
- Only variable names
- Only file names
- Special names, conditions, alphabet names, class names, and currency symbols
- Only procedure names
4. What is the purpose of defining alphabet names in SPECIAL-NAMES?
- To create new programming languages
- To define custom character sets and collating sequences
- To name variables
- To define file names
5. Can SPECIAL-NAMES be used to define currency symbols?
- No, it is not possible
- Yes, it can define currency symbols and decimal point characters
- Only in some implementations
- Only for international programs