COBOL standards are official specifications that define the COBOL programming language, ensuring consistency, portability, and compatibility across different implementations and platforms. Understanding COBOL standards is essential for writing portable code, choosing appropriate language features, and ensuring compatibility with your target environment. The main COBOL standards are COBOL 85, COBOL 2002, and COBOL 2014, each building upon previous standards while maintaining backward compatibility.
COBOL standards are formal specifications published by standards organizations (ANSI and ISO/IEC) that define:
Standards ensure that COBOL code written for one compiler can work with another (portability), provide a common reference for implementers, and give programmers confidence in language features and behavior.
COBOL has evolved through several major standards:
The first COBOL standard was published in 1960, with revisions in 1961, 1962, 1965, 1968, and 1974. These early standards established the foundation of COBOL but lacked structured programming features.
COBOL 85 was a major milestone that introduced structured programming features:
COBOL 85 is widely used in mainframe environments and is considered the de facto standard for traditional COBOL applications.
COBOL 2002 added modern programming features:
COBOL 2002 maintains full backward compatibility with COBOL 85 while adding object-oriented capabilities.
COBOL 2014 is the most recent standard, adding contemporary features:
COBOL 2014 maintains compatibility with previous standards while providing modern capabilities.
COBOL 85 introduced structured programming features that are now standard:
Scope terminators explicitly mark the end of control structures:
123456789101112131415*> COBOL 85: Using scope terminators IF CUSTOMER-AGE >= 18 DISPLAY 'Adult customer' IF CUSTOMER-AGE >= 65 DISPLAY 'Senior discount applies' END-IF ELSE DISPLAY 'Minor customer' END-IF *> Old style (COBOL 74) used periods: *> IF CUSTOMER-AGE >= 18 *> DISPLAY 'Adult customer'. *> IF CUSTOMER-AGE >= 65 *> DISPLAY 'Senior discount applies'.
Scope terminators make code more readable and reduce errors from misplaced periods. END-IF clearly marks where the IF statement ends, making nested IFs much clearer.
EVALUATE provides case logic for multiple conditions:
1234567891011*> COBOL 85: EVALUATE for case logic EVALUATE CUSTOMER-TYPE WHEN 'REGULAR' COMPUTE DISCOUNT = PRICE * 0.10 WHEN 'PREMIUM' COMPUTE DISCOUNT = PRICE * 0.20 WHEN 'VIP' COMPUTE DISCOUNT = PRICE * 0.30 WHEN OTHER COMPUTE DISCOUNT = 0 END-EVALUATE
EVALUATE is cleaner and more efficient than multiple IF statements for case logic. It's easier to read and maintain.
PERFORM can include inline statements:
123456789*> COBOL 85: Inline PERFORM PERFORM ADD 1 TO COUNTER DISPLAY 'Count: ' COUNTER IF COUNTER > 10 MOVE 'Y' TO DONE-FLAG END-IF UNTIL DONE-FLAG = 'Y' END-PERFORM
Inline PERFORM eliminates the need for separate paragraphs for simple loops, making code more compact and readable.
COBOL 2002 added object-oriented programming and modern features:
COBOL 2002 introduced classes, methods, and inheritance:
1234567891011121314151617181920212223*> COBOL 2002: Class definition CLASS-ID. CustomerClass. ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. CLASS CustomerClass. DATA DIVISION. WORKING-STORAGE SECTION. 01 customer-name PIC X(30). PROCEDURE DIVISION. METHOD-ID. set-name. DATA DIVISION. LINKAGE SECTION. 01 name-param PIC X(30). PROCEDURE DIVISION USING name-param. MOVE name-param TO customer-name END METHOD set-name. END CLASS CustomerClass.
Object-oriented features allow COBOL to support modern software design patterns, encapsulation, and code reuse through inheritance and polymorphism.
COBOL 2002 added FUNCTION keywords for built-in functions:
123456789101112131415161718192021*> COBOL 2002: Intrinsic functions WORKING-STORAGE SECTION. 01 text-field PIC X(30) VALUE 'Hello World'. 01 upper-text PIC X(30). 01 text-length PIC 9(4). PROCEDURE DIVISION. *> Convert to uppercase MOVE FUNCTION UPPER-CASE(text-field) TO upper-text *> Get length COMPUTE text-length = FUNCTION LENGTH(text-field) *> Reverse string MOVE FUNCTION REVERSE(text-field) TO upper-text DISPLAY 'Original: ' text-field DISPLAY 'Uppercase: ' upper-text DISPLAY 'Length: ' text-length STOP RUN.
Intrinsic functions provide built-in capabilities for common operations like string manipulation, mathematical functions, and data conversion, reducing the need for custom code.
COBOL 2014 added modern data format support and enhanced capabilities:
COBOL 2014 includes built-in JSON parsing and generation:
1234567891011121314*> COBOL 2014: JSON support (conceptual) WORKING-STORAGE SECTION. 01 json-data PIC X(200). 01 parsed-value PIC X(50). PROCEDURE DIVISION. *> Parse JSON JSON PARSE json-data INTO parsed-value *> Generate JSON JSON GENERATE json-data FROM parsed-value DISPLAY 'JSON data: ' json-data STOP RUN.
JSON support allows COBOL programs to easily work with modern web APIs and data exchange formats without external libraries.
COBOL 2014 improved table (array) operations:
1234567891011121314151617*> COBOL 2014: Dynamic tables WORKING-STORAGE SECTION. 01 table-size PIC 9(4) VALUE 100. 01 customer-table. 05 customer-entry OCCURS 1 TO 1000 TIMES DEPENDING ON table-size INDEXED BY customer-index. 10 customer-id PIC 9(5). 10 customer-name PIC X(30). PROCEDURE DIVISION. *> Dynamic table with variable size SET customer-index TO 1 MOVE 12345 TO customer-id(customer-index) MOVE 'JOHN SMITH' TO customer-name(customer-index) STOP RUN.
Enhanced table handling provides more flexible array operations and better support for dynamic data structures.
| Feature | COBOL 85 | COBOL 2002 | COBOL 2014 |
|---|---|---|---|
| Scope terminators (END-IF, etc.) | Yes | Yes | Yes |
| EVALUATE statement | Yes | Yes | Yes |
| Inline PERFORM | Yes | Yes | Yes |
| Object-oriented programming | No | Yes | Yes |
| Intrinsic functions (FUNCTION) | No | Yes | Yes |
| JSON/XML support | No | No | Yes |
| Enhanced exception handling | Basic | Improved | Advanced |
| Unicode support | Limited | Improved | Enhanced |
COBOL standards are designed to be backward compatible:
This compatibility allows organizations to migrate gradually, adopting new features as needed while maintaining existing code.
Consider these factors when choosing a standard:
Check what standards your COBOL compiler supports. Most mainframe compilers support COBOL 85, many support COBOL 2002, and some support COBOL 2014. Use the highest standard your compiler supports that meets your needs.
Your organization may have standards or policies specifying which COBOL standard to use. Many mainframe shops standardize on COBOL 85 for consistency and compatibility.
Consider what features you need:
If you need to share code with other systems or maintain compatibility with existing codebases, use the lowest common standard that meets your needs.
In mainframe environments:
Most mainframe COBOL programs use COBOL 85, which provides a good balance of modern structured programming features and wide compiler support.
Follow these best practices:
Use compiler directives to specify the COBOL standard:
123456789*> Specify COBOL 85 PROCESS NODYNAM, NOADV, NOSOURCE, NOSEQ *> Or use compiler-specific directives: *> IBM: PROCESS APOST, NODYNAM *> Micro Focus: $SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. ExampleProgram. *> Rest of program...
Compiler directives vary by vendor. Check your compiler documentation for the correct directives to specify your target COBOL standard.
Think of COBOL standards like different versions of a video game:
So COBOL standards are like different versions of the same game, each adding new features while keeping the old ones working!
Complete these exercises to reinforce your understanding:
Write a program using COBOL 85 features: scope terminators (END-IF, END-PERFORM), EVALUATE statement, and inline PERFORM. Demonstrate structured programming practices.
Research and document the key differences between COBOL 85, 2002, and 2014. Create a comparison table of features you would use in your environment.
Check your COBOL compiler documentation to determine which standards it supports. Document the compiler version and supported standards.
Write a simple COBOL 85 program and test it with different compiler settings to verify compatibility. Note any warnings or errors.
Identify a piece of old COBOL code (if available) and document how you would update it to use COBOL 85 features like scope terminators and EVALUATE.
1. Which COBOL standard introduced structured programming features like END-IF?
2. Which COBOL standard added object-oriented programming features?
3. Which COBOL standard is most commonly used in mainframe environments?
4. What does backward compatibility mean for COBOL standards?
5. Which standard added JSON and XML support?
6. What should you consider when choosing a COBOL standard?