Chapter 21 Exercises: COBOL Coding Standards and Best Practices

Tier 1: Recall and Recognition (Exercises 1-7)

Exercise 1: Naming Convention Identification

For each of the following variable names, identify whether it follows good naming conventions and explain why or why not. If the name is poor, suggest a better alternative.

a) W01-X b) WS-CUSTOMER-BALANCE c) A d) CT-RECORDS-READ e) CRSMTPGDR f) WS-AMT g) data-field h) FL-END-OF-FILE i) SAVE-IT j) WS-ACCT-LAST-TRANS-DT

Solution:

a) Poor. W01-X is cryptic -- no indication of purpose or content. Better: WS-TEMP-COUNTER or whatever the field actually represents.

b) Good. WS-CUSTOMER-BALANCE has a clear prefix (WS = Working-Storage), uses hyphens, and is self-documenting.

c) Poor. Single-character names are never acceptable in COBOL. Better: name it after its purpose.

d) Good. CT-RECORDS-READ uses the counter prefix (CT) and describes exactly what it counts.

e) Poor. CRSMTPGDR is an incomprehensible abbreviation. Better: WS-CORRESPONDENCE-PAGER or whatever it means.

f) Acceptable with caution. WS-AMT uses a common abbreviation (AMT = amount) but lacks specificity. Better: WS-TRANS-AMOUNT or WS-PAYMENT-AMOUNT.

g) Poor. data-field is vague and lacks a prefix. Better: prefix and specific purpose, e.g., WS-INPUT-DATA-FIELD.

h) Good. FL-END-OF-FILE uses the flag prefix (FL) and is clear.

i) Poor. SAVE-IT is vague and colloquial. Better: WS-SAVED-ACCOUNT-NUM or whatever is being saved.

j) Good. WS-ACCT-LAST-TRANS-DT uses standard abbreviations (ACCT, TRANS, DT) and is clearly structured.

Exercise 2: Prefix Matching

Match each prefix to its conventional meaning in COBOL WORKING-STORAGE:

Prefix Meaning
a) WS- 1) Counter
b) CT- 2) Flag or boolean
c) FL- 3) Table entry
d) AC- 4) Error-related
e) WK- 5) General working-storage variable
f) TB- 6) Accumulator
g) ER- 7) Work/temporary variable
h) SW- 8) Switch
i) IX- 9) Report-related
j) RPT- 10) Index

Solution: a-5, b-1, c-2, d-6, e-7, f-3, g-4, h-8, i-10, j-9

Exercise 3: Paragraph Numbering

A program has the following paragraphs. Reorganize them using the standard numbering convention (0000-MAIN, 1000-level for major sections, 1100-level for subsections):

Current (disordered):

PROCESS-RECORDS
DO-CALCULATIONS
OPEN-ALL-FILES
MAIN-CONTROL
CLOSE-ALL-FILES
READ-INPUT
VALIDATE-DATA
WRITE-OUTPUT
HANDLE-ERROR
PRINT-SUMMARY

Exercise 4: Structured Programming Violations

Identify the structured programming violations in the following code and explain why each is problematic:

       0000-MAIN.
           OPEN INPUT TRANS-FILE
           OPEN I-O MASTER-FILE
       READ-NEXT.
           READ TRANS-FILE
               AT END GO TO WRAP-UP
           END-READ
           IF TR-TYPE = 'A'
               GO TO DO-ADD
           END-IF
           IF TR-TYPE = 'D'
               GO TO DO-DELETE
           END-IF
           GO TO READ-NEXT.
       DO-ADD.
           WRITE MASTER-RECORD FROM TR-RECORD
           GO TO READ-NEXT.
       DO-DELETE.
           DELETE MASTER-FILE
           GO TO READ-NEXT.
       WRAP-UP.
           CLOSE TRANS-FILE MASTER-FILE
           STOP RUN.

Exercise 5: PERFORM Structure Best Practices

