MainframeMaster

COBOL Tutorial

COBOL CONFIGURATION SECTION

Master environment setup and system configuration with the CONFIGURATION SECTION. Learn how to define computing environments, customize program behavior, and optimize compilation settings for your COBOL applications.

Overview

The CONFIGURATION SECTION is the first section within the ENVIRONMENT DIVISION of a COBOL program. It serves as the foundation for defining the computing environment, specifying compilation parameters, and customizing program behavior. This section provides essential information about the hardware and software environment where your program will be compiled and executed.

Within the CONFIGURATION SECTION, you can define source and object computer specifications, customize currency symbols and decimal points, create custom character classes, and establish various compilation options. This level of control is particularly important for enterprise applications that need to maintain consistency across different computing environments.

Understanding the CONFIGURATION SECTION is crucial for creating portable, maintainable COBOL programs that can adapt to different deployment environments while maintaining consistent behavior and formatting requirements.

Basic Structure and Syntax

Complete CONFIGURATION SECTION Structure

The CONFIGURATION SECTION follows a specific structure within the ENVIRONMENT DIVISION. Here's the basic framework that shows all possible paragraphs:

cobol
1
2
3
4
5
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. OBJECT-COMPUTER. SPECIAL-NAMES.

This basic structure shows the three main paragraphs that can appear in the CONFIGURATION SECTION. Each paragraph serves a specific purpose in defining the program's environment and behavior. All paragraphs are optional, but when present, they must appear in this order.

SOURCE-COMPUTER Paragraph

The SOURCE-COMPUTER paragraph identifies the computer system where the program will be compiled. This information helps the compiler optimize code generation for the specific hardware platform:

cobol
1
2
3
SOURCE-COMPUTER. IBM-370. SOURCE-COMPUTER. IBM-PC. SOURCE-COMPUTER. UNIX-SYSTEM.

The computer name can be any valid COBOL word that identifies your compilation platform. Modern COBOL compilers often use this information for optimization decisions and to ensure compatibility with the target compilation environment.

OBJECT-COMPUTER Paragraph

The OBJECT-COMPUTER paragraph specifies the system where the compiled program will execute. This can include memory size specifications and other runtime characteristics:

cobol
1
2
3
4
5
OBJECT-COMPUTER. IBM-370 MEMORY SIZE 2048 WORDS. OBJECT-COMPUTER. PRODUCTION-SERVER PROGRAM COLLATING SEQUENCE IS EBCDIC.

The OBJECT-COMPUTER paragraph can specify memory requirements, collating sequences, and other runtime characteristics that affect program execution. These specifications help ensure optimal performance in the target environment.

SPECIAL-NAMES Paragraph

Currency Symbol Customization

One of the most common uses of SPECIAL-NAMES is customizing the currency symbol used in PICTURE clauses. This is essential for international applications:

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

This configuration changes the default currency symbol from "$" to "€" and switches the decimal point from "." to "," (comma). This is particularly useful for European applications where comma is used as the decimal separator.

Custom Character Classes

SPECIAL-NAMES allows you to define custom character classes for data validation. This provides powerful pattern matching capabilities:

cobol
1
2
3
4
SPECIAL-NAMES. CLASS VOWELS IS "AEIOUaeiou" CLASS CONSONANTS IS "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz" CLASS DIGITS IS "0123456789".

These custom classes can then be used in conditional statements to validate data content. For example, you can test if a field contains only vowels or if a string consists entirely of digits.

Condition Name Assignments

SPECIAL-NAMES can assign meaningful names to special conditions, making your code more readable and maintainable:

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

This example creates meaningful names for system switches and console devices. You can then use DEBUG-MODE and PRODUCTION-MODE as condition names in your program logic, making the code more self-documenting.

Tutorial: Building a Multi-Currency Financial System

Let's create a comprehensive financial system that demonstrates the power of the CONFIGURATION SECTION for handling multiple currencies and international formatting requirements. This tutorial will show you how to build a flexible system that can adapt to different regional requirements.

Step 1: Define the Base Configuration

First, we'll establish the basic configuration for our financial system, including source and object computer specifications:

cobol
1
2
3
4
5
6
7
8
9
IDENTIFICATION DIVISION. PROGRAM-ID. FINANCIAL-SYSTEM. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. DEVELOPMENT-WORKSTATION. OBJECT-COMPUTER. PRODUCTION-SERVER MEMORY SIZE 4096 WORDS PROGRAM COLLATING SEQUENCE IS ASCII.

