COBOL-to-Java Converter: Side-by-Side Code Comparison

SoftwareMining's automated, rule-based COBOL-to-Java Translation Toolkit converts enterprise COBOL applications into maintainable Java source code. This page compares a small COBOL program with the corresponding Java code generated by the translator.

The comparison shows how COBOL business logic, data definitions and program flow are represented in readable, object-oriented Java code. For a complete application, the translated system should be validated against the original COBOL application through functional-equivalence testing .



Download COBOL-to-Java and C# Conversion Toolkit | Free Evaluation

This introductory comparison focuses on the readability and structure of the generated code. Complete enterprise conversions must also address advanced COBOL requirements such as GO TO control flow, dead-code analysis, REDEFINES, CICS integration and pointer handling.

For detailed coverage of supported COBOL language constructs, platform technologies, data handling and translation patterns, see the Enterprise COBOL-to-Java Translator Feature List .

Key COBOL-to-Java Conversion Features

  1. COBOL 01-level data declarations are converted into generated Data Access Object (DAO) classes that preserve COBOL structures such as REDEFINES, computational fields and OCCURS DEPENDING ON (see the WS-DATA structure below).
  2. COBOL 01-level record definitions in the FILE SECTION are converted into Object-Relational Mapping (ORM) classes for use by the translated Java application.
  3. COBOL 01-level WORKING-STORAGE definitions used as record areas by CICS READ and WRITE commands are also converted into ORM classes.
  4. Unreferenced 01-level declarations are automatically commented out in the generated code, reducing unnecessary clutter while retaining the original definitions for reference.
  5. The translator avoids generating unused DAO references and reuses shared data structures where possible, reducing duplication in the generated code.
  6. GO TO control flow is converted into structured IF, switch and loop constructs where practical. More complex irreducible paths are preserved through controlled patterns supported by the SoftwareMining Framework libraries.
  7. Translated batch programs can be executed from the command line or integrated with enterprise job schedulers. Supported JCL can also be converted into Unix shell scripts or Windows batch files .
  8. Translated online applications can be deployed on Java application servers such as Apache Tomcat, Jakarta EE servers, or Spring-based environments and integrated with standard enterprise database, messaging and security services.

COBOL to Java: Side-by-Side Code Comparison

  PROGRAM-ID. LOAN.
  DATA DIVISION.
  FILE SECTION.

  WORKING-STORAGE SECTION.
  01  WS-DATA.
    05 PRINCIPAL          PIC 9(9) VALUE 0.
    05 INTEREST-RATE      PIC 99V99 VALUE 0.
    05 LOAN-LENGTH        PIC 99 VALUE 0.
    05 NEXT-INTEREST      PIC 99V99.
    05 NEXT-YEAR          PIC 99.
  01 CLIENT-RECORD.
    05 NAME               PIC X(20).
    05 ADDRESS            PIC X(20) OCCURS 3 TIMES.
    05 ID                 PIC 9(4) COMP.

  ...
// Sample COBOL to Java translated code

public class Loan extends BaseService  {
  
// Notes: 01 level WS-DATA name is simplified (Optional)
// and converted to a DAO
// The DAO handles REDEFINES, COMP, OCCURS-DEPENDING, ...
  
  private WsData data = new WsData(this);
  
// Client-RECORD has been translated to ClientRecord DAO,
// but since the program does not reference ClientRecord,
// it will automatically be commented out.
  
  
// private ClientRecord clientRecord = new ClientRecord(this);
  
  ...
  * Main entry point to program
   LOAN-MAIN-001.

  *  -
  * CLEAR SCREEN AND READ DATA
  *  -

       IF LOAN-LENGTH > 4 THEN
          COMPUTE START-YEAR = LOAN-LENGTH - 4
       ELSE
          COMPUTE START-YEAR = 0.

       IF INTEREST-RATE > 0.4 THEN
          COMPUTE START-INTEREST = INTEREST-RATE - 0.4
       ELSE
          COMPUTE START-INTEREST = 0
       END-IF

       MOVE 1 TO YEAR-ROW.

  *  -
  * GO THRU THE NUMBER OF YEARS
  *  -

       MOVE "% Rate->" TO DSP-NO-YRS(1).
       MOVE START-YEAR TO NEXT-YEAR
       PERFORM VARYING YEAR-ROW FROM 2 BY 1 UNTIL YEAR-ROW = 11
         PERFORM DO-NEXT-ROW
         ADD 1 TO NEXT-YEAR
       END-PERFORM.

  *  -
  *  AND EXIT
  *  -
       STOP RUN.
/**
 * Main entrance to program
 */
protected void loanMain () {
  //  -
  // CLEAR SCREEN AND READ DATA
  //  -
  if (data.getLoanLength() > 4) {
    data.setStartYear(data.getLoanLength() - 4);
  } else {
    data.setStartYear(0);
  }
  if (data.getInterestRate() > 0.4) {
    data.setStartInterest(data.getInterestRate() - 0.4);
  } else {
    data.setStartInterest(0.0);
  }
  data.setYearRow(1);

  //  -
  // GO THRU THE NUMBER OF YEARS
  //  -
  displayResult.setNoYrs(0, "% Rate->");
  data.setNextYear(data.getStartYear());
  // initialize loop variable
  data.setYearRow(2);
  while (data.getYearRow() != 11) {
    doNextRow();
    data.setNextYear(data.getNextYear() + 1);
    data.setYearRow(data.getYearRow() + 1);
  }

  //  -
  // AND EXIT
  //  -
  stop();
}
  *
  * Calculates values for individual rows
  *
   DO-NEXT-ROW.

       MOVE START-INTEREST TO NEXT-INTEREST

       PERFORM VARYING INTEREST-COL FROM 1 BY 1
         UNTIL INTEREST-COL = 10
         MOVE NEXT-INTEREST TO DSP-RESULT(1, INTEREST-COL)
         PERFORM CALCULATE
         MOVE NEXT-RESULT TO DSP-RESULT(YEAR-ROW, INTEREST-COL)
         ADD 0.1 TO NEXT-INTEREST
       END-PERFORM.
/**
 * Calculates values for individual rows
 */
protected void doNextRow () {
  data.setNextInterest(data.getStartInterest());

  data.setInterestCol(1);
  while (data.getInterestCol() != 10) {
    displayResult.setResult(
      0,
      data.getInterestCol() - 1,
      data.getNextInterest()
    );
    calculate();
    displayResult.setResult(
      data.getYearRow() - 1,
      data.getInterestCol() - 1,
      data.getNextResult()
    );
    data.setNextInterest(data.getNextInterest() + 0.1);
    data.setInterestCol(data.getInterestCol() + 1);
  }
}
  *
  * The next paragraph calculates CELL values
  *
   CALCULATE.
       COMPUTE INTDEC = NEXT-INTEREST / (12.0 * 100.0)
       COMPUTE NUMMONTHS = NEXT-YEAR * 12.0
       ...
/**
 * The next paragraph calculates CELL values
 */
protected void calculate () {
  data.setIntdec(data.getNextInterest() / (12.0 * 100.0));
  data.setNummonths((double) data.getNextYear() * 12.0);
  ...
}

Run the Converted Java Version of AWS CardDemo