Rewrite the following nested IF structure using EVALUATE, which is the preferred structured approach:

           IF WS-TRANS-TYPE = 'D'
               IF WS-AMOUNT > WS-BALANCE
                   PERFORM 3100-INSUFFICIENT-FUNDS
               ELSE
                   PERFORM 3200-PROCESS-DEBIT
               END-IF
           ELSE
               IF WS-TRANS-TYPE = 'C'
                   PERFORM 3300-PROCESS-CREDIT
               ELSE
                   IF WS-TRANS-TYPE = 'T'
                       IF WS-TRANSFER-ACCT = SPACES
                           PERFORM 3400-MISSING-ACCOUNT
                       ELSE
                           PERFORM 3500-PROCESS-TRANSFER
                       END-IF
                   ELSE
                       PERFORM 3600-INVALID-TYPE
                   END-IF
               END-IF
           END-IF

Solution:

           EVALUATE TRUE
               WHEN WS-TRANS-TYPE = 'D'
                    AND WS-AMOUNT > WS-BALANCE
                   PERFORM 3100-INSUFFICIENT-FUNDS
               WHEN WS-TRANS-TYPE = 'D'
                   PERFORM 3200-PROCESS-DEBIT
               WHEN WS-TRANS-TYPE = 'C'
                   PERFORM 3300-PROCESS-CREDIT
               WHEN WS-TRANS-TYPE = 'T'
                    AND WS-TRANSFER-ACCT = SPACES
                   PERFORM 3400-MISSING-ACCOUNT
               WHEN WS-TRANS-TYPE = 'T'
                   PERFORM 3500-PROCESS-TRANSFER
               WHEN OTHER
                   PERFORM 3600-INVALID-TYPE
           END-EVALUATE

Exercise 6: Comment Quality Assessment

Rate each of the following comments as "Useful," "Useless" (states the obvious), or "Harmful" (misleading or wrong), and explain:

a)

      * Add 1 to counter
           ADD 1 TO CT-RECORDS-READ

b)

      * Apply late payment penalty per FDIC Reg Z Section 226.5
      * Penalty is 5% of payment amount, max $50.00
           COMPUTE WS-PENALTY = WS-PAYMENT * 0.05
           IF WS-PENALTY > 50.00
               MOVE 50.00 TO WS-PENALTY
           END-IF

c)

      * Process the record
           PERFORM 2000-PROCESS-RECORD

d)

      * Calculate monthly interest (updated 2023-06-15 per CR-4521)
      * Uses simple interest: balance * (annual-rate / 12)
      * Note: compound interest calc is in INTCALC2 program
           COMPUTE WS-MONTHLY-INTEREST ROUNDED =
               WS-BALANCE * (WS-ANNUAL-RATE / 12)

Exercise 7: 88-Level Best Practices

Rewrite the following IF conditions using 88-level condition names:

       01  WS-ACCOUNT-STATUS    PIC X(1).
       01  WS-TRANS-CODE        PIC X(2).

           IF WS-ACCOUNT-STATUS = 'A'
               OR WS-ACCOUNT-STATUS = 'P'
               PERFORM 2000-PROCESS-ACTIVE
           END-IF

           IF WS-TRANS-CODE = '01'
               OR WS-TRANS-CODE = '02'
               OR WS-TRANS-CODE = '03'
               PERFORM 3000-PROCESS-DEPOSIT
           ELSE
               IF WS-TRANS-CODE = '10'
                   OR WS-TRANS-CODE = '11'
                   PERFORM 3100-PROCESS-WITHDRAWAL
               END-IF
           END-IF

Tier 2: Comprehension and Application (Exercises 8-15)

Exercise 8: Program Header Standard

Write a complete program header comment block (to be placed before the IDENTIFICATION DIVISION) that includes: - Program name and description - Author and date written - Change history with dates, change request numbers, and descriptions - Input and output files - Called programs - Business rules summary

Use a real-world scenario: a program that calculates monthly service charges on checking accounts.