This configuration establishes that we're developing on a workstation but targeting a production server with specific memory and collating sequence requirements. The ASCII collating sequence ensures consistent sorting behavior across different systems.

Step 2: Configure Currency and Formatting

Next, we'll set up the SPECIAL-NAMES paragraph to handle European currency formatting with comma as decimal separator:

cobol
1
2
3
4
5
6
SPECIAL-NAMES. CURRENCY SIGN IS "€" DECIMAL-POINT IS COMMA CLASS VALID-CURRENCY IS "€$£¥" CLASS NUMERIC-CHARS IS "0123456789,.-" CONSOLE IS CRT-TERMINAL.

This configuration sets the Euro as the primary currency symbol, uses comma as the decimal separator, and defines custom classes for validating currency symbols and numeric data. The VALID-CURRENCY class includes multiple currency symbols for international support.

Step 3: Define Working Storage with Custom Formatting

Now we'll create working storage that takes advantage of our configuration settings for proper currency formatting:

cobol
1
2
3
4
5
6
7
DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-FINANCIAL-FIELDS. 05 WS-AMOUNT-EUR PIC €€€.€€€.€€9,99. 05 WS-AMOUNT-USD PIC $$$.$$$.$99.99. 05 WS-EXCHANGE-RATE PIC 9,9999. 05 WS-CONVERTED-AMT PIC €€€.€€€.€€9,99.

These field definitions use the configured currency symbols and decimal formatting. The Euro fields use comma as decimal separator due to our DECIMAL-POINT IS COMMA specification, while USD fields maintain the standard dot notation.

Step 4: Implement Currency Validation

Let's create validation routines that use our custom character classes:

cobol
1
2
3
4
5
6
7
8
9
10
11
PROCEDURE DIVISION. VALIDATE-CURRENCY-INPUT. ACCEPT WS-INPUT-CURRENCY FROM CRT-TERMINAL IF WS-INPUT-CURRENCY IS VALID-CURRENCY DISPLAY "Valid currency symbol entered" PERFORM PROCESS-TRANSACTION ELSE DISPLAY "Invalid currency symbol" PERFORM VALIDATE-CURRENCY-INPUT END-IF.

This validation routine uses our custom VALID-CURRENCY class to ensure that only supported currency symbols are accepted. The use of the configured CRT-TERMINAL name makes the code more readable and maintainable.

Step 5: Currency Conversion Logic

Finally, we'll implement currency conversion that respects our formatting configuration:

cobol
1
2
3
4
5
6
7
CONVERT-CURRENCY. MOVE 1,2050 TO WS-EXCHANGE-RATE COMPUTE WS-CONVERTED-AMT = WS-AMOUNT-USD * WS-EXCHANGE-RATE DISPLAY "Original USD: " WS-AMOUNT-USD DISPLAY "Exchange Rate: " WS-EXCHANGE-RATE DISPLAY "Converted EUR: " WS-CONVERTED-AMT.

This conversion routine automatically applies the correct formatting based on our CONFIGURATION SECTION settings. The comma decimal separator is used consistently throughout the calculations and display operations.

Advanced Configuration Techniques

Conditional Compilation Settings

Advanced COBOL systems often need different configurations for development, testing, and production environments. Here's how to handle this:

cobol
1
2
3
4
5
6
CONFIGURATION SECTION. SOURCE-COMPUTER. DEVELOPMENT-SYSTEM WITH DEBUGGING MODE. OBJECT-COMPUTER. PRODUCTION-SYSTEM MEMORY SIZE 8192 WORDS SEGMENT-LIMIT IS 64.

The WITH DEBUGGING MODE clause enables special debugging features during compilation, while the SEGMENT-LIMIT controls memory management for large programs. These settings can be adjusted based on the target environment.

International Character Support

For applications that need to handle international characters and multiple languages, the CONFIGURATION SECTION can specify appropriate settings:

cobol
1
2
3
4
5
SPECIAL-NAMES. ALPHABET INTERNATIONAL IS STANDARD-1 CLASS ACCENTED-CHARS IS "ÀÁÂÃÄÅàáâãäåÈÉÊËèéêë" CLASS GERMAN-CHARS IS "ÄÖÜäöüß" CLASS FRENCH-CHARS IS "ÀÂÄÇÉÈÊËÎÏÔÙÛÜàâäçéèêëîïôùûü".

