MainframeMaster
MainframeMaster

COBOL Tutorial

Progress0 of 0 lessons

COBOL Standards

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.

What are COBOL Standards?

COBOL standards are formal specifications published by standards organizations (ANSI and ISO/IEC) that define:

  • Language syntax: Valid statements, clauses, and constructs
  • Data types: Supported data types and their characteristics
  • Features and capabilities: Available language features and functions
  • Behavior specifications: How language constructs should behave
  • Reserved words: Words that cannot be used as identifiers
  • Compatibility rules: How standards relate to each other

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.

History of COBOL Standards

COBOL has evolved through several major standards:

Early Standards (1960s-1970s)

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 (ANSI X3.23-1985)

COBOL 85 was a major milestone that introduced structured programming features:

  • Scope terminators: END-IF, END-PERFORM, END-READ, END-WRITE, etc.
  • Nested IF statements: IF statements within other IF statements
  • EVALUATE statement: Case logic for multiple conditions
  • Inline PERFORM: PERFORM with inline statements using END-PERFORM
  • Improved file handling: Better I/O operations and error handling
  • Boolean data: Support for true/false values

COBOL 85 is widely used in mainframe environments and is considered the de facto standard for traditional COBOL applications.

COBOL 2002 (ISO/IEC 1989:2002)

COBOL 2002 added modern programming features:

  • Object-oriented programming: Classes, methods, inheritance, polymorphism
  • Intrinsic functions: FUNCTION keywords for built-in functions
  • Improved string handling: Better string manipulation capabilities
  • Enhanced date/time: Better date and time functions
  • Exception handling: Improved error handling mechanisms
  • Modern file operations: Enhanced file I/O capabilities

COBOL 2002 maintains full backward compatibility with COBOL 85 while adding object-oriented capabilities.

COBOL 2014 (ISO/IEC 1989:2014)

COBOL 2014 is the most recent standard, adding contemporary features:

  • JSON and XML support: Built-in parsing and generation
  • Improved table handling: Dynamic tables and better array operations
  • Enhanced string functions: Additional string manipulation functions
  • Unicode support: Better international character handling
  • Improved exception handling: Try-catch blocks and better error management
  • Web service features: Support for modern web integration

COBOL 2014 maintains compatibility with previous standards while providing modern capabilities.

COBOL 85 Features

COBOL 85 introduced structured programming features that are now standard:

Scope Terminators

Scope terminators explicitly mark the end of control structures:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
*> 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 Statement

EVALUATE provides case logic for multiple conditions:

cobol
1
2
3
4
5
6
7
8
9
10
11
*> 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.

Inline PERFORM

PERFORM can include inline statements:

cobol
1
2
3
4
5
6
7
8
9
*> 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 Features

COBOL 2002 added object-oriented programming and modern features:

Object-Oriented Programming

COBOL 2002 introduced classes, methods, and inheritance:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
*> 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.

Intrinsic Functions

COBOL 2002 added FUNCTION keywords for built-in functions:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
*> 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 Features

COBOL 2014 added modern data format support and enhanced capabilities:

JSON Support

COBOL 2014 includes built-in JSON parsing and generation:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
*> 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.

Enhanced Table Handling

COBOL 2014 improved table (array) operations:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
*> 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.

Comparing COBOL Standards

COBOL Standards Feature Comparison
FeatureCOBOL 85COBOL 2002COBOL 2014
Scope terminators (END-IF, etc.)YesYesYes
EVALUATE statementYesYesYes
Inline PERFORMYesYesYes
Object-oriented programmingNoYesYes
Intrinsic functions (FUNCTION)NoYesYes
JSON/XML supportNoNoYes
Enhanced exception handlingBasicImprovedAdvanced
Unicode supportLimitedImprovedEnhanced

Backward Compatibility

COBOL standards are designed to be backward compatible:

  • COBOL 85 code works in COBOL 2002: Code written for COBOL 85 compiles and runs under COBOL 2002 compilers
  • COBOL 2002 code works in COBOL 2014: Code written for COBOL 2002 compiles and runs under COBOL 2014 compilers
  • Gradual adoption: You can adopt new features incrementally without rewriting existing code
  • Deprecated features: Some old features may generate warnings but still work
  • New reserved words: New standards may add reserved words that conflict with existing code (rare)

This compatibility allows organizations to migrate gradually, adopting new features as needed while maintaining existing code.

Choosing a COBOL Standard

Consider these factors when choosing a standard:

Compiler Support

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.

Organizational Requirements

Your organization may have standards or policies specifying which COBOL standard to use. Many mainframe shops standardize on COBOL 85 for consistency and compatibility.

Feature Requirements

Consider what features you need:

  • COBOL 85: Sufficient for most traditional mainframe applications
  • COBOL 2002: Needed for object-oriented programming or advanced intrinsic functions
  • COBOL 2014: Needed for JSON/XML support or other modern features

Compatibility Requirements

If you need to share code with other systems or maintain compatibility with existing codebases, use the lowest common standard that meets your needs.

Mainframe COBOL Standards

In mainframe environments:

  • COBOL 85 is most common: Widely supported, stable, and provides all features needed for traditional applications
  • COBOL 2002 is available: Supported by major mainframe compilers (IBM Enterprise COBOL, Micro Focus)
  • COBOL 2014 support varies: Check your specific compiler version for support
  • Compiler-specific extensions: Mainframe compilers often add extensions beyond standards

Most mainframe COBOL programs use COBOL 85, which provides a good balance of modern structured programming features and wide compiler support.

Best Practices for COBOL Standards

Follow these best practices:

  • Use scope terminators: Always use END-IF, END-PERFORM, etc., for clarity and maintainability (COBOL 85+)
  • Specify the standard: Use compiler directives to specify which standard you're targeting
  • Test compatibility: Test code on target compilers to ensure compatibility
  • Avoid deprecated features: Use modern alternatives to deprecated features when possible
  • Document standard used: Document which COBOL standard your code uses in comments or documentation
  • Check reserved words: Be aware of reserved words in your target standard
  • Use standard features: Prefer standard features over compiler-specific extensions for portability
  • Gradual migration: Migrate to newer standards gradually, testing thoroughly at each step
  • Understand limitations: Know what features are available in your target standard
  • Maintain compatibility: When possible, write code compatible with the lowest standard that meets your needs

Compiler Directives

Use compiler directives to specify the COBOL standard:

cobol
1
2
3
4
5
6
7
8
9
*> 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.

Explain Like I'm 5: COBOL Standards

Think of COBOL standards like different versions of a video game:

  • COBOL 85 is like the original game with all the basic features - it has everything you need to play and have fun
  • COBOL 2002 is like an updated version that adds new characters and abilities - you can still play the old way, but now you have more options
  • COBOL 2014 is like the latest version with online features and new modes - it has everything from before plus modern features
  • Backward compatibility means you can play games from older versions on newer consoles - old code works with new compilers
  • Choosing a standard is like choosing which game version to play - you pick the one that has the features you want and works on your system

So COBOL standards are like different versions of the same game, each adding new features while keeping the old ones working!

Practice Exercises

Complete these exercises to reinforce your understanding:

Exercise 1: COBOL 85 Features

Write a program using COBOL 85 features: scope terminators (END-IF, END-PERFORM), EVALUATE statement, and inline PERFORM. Demonstrate structured programming practices.

Exercise 2: Standard Comparison

Research and document the key differences between COBOL 85, 2002, and 2014. Create a comparison table of features you would use in your environment.

Exercise 3: Compiler Check

Check your COBOL compiler documentation to determine which standards it supports. Document the compiler version and supported standards.

Exercise 4: Compatibility Test

Write a simple COBOL 85 program and test it with different compiler settings to verify compatibility. Note any warnings or errors.

Exercise 5: Feature Migration

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.

Test Your Knowledge

1. Which COBOL standard introduced structured programming features like END-IF?

  • COBOL 74
  • COBOL 85
  • COBOL 2002
  • COBOL 2014

2. Which COBOL standard added object-oriented programming features?

  • COBOL 85
  • COBOL 2002
  • COBOL 2014
  • COBOL 74

3. Which COBOL standard is most commonly used in mainframe environments?

  • COBOL 2014
  • COBOL 2002
  • COBOL 85
  • COBOL 74

4. What does backward compatibility mean for COBOL standards?

  • New standards cannot use old features
  • Code from older standards works in newer compilers
  • New standards replace old standards completely
  • You must rewrite code for each standard

5. Which standard added JSON and XML support?

  • COBOL 85
  • COBOL 2002
  • COBOL 2014
  • None of the above

6. What should you consider when choosing a COBOL standard?

  • Only the latest standard
  • Compiler support, organizational requirements, and needed features
  • Only backward compatibility
  • Only object-oriented features

Related Concepts

Related Pages