Solution:

      *================================================================*
      * PROGRAM:    SVCCHARG                                           *
      * DESCRIPTION: Calculates monthly service charges on checking    *
      *              accounts based on average daily balance, number   *
      *              of transactions, and account tier.                *
      *                                                                *
      * AUTHOR:      M. Williams           DATE: 2019-03-15           *
      *                                                                *
      * INPUT FILES:                                                   *
      *   ACCTMAST - Checking account master (VSAM KSDS)             *
      *   TRANSUM  - Monthly transaction summary (sequential)         *
      *   TIERTBL  - Service charge tier table (sequential)           *
      *                                                                *
      * OUTPUT FILES:                                                  *
      *   CHRGFILE - Service charge detail (sequential)               *
      *   RPTFILE  - Service charge report (sequential)               *
      *                                                                *
      * CALLED PROGRAMS:                                               *
      *   DATEUTIL - Date calculation utilities                        *
      *   FMTUTIL  - Report formatting utilities                       *
      *                                                                *
      * BUSINESS RULES:                                                *
      *   1. Accounts with avg daily balance >= tier threshold         *
      *      receive a fee waiver                                      *
      *   2. Each transaction over the free limit incurs $0.25         *
      *   3. Minimum monthly charge is $5.00 for non-waived accts     *
      *   4. Senior accounts (type 'S') receive 50% discount          *
      *                                                                *
      * CHANGE HISTORY:                                                *
      * DATE       CR#      AUTHOR       DESCRIPTION                   *
      * ---------- -------- ------------ ----------------------------- *
      * 2019-03-15 CR-3201  M.Williams   Initial development           *
      * 2020-01-10 CR-3845  S.Chen       Added senior discount         *
      * 2021-06-22 CR-4102  M.Williams   Updated tier thresholds       *
      * 2023-09-01 CR-4789  R.Patel      Added fee waiver logic        *
      *================================================================*

Exercise 9: WORKING-STORAGE Organization

Reorganize the following chaotic WORKING-STORAGE SECTION into properly grouped and ordered sections:

       WORKING-STORAGE SECTION.
       01  AMOUNT     PIC 9(7)V99.
       01  EOF-SW     PIC X VALUE 'N'.
       01  HOLD-ACCT  PIC X(10).
       01  LINE-CT    PIC 99 VALUE 0.
       01  X          PIC 9 VALUE 0.
       01  TOTAL      PIC 9(9)V99 VALUE 0.
       01  ERR-MSG    PIC X(50).
       01  RATE       PIC 9V9999.
       01  PAGE-NUM   PIC 9(3) VALUE 0.
       01  REC-CT     PIC 9(7) VALUE 0.
       01  STATUS1    PIC XX.
       01  W-DATE     PIC X(8).
       01  BAL        PIC S9(9)V99.
       01  FOUND-SW   PIC X VALUE 'N'.
       01  ERR-CT     PIC 9(5) VALUE 0.

Exercise 10: Eliminating GO TO Statements

Rewrite the following GO TO-based program logic using structured PERFORM statements:

       0000-MAIN.
           PERFORM 1000-OPEN-FILES
           GO TO 2000-READ-FIRST.
       2000-READ-FIRST.
           READ INPUT-FILE
               AT END GO TO 9000-CLOSE-FILES
           END-READ.
       3000-PROCESS.
           IF TR-TYPE = 'H'
               GO TO 3100-PROCESS-HEADER
           END-IF
           IF TR-TYPE = 'D'
               GO TO 3200-PROCESS-DETAIL
           END-IF
           IF TR-TYPE = 'T'
               GO TO 3300-PROCESS-TRAILER
           END-IF
           DISPLAY 'UNKNOWN TYPE: ' TR-TYPE
           GO TO 4000-READ-NEXT.
       3100-PROCESS-HEADER.
           MOVE TR-BATCH-NUM TO WS-CURRENT-BATCH
           GO TO 4000-READ-NEXT.
       3200-PROCESS-DETAIL.
           ADD TR-AMOUNT TO WS-BATCH-TOTAL
           ADD 1 TO CT-DETAILS
           GO TO 4000-READ-NEXT.
       3300-PROCESS-TRAILER.
           IF WS-BATCH-TOTAL NOT = TR-CONTROL-TOTAL
               DISPLAY 'BATCH OUT OF BALANCE'
           END-IF
           MOVE 0 TO WS-BATCH-TOTAL CT-DETAILS
           GO TO 4000-READ-NEXT.
       4000-READ-NEXT.
           READ INPUT-FILE
               AT END GO TO 9000-CLOSE-FILES
           END-READ
           GO TO 3000-PROCESS.
       9000-CLOSE-FILES.
           CLOSE INPUT-FILE
           STOP RUN.

