COBOL STANDARD Clause - Quick Reference
The STANDARD clause in COBOL is used to specify the COBOL standard compliance level and available features. It allows you to control which COBOL language features are available and ensure compatibility with specific COBOL standards.
Primary Use
Specify COBOL standard compliance level
Division
ENVIRONMENT DIVISION
Section
CONFIGURATION SECTION
Status
Optional clause
Overview
The STANDARD clause is part of the CONFIGURATION SECTION in the ENVIRONMENT DIVISION. It specifies which COBOL standard features and compliance level your program should follow. This includes STANDARD-1 (COBOL 85) and STANDARD-2 (COBOL 2002), each providing different sets of language features and capabilities.
Syntax
123456789101112131415ENVIRONMENT DIVISION. CONFIGURATION SECTION. STANDARD-1. * OR STANDARD-2. * Examples: ENVIRONMENT DIVISION. CONFIGURATION SECTION. STANDARD-1. * OR for newer features: ENVIRONMENT DIVISION. CONFIGURATION SECTION. STANDARD-2.
Practical Examples
Basic STANDARD-1 Usage
123456789101112131415161718192021222324252627* Basic STANDARD-1 clause example (COBOL 85) IDENTIFICATION DIVISION. PROGRAM-ID. STANDARD-1-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. STANDARD-1. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-COUNTER PIC 9(3) VALUE ZERO. 01 WS-RESULT PIC 9(5). 01 WS-MESSAGE PIC X(50) VALUE "Using COBOL 85 Standard". PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY WS-MESSAGE DISPLAY "Standard: COBOL 85 (STANDARD-1)" * Perform some calculations using COBOL 85 features PERFORM VARYING WS-COUNTER FROM 1 BY 1 UNTIL WS-COUNTER > 5 COMPUTE WS-RESULT = WS-COUNTER * 10 DISPLAY "Counter: " WS-COUNTER " Result: " WS-RESULT END-PERFORM DISPLAY "STANDARD-1 processing completed" STOP RUN.
Explanation: This example demonstrates basic usage of the STANDARD-1 clause. The program specifies COBOL 85 compliance, which provides the standard COBOL 85 language features. This includes basic arithmetic operations, PERFORM loops, and standard COBOL syntax. STANDARD-1 ensures compatibility with COBOL 85 implementations and restricts the program to features available in that standard.
STANDARD-2 with Advanced Features
1234567891011121314151617181920212223242526272829303132* STANDARD-2 clause example (COBOL 2002) IDENTIFICATION DIVISION. PROGRAM-ID. STANDARD-2-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. STANDARD-2. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-COUNTER PIC 9(3) VALUE ZERO. 01 WS-RESULT PIC 9(5). 01 WS-MESSAGE PIC X(50) VALUE "Using COBOL 2002 Standard". 01 WS-ARRAY PIC 9(3) OCCURS 10 TIMES. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY WS-MESSAGE DISPLAY "Standard: COBOL 2002 (STANDARD-2)" * Use COBOL 2002 features like enhanced PERFORM PERFORM VARYING WS-COUNTER FROM 1 BY 1 UNTIL WS-COUNTER > 10 MOVE WS-COUNTER TO WS-ARRAY(WS-COUNTER) COMPUTE WS-RESULT = WS-COUNTER * WS-COUNTER DISPLAY "Index: " WS-COUNTER " Array Value: " WS-ARRAY(WS-COUNTER) " Square: " WS-RESULT END-PERFORM * Use COBOL 2002 string functions DISPLAY "String length of message: " FUNCTION LENGTH(WS-MESSAGE) DISPLAY "STANDARD-2 processing completed" STOP RUN.
Explanation: This example shows STANDARD-2 usage with COBOL 2002 features. STANDARD-2 enables additional language features beyond COBOL 85, including enhanced PERFORM statements, built-in functions like FUNCTION LENGTH, improved array handling, and other COBOL 2002 capabilities. This provides more modern COBOL features while maintaining backward compatibility where possible.
Standard Compliance Checking
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960* Standard compliance checking example IDENTIFICATION DIVISION. PROGRAM-ID. STANDARD-COMPLIANCE-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. STANDARD-1. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-STANDARD-LEVEL PIC X(10) VALUE "STANDARD-1". 01 WS-FEATURE-STATUS PIC X(20). 01 WS-COMPLIANCE-CHECK PIC X(1) VALUE 'Y'. 01 WS-FEATURES. 05 WS-ENHANCED-PERFORM PIC X(1) VALUE 'N'. 05 WS-BUILTIN-FUNCTIONS PIC X(1) VALUE 'N'. 05 WS-ADVANCED-ARRAYS PIC X(1) VALUE 'N'. 05 WS-EXCEPTION-HANDLING PIC X(1) VALUE 'N'. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "COBOL Standard Compliance Check" DISPLAY "Standard Level: " WS-STANDARD-LEVEL * Check available features based on standard PERFORM CHECK-STANDARD-FEATURES * Display feature availability DISPLAY "Feature Availability:" DISPLAY "Enhanced PERFORM: " WS-ENHANCED-PERFORM DISPLAY "Built-in Functions: " WS-BUILTIN-FUNCTIONS DISPLAY "Advanced Arrays: " WS-ADVANCED-ARRAYS DISPLAY "Exception Handling: " WS-EXCEPTION-HANDLING IF WS-COMPLIANCE-CHECK = 'Y' DISPLAY "Program is compliant with " WS-STANDARD-LEVEL ELSE DISPLAY "Compliance issues detected" END-IF STOP RUN. CHECK-STANDARD-FEATURES. * Check which features are available in STANDARD-1 IF WS-STANDARD-LEVEL = "STANDARD-1" MOVE 'N' TO WS-ENHANCED-PERFORM MOVE 'N' TO WS-BUILTIN-FUNCTIONS MOVE 'N' TO WS-ADVANCED-ARRAYS MOVE 'N' TO WS-EXCEPTION-HANDLING MOVE "COBOL 85 Features Only" TO WS-FEATURE-STATUS ELSE MOVE 'Y' TO WS-ENHANCED-PERFORM MOVE 'Y' TO WS-BUILTIN-FUNCTIONS MOVE 'Y' TO WS-ADVANCED-ARRAYS MOVE 'Y' TO WS-EXCEPTION-HANDLING MOVE "COBOL 2002 Features" TO WS-FEATURE-STATUS END-IF DISPLAY "Feature Status: " WS-FEATURE-STATUS.
Explanation: This example demonstrates how to check standard compliance and feature availability. The program uses STANDARD-1 and includes logic to determine which COBOL features are available based on the specified standard. This is useful for ensuring program compatibility and understanding which language constructs can be used safely. The program checks for features like enhanced PERFORM statements, built-in functions, advanced array handling, and exception handling.
Portability and Migration Example
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859* Portability and migration example IDENTIFICATION DIVISION. PROGRAM-ID. PORTABILITY-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. * Use STANDARD-1 for maximum portability STANDARD-1. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-PORTABILITY-INFO. 05 WS-TARGET-STANDARD PIC X(10) VALUE "STANDARD-1". 05 WS-MIGRATION-STATUS PIC X(1) VALUE 'P'. * P = Portable, N = Needs Migration, C = Compatible 05 WS-COMPATIBILITY PIC X(1) VALUE 'Y'. 01 WS-FEATURE-USAGE. 05 WS-USES-ENHANCED-PERFORM PIC X(1) VALUE 'N'. 05 WS-USES-BUILTIN-FUNCTIONS PIC X(1) VALUE 'N'. 05 WS-USES-ADVANCED-ARRAYS PIC X(1) VALUE 'N'. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "COBOL Portability Analysis" DISPLAY "Target Standard: " WS-TARGET-STANDARD * Analyze feature usage for portability PERFORM ANALYZE-PORTABILITY * Display portability results DISPLAY "Portability Analysis Results:" DISPLAY "Migration Status: " WS-MIGRATION-STATUS DISPLAY "Compatibility: " WS-COMPATIBILITY DISPLAY "Enhanced PERFORM Usage: " WS-USES-ENHANCED-PERFORM DISPLAY "Built-in Functions Usage: " WS-USES-BUILTIN-FUNCTIONS DISPLAY "Advanced Arrays Usage: " WS-USES-ADVANCED-ARRAYS IF WS-COMPATIBILITY = 'Y' DISPLAY "Program is portable across COBOL implementations" ELSE DISPLAY "Program may require modifications for portability" END-IF STOP RUN. ANALYZE-PORTABILITY. * Check if program uses STANDARD-2 features IF WS-USES-ENHANCED-PERFORM = 'Y' OR WS-USES-BUILTIN-FUNCTIONS = 'Y' OR WS-USES-ADVANCED-ARRAYS = 'Y' MOVE 'N' TO WS-MIGRATION-STATUS MOVE 'N' TO WS-COMPATIBILITY DISPLAY "Program uses STANDARD-2 features - migration required" ELSE MOVE 'P' TO WS-MIGRATION-STATUS MOVE 'Y' TO WS-COMPATIBILITY DISPLAY "Program uses only STANDARD-1 features - portable" END-IF.
Explanation: This example shows how to analyze program portability based on the STANDARD clause. The program uses STANDARD-1 for maximum portability and includes logic to check if any STANDARD-2 features are being used. This is important for programs that need to run on different COBOL implementations or when migrating between systems. The analysis helps determine if the program will be compatible with different COBOL standards and implementations.
Best Practices and Considerations
Important Considerations
- STANDARD clause is optional and defaults to STANDARD-1
- Use STANDARD-1 for maximum portability
- Use STANDARD-2 for access to newer COBOL features
- Consider target system compatibility when choosing standard
- Document standard requirements for program maintenance
Advantages
- Controls available COBOL language features
- Ensures compatibility with specific standards
- Improves program portability
- Enables access to newer COBOL features
- Provides clear compliance documentation
Limitations
- Optional clause that may be omitted
- May restrict access to newer features
- Requires understanding of standard differences
- May not be supported in all implementations
- Can affect program functionality
Best Practices
- • Use STANDARD-1 for maximum portability
- • Use STANDARD-2 when newer features are needed
- • Document standard requirements clearly
- • Test compatibility with target systems
- • Consider migration implications
Test Your Knowledge
1. What is the primary purpose of the STANDARD clause in COBOL?
- To define program variables
- To specify standard features and compliance levels
- To define file names
- To specify data types
2. In which COBOL division is the STANDARD clause typically used?
- IDENTIFICATION DIVISION
- ENVIRONMENT DIVISION
- DATA DIVISION
- PROCEDURE DIVISION
3. What are the common values for the STANDARD clause?
- STANDARD-1 and STANDARD-2
- STANDARD-1, STANDARD-2, and STANDARD-3
- STANDARD-1 only
- STANDARD-2 only
4. What is the difference between STANDARD-1 and STANDARD-2?
- They are the same thing
- STANDARD-1 is COBOL 85, STANDARD-2 is COBOL 2002 with additional features
- STANDARD-1 is newer than STANDARD-2
- They cannot be used together
5. Can the STANDARD clause be omitted from a COBOL program?
- No, it is required
- Yes, it is optional and defaults to STANDARD-1
- No, it is mandatory
- Only in some implementations