These character class definitions enable proper validation and processing of international text data. You can create specific classes for different languages and use them in data validation routines.

Performance Optimization Settings

The CONFIGURATION SECTION can include settings that optimize program performance for specific hardware configurations:

cobol
1
2
3
4
5
6
7
8
OBJECT-COMPUTER. HIGH-PERFORMANCE-SERVER MEMORY SIZE 16384 WORDS PROGRAM COLLATING SEQUENCE IS EBCDIC SEGMENT-LIMIT IS 128. SPECIAL-NAMES. SWITCH-1 ON STATUS IS BATCH-MODE SWITCH-2 ON STATUS IS OPTIMIZE-MEMORY.

These settings configure the program for high-performance execution with larger memory allocation and optimized segmentation. The switch settings allow runtime control of optimization features.

Practical Exercises

Exercise 1: Multi-Language Support System

Create a CONFIGURATION SECTION that supports multiple languages with different currency symbols and decimal formats:

cobol
1
2
3
4
5
* Create configurations for: * - English ($ currency, . decimal) * - German (€ currency, , decimal) * - Japanese (¥ currency, . decimal) * Include appropriate character classes for each language

Solution Approach: Use conditional compilation or multiple program versions with different SPECIAL-NAMES configurations. Create character classes for language-specific validation and implement currency conversion routines that respect the formatting rules.

Exercise 2: Environment-Specific Configuration

Design a configuration system that adapts to different deployment environments (development, testing, production):

cobol
1
2
3
4
* Development: Enable debugging, smaller memory * Testing: Standard settings, validation enabled * Production: Optimized settings, larger memory * Include appropriate switch settings for each environment

Solution Approach: Create different versions of the CONFIGURATION SECTION for each environment, or use copybooks to maintain environment-specific settings. Implement switch-based logic to enable different features based on the deployment target.

Exercise 3: Custom Validation Framework

Build a comprehensive validation system using custom character classes:

cobol
1
2
3
4
5
6
* Create classes for: * - Email characters * - Phone number formats * - Social security numbers * - Credit card numbers * Implement validation routines using these classes

Solution Approach: Define comprehensive character classes in SPECIAL-NAMES for different data types. Create reusable validation paragraphs that use these classes to verify data format and content. Include error handling and user feedback mechanisms.

Best Practices and Guidelines

Configuration Management

  • Use meaningful computer names that reflect actual hardware or environments
  • Document all custom character classes and their intended purposes
  • Maintain separate configuration copybooks for different environments
  • Include comments explaining the rationale for specific settings
  • Test configuration changes across all target environments
  • Version control configuration settings along with source code

Portability Considerations

  • Avoid compiler-specific extensions in the CONFIGURATION SECTION
  • Use standard character sets and collating sequences when possible
  • Test programs with different CONFIGURATION SECTION settings
  • Document any environment-specific requirements
  • Consider using conditional compilation for environment differences
  • Validate that custom classes work correctly across platforms

Performance Optimization

  • Set appropriate memory sizes based on actual program requirements
  • Use segment limits to optimize memory usage for large programs
  • Choose collating sequences that match your data processing needs
  • Minimize the number of custom character classes to reduce overhead
  • Test performance impact of different configuration settings
  • Monitor memory usage and adjust settings as needed

Maintenance and Documentation

Proper documentation of your CONFIGURATION SECTION is essential for long-term maintenance. Include comments that explain the business rationale for specific settings, document any dependencies on external systems, and maintain a configuration change log.

Regular review of configuration settings ensures they remain appropriate as your system evolves. Consider the impact of configuration changes on existing data and programs, and always test thoroughly before deploying to production.

Interactive Quiz

Test Your CONFIGURATION SECTION Knowledge

Question 1:

Which paragraph in the CONFIGURATION SECTION specifies where the compiled program will execute?

Answer: OBJECT-COMPUTER. This paragraph specifies the computer system where the compiled program will execute, including memory requirements and runtime characteristics.

Question 2:

What does "DECIMAL-POINT IS COMMA" accomplish in SPECIAL-NAMES?

Answer: Uses comma as the decimal separator instead of period. This is particularly useful for European applications where comma is the standard decimal separator.

Question 3:

What is the primary purpose of custom character classes in SPECIAL-NAMES?

Answer: To enable data validation and pattern matching. Custom character classes allow you to define specific sets of characters and test whether data fields contain only those characters.

Frequently Asked Questions

Related Pages