Solution:

       0000-MAIN.
           PERFORM 1000-OPEN-FILES
           PERFORM 2000-READ-INPUT
           PERFORM 3000-PROCESS-LOOP
               UNTIL FL-EOF-INPUT
           PERFORM 9000-CLOSE-FILES
           STOP RUN
           .

       1000-OPEN-FILES.
           OPEN INPUT INPUT-FILE
           .

       2000-READ-INPUT.
           READ INPUT-FILE
               AT END
                   SET FL-EOF-INPUT TO TRUE
           END-READ
           .

       3000-PROCESS-LOOP.
           EVALUATE TR-TYPE
               WHEN 'H'
                   PERFORM 3100-PROCESS-HEADER
               WHEN 'D'
                   PERFORM 3200-PROCESS-DETAIL
               WHEN 'T'
                   PERFORM 3300-PROCESS-TRAILER
               WHEN OTHER
                   DISPLAY 'UNKNOWN TYPE: ' TR-TYPE
           END-EVALUATE
           PERFORM 2000-READ-INPUT
           .

       3100-PROCESS-HEADER.
           MOVE TR-BATCH-NUM TO WS-CURRENT-BATCH
           .

       3200-PROCESS-DETAIL.
           ADD TR-AMOUNT TO WS-BATCH-TOTAL
           ADD 1 TO CT-DETAILS
           .

       3300-PROCESS-TRAILER.
           IF WS-BATCH-TOTAL NOT = TR-CONTROL-TOTAL
               DISPLAY 'BATCH OUT OF BALANCE'
           END-IF
           MOVE 0 TO WS-BATCH-TOTAL
           MOVE 0 TO CT-DETAILS
           .

       9000-CLOSE-FILES.
           CLOSE INPUT-FILE
           .

Exercise 11: Scope Terminator Enforcement

Add the missing scope terminators to the following code. Explain what incorrect behavior could result from each missing terminator.

           READ TRANS-FILE
               AT END
                   MOVE 'Y' TO WS-EOF

           IF WS-AMOUNT > 10000
               IF WS-APPROVAL-CODE = SPACES
                   DISPLAY 'LARGE TRANS NEEDS APPROVAL'
                   MOVE 'R' TO WS-STATUS
               ELSE
                   MOVE 'A' TO WS-STATUS

           COMPUTE WS-INTEREST =
               WS-BALANCE * WS-RATE / 12
               ON SIZE ERROR
                   MOVE 0 TO WS-INTEREST
                   DISPLAY 'OVERFLOW ON INTEREST CALC'

Exercise 12: Copybook Design

Design a COPY member called ACCTLYT that defines a checking account record layout. The copybook should: - Be usable in both the FILE SECTION (under an FD) and WORKING-STORAGE - Include 88-level condition names for status codes and account types - Use consistent naming with a prefix parameter that can be changed via COPY REPLACING - Include inline comments explaining each field's purpose and valid values

Exercise 13: Paragraph Size and Complexity

