TExcelTAD
Home › COBOL › COBOL Modernisation

COBOL Modernisation

Organisations that depend on COBOL face a familiar set of questions: the code works and is fast, but it is old, the people who wrote it are retiring, and the business wants web APIs, mobile apps and cloud deployment. "Modernising" COBOL can mean very different things, from improving the code you have to replacing the whole system.

The main strategies

Strategy What happens Risk Typical effort
Refactor in place Clean up and restructure the COBOL, add tests, keep the platform Low Ongoing
Wrap / expose Keep the COBOL, put APIs (REST, MQ, events) in front of it Low–medium Months
Rehost ("lift and shift") Recompile the COBOL for Linux/cloud (Micro Focus, GnuCOBOL, emulators) Medium Months–years
Convert Automatically translate COBOL to Java or C# Medium–high Years
Rewrite / replace Build or buy a new system and migrate the data High Years

Many failed replacement projects have taught the industry to prefer incremental change: wrap the core, strangle it piece by piece behind APIs, and keep the decimal-exact business rules running while you do.

Writing modern COBOL

Even without changing the platform, a lot can be improved in the code itself:

  • Use END-IF, END-PERFORM, EVALUATE and inline PERFORM instead of periods and GO TO.
  • Give names meaning, and use level-88 condition names instead of magic codes.
  • One paragraph, one job; keep paragraphs short.
  • Use intrinsic functions (TRIM, NUMVAL, date functions) instead of hand-written loops.
  • Put shared layouts in copybooks and check FILE STATUS and SQLCODE everywhere.
  • Add automated tests (IBM's zUnit, the open-source COBOL Check, or GnuCOBOL test drivers).

Compare a legacy paragraph with its refactored version:

cobol
      *> Legacy style
       200-CALC.
           IF WS-TYPE = 'G' GO TO 210-GOLD.
           IF WS-TYPE = 'S' GO TO 220-SILVER.
           MOVE 0 TO WS-DISC. GO TO 290-EXIT.
       210-GOLD.
           MOVE 15 TO WS-DISC. GO TO 290-EXIT.
       220-SILVER.
           MOVE 10 TO WS-DISC.
       290-EXIT.
           EXIT.
cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. MODERN-STYLE.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-CUSTOMER-TYPE       PIC X.
           88  GOLD-CUSTOMER                  VALUE "G".
           88  SILVER-CUSTOMER                VALUE "S".
       01  WS-DISCOUNT-PCT        PIC 99.
       01  WS-TYPES               PIC X(3)    VALUE "GSB".
       01  WS-I                   PIC 9.
       PROCEDURE DIVISION.
           PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 3
               MOVE WS-TYPES (WS-I:1) TO WS-CUSTOMER-TYPE
               PERFORM CALCULATE-DISCOUNT
               DISPLAY "Type " WS-CUSTOMER-TYPE ": "
                       WS-DISCOUNT-PCT "% discount"
           END-PERFORM
           GOBACK.

       CALCULATE-DISCOUNT.
           EVALUATE TRUE
               WHEN GOLD-CUSTOMER     MOVE 15 TO WS-DISCOUNT-PCT
               WHEN SILVER-CUSTOMER   MOVE 10 TO WS-DISCOUNT-PCT
               WHEN OTHER             MOVE 0  TO WS-DISCOUNT-PCT
           END-EVALUATE.
Type G: 15% discount
Type S: 10% discount
Type B: 00% discount

Exposing COBOL as a service

A common first step is to put a modern interface in front of an existing program. On z/OS, z/OS Connect maps a REST/JSON request onto a CICS program's COMMAREA; on Linux, a small web service can CALL a GnuCOBOL module. The COBOL side stays a plain subprogram with a request/response layout:

cobol
       LINKAGE SECTION.
       01  BALANCE-REQUEST.
           05  REQ-ACCOUNT-ID         PIC X(10).
       01  BALANCE-RESPONSE.
           05  RSP-STATUS             PIC XX.
           05  RSP-BALANCE            PIC S9(9)V99 COMP-3.
       PROCEDURE DIVISION USING BALANCE-REQUEST BALANCE-RESPONSE.

COBOL 2014 compilers (Enterprise COBOL 6, GnuCOBOL with extensions) can also produce and parse JSON and XML directly with JSON GENERATE/JSON PARSE and XML GENERATE/XML PARSE, so the program can speak the API's format itself. Where those statements are not available, the text can be built with STRING:

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. JSON-BY-HAND.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-ACCOUNT-ID          PIC X(10)   VALUE "ACC-0042".
       01  WS-BALANCE             PIC S9(7)V99 VALUE 1520.75.
       01  WS-BALANCE-TEXT        PIC -(7)9.99.
       01  WS-JSON                PIC X(80)   VALUE SPACES.
       PROCEDURE DIVISION.
           MOVE WS-BALANCE TO WS-BALANCE-TEXT
           STRING '{"account":"'           DELIMITED BY SIZE
                  WS-ACCOUNT-ID            DELIMITED BY SPACE
                  '","balance":'           DELIMITED BY SIZE
                  FUNCTION TRIM(WS-BALANCE-TEXT) DELIMITED BY SIZE
                  ',"currency":"EUR"}'     DELIMITED BY SIZE
               INTO WS-JSON
           END-STRING
           DISPLAY FUNCTION TRIM(WS-JSON)
           STOP RUN.
{"account":"ACC-0042","balance":1520.75,"currency":"EUR"}

DevOps for COBOL

Modern mainframe shops use the same practices as everyone else:

  • Source in Git instead of only in PDS libraries, with pull requests and code review.
  • Builds and deployments in pipelines (Jenkins, GitLab CI, GitHub Actions) using tools like IBM Dependency Based Build and Zowe CLI to talk to the mainframe.
  • VS Code with COBOL language support, linting and debugging.
  • Automated unit and regression tests run on every change.
bash
# Example: a CI job compiling and testing COBOL on Linux with GnuCOBOL
cobc -x -Wall -o build/payroll src/payroll.cob src/calctax.cob
./build/payroll < test/input.txt > build/actual.txt
diff test/expected.txt build/actual.txt

Why COBOL skills still matter

Billions of lines of COBOL still run critical systems, and most modernisation projects need people who can read the existing code and understand its business rules, the PICTURE clauses, the decimal arithmetic and the batch flow. Knowing COBOL and modern tools is a rare and valued combination.

Test yourself

Which modernisation strategy keeps the COBOL code but adds REST APIs in front of it?

  1. Rewrite
  2. Wrap / expose
  3. Convert
  4. Rehost

Which change best modernises a paragraph full of GO TO jumps?

  1. Add more periods
  2. Replace it with EVALUATE, level-88 names and PERFORM
  3. Convert it to COMP-3
  4. Move it to a copybook

What does 'rehosting' a COBOL application mean?

  1. Rewriting it in Java
  2. Recompiling and running the COBOL on another platform such as Linux or the cloud
  3. Adding a web front end
  4. Moving it to a new mainframe