The following paragraph is 85 lines long and contains 7 levels of nested IF statements. Refactor it into smaller, single-purpose paragraphs, each no longer than 30 lines. Maintain the same business logic.

       3000-PROCESS-TRANSACTION.
           IF WS-ACCOUNT-STATUS = 'A'
               IF WS-TRANS-TYPE = 'D'
                   IF WS-AMOUNT > 0
                       IF WS-AMOUNT <= WS-BALANCE
                           SUBTRACT WS-AMOUNT FROM WS-BALANCE
                           ADD 1 TO CT-DEBITS
                           ADD WS-AMOUNT TO AC-TOTAL-DEBITS
                           IF WS-BALANCE < WS-MIN-BALANCE
                               MOVE 'L' TO WS-ALERT-CODE
                               ADD 1 TO CT-LOW-BALANCE
                           END-IF
                       ELSE
                           IF WS-OVERDRAFT-OK = 'Y'
                               SUBTRACT WS-AMOUNT
                                   FROM WS-BALANCE
                               ADD 25.00 TO WS-FEE-TOTAL
                               ADD 1 TO CT-OVERDRAFTS
                           ELSE
                               MOVE 'R' TO WS-RESULT-CODE
                               ADD 1 TO CT-REJECTED
                           END-IF
                       END-IF
                   ELSE
                       MOVE 'E' TO WS-RESULT-CODE
                       ADD 1 TO CT-ERRORS
                   END-IF
               ELSE
                   IF WS-TRANS-TYPE = 'C'
                       ADD WS-AMOUNT TO WS-BALANCE
                       ADD 1 TO CT-CREDITS
                       ADD WS-AMOUNT TO AC-TOTAL-CREDITS
                   ELSE
                       MOVE 'E' TO WS-RESULT-CODE
                       ADD 1 TO CT-ERRORS
                   END-IF
               END-IF
           ELSE
               MOVE 'I' TO WS-RESULT-CODE
               ADD 1 TO CT-INACTIVE
           END-IF
           .

Exercise 14: Error Handling Standards

Write a standards document section (in the form of COBOL comments) specifying the error-handling rules for a development team. Cover: - File status checking requirements - Arithmetic error handling - Subprogram return code conventions - Error logging format - Severity level definitions

Exercise 15: Code Documentation Standards

Write the paragraph-level documentation standard for the following paragraph. Include a header comment block that describes the paragraph's purpose, inputs, outputs, and any side effects:

       3500-CALCULATE-MONTHLY-PAYMENT.
           COMPUTE WS-MONTHLY-RATE =
               WS-ANNUAL-RATE / 1200
           IF WS-MONTHLY-RATE = 0
               COMPUTE WS-MONTHLY-PAYMENT =
                   WS-PRINCIPAL / WS-TERM-MONTHS
           ELSE
               COMPUTE WS-MONTHLY-PAYMENT ROUNDED =
                   WS-PRINCIPAL * WS-MONTHLY-RATE /
                   (1 - (1 + WS-MONTHLY-RATE)
                       ** (0 - WS-TERM-MONTHS))
               ON SIZE ERROR
                   MOVE 0 TO WS-MONTHLY-PAYMENT
                   MOVE 'Y' TO WS-CALC-ERROR-FLAG
           END-COMPUTE
           END-IF
           .

Tier 3: Analysis and Problem Solving (Exercises 16-22)

Exercise 16: Code Review Checklist

Create a comprehensive code review checklist for COBOL programs. The checklist should have sections for: - Naming conventions (at least 8 items) - Program structure (at least 6 items) - Data definitions (at least 8 items) - Error handling (at least 6 items) - Performance (at least 4 items) - Documentation (at least 5 items)

For each item, specify whether it is Critical (must fix before production), Important (should fix), or Advisory (nice to have).

Exercise 17: Anti-Pattern Identification

Identify and explain the problems with each of the following COBOL anti-patterns. For each one, provide the corrected code.

a) The "Magic Number" anti-pattern:

           IF WS-BALANCE < 500
               ADD 25.00 TO WS-FEES
           END-IF
           IF CT-TRANSACTIONS > 20
               COMPUTE WS-EXCESS-FEE =
                   (CT-TRANSACTIONS - 20) * 0.35
           END-IF

b) The "God Paragraph" anti-pattern (a single paragraph that does everything):

       0000-MAIN.
           OPEN INPUT TRANS-FILE
           OPEN I-O MASTER-FILE
           READ TRANS-FILE AT END MOVE 'Y' TO WS-EOF END-READ
           PERFORM UNTIL WS-EOF = 'Y'
               MOVE TR-KEY TO MR-KEY
               READ MASTER-FILE
                   INVALID KEY DISPLAY 'NOT FOUND'
               END-READ
               ADD TR-AMOUNT TO MR-BALANCE
               REWRITE MASTER-RECORD
               READ TRANS-FILE AT END MOVE 'Y' TO WS-EOF
               END-READ
           END-PERFORM
           CLOSE TRANS-FILE MASTER-FILE
           STOP RUN.

c) The "Dead Code" anti-pattern:

           MOVE 'A' TO WS-STATUS
      *    MOVE 'P' TO WS-STATUS
           IF WS-STATUS = 'A'
               PERFORM 3000-PROCESS
           END-IF
      *    IF WS-STATUS = 'P'
      *        PERFORM 3100-PENDING
      *    END-IF
           IF WS-STATUS = 'X'
               PERFORM 3200-SPECIAL
           END-IF

Exercise 18: PERFORM THRU Evaluation

Your team is debating whether to allow PERFORM ... THRU in new code. Write a position paper (as COBOL comments, 20-30 lines) arguing for OR against PERFORM THRU, with specific examples of the risks and benefits.

Exercise 19: Naming Convention Design

Design a complete naming convention system for a bank's COBOL development team. Cover: - WORKING-STORAGE prefixes (at least 12 categories) - Paragraph naming and numbering scheme - File and record naming - Copybook naming - Program naming (8-character limit) - Condition name (88-level) naming

Include a reference table that developers can print and keep at their desks.

Exercise 20: Legacy Code Assessment

Assess the following legacy code fragment on a scale of 1-10 for maintainability. Identify every violation of modern coding standards and estimate the effort (in hours) to bring it up to standard:

       01  A         PIC X(80).
       01  B         PIC X(80).
       01  C         PIC 9(7)V99.
       01  D         PIC 9(7)V99.
       01  E         PIC 9(5).
       01  F         PIC X.
       01  G         PIC X(10).

       P1.
           OPEN INPUT FI OPEN OUTPUT FO.
           READ FI INTO A AT END GO TO P9 END-READ.
       P2.
           IF A(1:2) = '01' GO TO P3.
           IF A(1:2) = '02' GO TO P4.
           GO TO P5.
       P3.
           MOVE A(3:10) TO G.
           MOVE 0 TO C D E. GO TO P6.
       P4.
           ADD 1 TO E.
           MOVE A(13:9) TO C.
           ADD C TO D. GO TO P6.
       P5.
           MOVE 'E' TO F. DISPLAY 'BAD REC ' A. GO TO P6.
       P6.
           READ FI INTO A AT END GO TO P7 END-READ. GO TO P2.
       P7.
           DISPLAY G ' TOTAL=' D ' COUNT=' E.
       P8.
           WRITE B FROM A. GO TO P9.
       P9.
           CLOSE FI FO. STOP RUN.

Exercise 21: INITIALIZE vs MOVE SPACES/ZEROS

Explain the difference between the following initialization approaches and when each is appropriate:

       01  WS-CUSTOMER-REC.
           05  WS-CUST-NAME      PIC X(30).
           05  WS-CUST-BALANCE   PIC S9(9)V99 COMP-3.
           05  WS-CUST-STATUS    PIC X.
           05  WS-CUST-COUNT     PIC 9(5) COMP.

      * Approach 1:
           INITIALIZE WS-CUSTOMER-REC

      * Approach 2:
           MOVE SPACES TO WS-CUSTOMER-REC

      * Approach 3:
           MOVE SPACES TO WS-CUST-NAME
           MOVE ZEROS  TO WS-CUST-BALANCE
           MOVE SPACE  TO WS-CUST-STATUS
           MOVE ZEROS  TO WS-CUST-COUNT

Exercise 22: Testing Standards

Define unit testing standards for COBOL programs. Your standards should specify: - How test data should be prepared - What boundary conditions must be tested for financial calculations - How test results should be documented - What coverage metrics are required - How regression tests should be maintained


Tier 4: Synthesis and Design (Exercises 23-28)

Exercise 23: Standards Enforcement Tool

Design a COBOL source code analyzer (described in pseudocode or COBOL) that reads a COBOL source file and checks for violations of the naming conventions, structural standards, and documentation requirements defined in this chapter. The analyzer should:

  1. Check that all WORKING-STORAGE variables have standard prefixes
  2. Verify that paragraphs are numbered in order
  3. Flag GO TO statements
  4. Check that every paragraph has a header comment
  5. Flag numeric literals in the PROCEDURE DIVISION (magic numbers)
  6. Report violations with line numbers and severity ratings

Hint: Read the source file as 80-character records. Parse column 7 for indicators, columns 8-72 for source, and use STRING/UNSTRING to extract tokens.

Exercise 24: Coding Standards Document

Write a complete COBOL coding standards document for a banking IT department. The document should be structured as a COBOL copybook (comment block) that can be included at the top of every program via COPY. It should cover all topics from this chapter in a concise, actionable format.

Hint: Organize the document into sections: Naming, Structure, Data, Error Handling, Documentation, Performance. Use numbered rules (e.g., "RULE-N01: All WORKING-STORAGE variables must have a standard prefix"). Keep each rule to 2-3 lines maximum.

Exercise 25: Refactoring Plan

Given a 5,000-line COBOL program with the following problems, create a prioritized refactoring plan: - 47 GO TO statements - No file status checking - Single-character variable names in 12 locations - No paragraph-level comments - Three 200+ line paragraphs - No 88-level conditions (uses literal comparisons everywhere) - Mixed COMP and COMP-3 usage without clear reason - PERFORM THRU used in 8 locations

For each refactoring task, specify: priority (1-5), estimated effort (hours), risk level, and testing requirements.

Hint: Prioritize changes that reduce the risk of production errors (file status checking, error handling) over cosmetic changes (naming, comments). Group related changes to minimize testing cycles.

Exercise 26: Cross-Platform Standards

Design coding standards that work for COBOL programs targeting both IBM z/OS (Enterprise COBOL) and GnuCOBOL on Linux. Address the areas where the two platforms differ: - Column format (fixed vs free) - Compiler directives - File handling (DD names vs file paths) - EBCDIC vs ASCII considerations - COMP field sizes - Debugging techniques

Hint: The key is to abstract platform-specific elements into COPY members and compiler option files, keeping the main program source portable. Use conditional compilation where available.

Exercise 27: Pair Programming Exercise

Design a pair programming exercise for two COBOL developers. Developer A writes a program intentionally violating 15 specific coding standards. Developer B must find all 15 violations during a code review session. Create both the "bad" program and the answer key listing all violations.

Hint: Include a mix of obvious violations (GO TO, missing error handling) and subtle ones (group MOVE to numeric field, PERFORM THRU with fall-through logic, uninitialized accumulator).

Exercise 28: Standards Evolution

A bank's COBOL coding standards were last updated in 2005. Write a proposal for updating them to incorporate modern practices available in Enterprise COBOL V6. Address:

  • EVALUATE TRUE vs nested IF
  • Inline PERFORM
  • Reference modification vs STRING/UNSTRING
  • FUNCTION CURRENT-DATE vs ACCEPT FROM DATE
  • END-verb scope terminators
  • XML and JSON PARSE (COBOL V6 features)
  • UTF-8 and Unicode support
  • Object-oriented COBOL features

For each practice, state whether it should be Required, Recommended, Optional, or Prohibited, with justification.

Hint: Not all new features are improvements for enterprise COBOL. Object-oriented COBOL, for instance, is rarely used in production mainframe environments and may not be appropriate to require.


Tier 5: Enterprise Integration Challenges (Exercises 29-35)

Exercise 29: Multi-Team Standards Governance

A large bank has 12 COBOL development teams across three sites. Each team has evolved its own coding standards over the past 20 years. Design a governance process to:

  1. Assess the current state of standards across all teams
  2. Develop a unified set of standards
  3. Migrate existing programs incrementally
  4. Enforce standards on new development
  5. Handle exceptions and waivers
  6. Measure compliance over time

Provide the governance charter, the assessment questionnaire, and the migration strategy.

Hint: Do not try to convert all existing code at once. Apply standards to new code and to any existing code that is modified. Track compliance as a percentage of recently-modified programs that pass the standards checker.

Exercise 30: Legacy Modernization Assessment

You are given a portfolio of 800 COBOL programs, totaling 2.4 million lines of code. The programs range in age from 5 years to 35 years. Create a scoring rubric that rates each program on a 1-100 maintainability scale based on:

  • Code structure (GO TO usage, paragraph size, nesting depth)
  • Naming quality (meaningful names, prefix usage, abbreviation consistency)
  • Documentation (header blocks, paragraph comments, inline comments)
  • Error handling (file status checking, arithmetic protection, return codes)
  • Data design (COPY member usage, 88-levels, proper USAGE clauses)

Design the rubric so that it can be automated (parsed by a tool reading the source file). Provide the scoring weights and threshold definitions for each category.

Hint: A simple approach is to assign positive and negative points per source line or per paragraph. For example: +1 for each paragraph with a comment header, -2 for each GO TO, +1 for each FILE STATUS clause, -1 for each single-character variable name. Normalize to 0-100.

Exercise 31: Standards-Compliant Program Template

Create a complete COBOL program template that new developers can copy as a starting point for any batch processing program. The template should include:

  • All four divisions with standard boilerplate
  • Standard file handling with file status checking
  • Main processing loop using structured PERFORM
  • Error handling framework
  • Standard WORKING-STORAGE organization
  • Placeholder paragraphs with documentation standards
  • Standard processing statistics and return code setting

The template should compile and run (processing zero records) without modification.

Exercise 32: Code Metrics Dashboard

Design a COBOL code quality metrics dashboard that management can review monthly. Define: - 8-10 key metrics (e.g., average paragraph length, GO TO density, comment ratio) - Threshold values for "green" (healthy), "yellow" (warning), and "red" (critical) - Trend indicators (improving, stable, degrading) - How to collect the metrics automatically from source libraries

Hint: Metrics that can be collected automatically include: lines of code per paragraph, percentage of programs with FILE STATUS on all files, percentage of GO TO-free programs, ratio of comment lines to code lines, percentage of programs using COPY members for shared layouts.

Exercise 33: Teaching Legacy Developers New Standards

A team of 8 experienced COBOL developers (average 20 years of experience) has been writing code using 1980s-era conventions. They resist changing their coding style. Design a training and change management program that:

  1. Acknowledges and respects their experience
  2. Demonstrates concrete benefits of modern standards (fewer production abends, faster onboarding)
  3. Provides hands-on exercises converting familiar code patterns
  4. Gradually introduces new practices over 6 months
  5. Uses code review as a coaching tool rather than a punitive mechanism

Outline the 6-month plan with monthly milestones and specific exercises for each month.

Hint: Start with changes that have immediate, visible benefits -- like file status checking (prevents abends) and EVALUATE (reduces nesting). Save cosmetic changes like naming conventions for later, when trust has been established.

Exercise 34: Automated Code Formatter

Design the specification for a COBOL source code formatter that automatically: 1. Aligns columns (PICTURE clauses, VALUE clauses) 2. Standardizes indentation within IF/EVALUATE/PERFORM blocks 3. Enforces consistent spacing around operators 4. Adds missing scope terminators 5. Reformats continuation lines

Define the formatting rules, provide before/after examples, and discuss the risks of automated formatting in COBOL (where column position matters).

Hint: The biggest risk is breaking column 72 boundaries. Any formatter must ensure that no source code extends beyond column 72 (for fixed-format COBOL). Continuation lines (hyphen in column 7) require special handling.

Exercise 35: Standards for AI-Generated COBOL

As AI coding assistants become more common, developers may use them to generate COBOL code. Write a set of guidelines for reviewing AI-generated COBOL code. Address: - Common patterns that AI gets wrong in COBOL (column positioning, COMP-3 arithmetic, EBCDIC assumptions) - Verification steps before accepting AI-generated code - Standards compliance checking - Test requirements for AI-generated code vs human-written code - Documentation requirements (attribution, review attestation)

Hint: AI-generated COBOL often uses modern syntax (free-format, long identifiers) that may not compile on older mainframe compilers. It may also generate semantically correct but non-idiomatic code that confuses experienced COBOL developers.