SoftwareMining
Simple, Safe & Effective COBOL to Java / C#


COBOL to Java Sample: Comparing COBOL to Converted Code


The following shows the translation of a small COBOL program to Java using SoftwareMining migration tools. This is a simple example, and does not show removal of GO TO statements, removal of dead code, code reuse strategies, or ....
Noteworthy issue:
For a more detailed list of translation features please see 16 Translator features Essential for successful COBOL to Java projects.
   
  PROGRAM-ID. LOAN.
  DATA DIVISION.
  FILE SECTION.

  WORKING-STORAGE SECTION.
  01  WS-VARS.
    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-VARS name is simplified (Optional) 
  // and converted to a DAO
  // The DAO handles REDEFINES, COMP, OCCURS-DEPENDING, ... 
  private Vars vars = new Vars(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 (vars.getLoanLength() > 4) {
     vars.setStartYear(vars.getLoanLength() - 4);
   } else {
     vars.setStartYear(0);
   }
   if (vars.getInterestRate() > 0.4) {
     vars.setStartInterest(vars.getInterestRate() - 0.4);
   } else {
     vars.setStartInterest(0.0);
   }
   vars.setYearRow(1);
   //   - 
   //  GO THRU THE NUMBER OF YEARS 
   //   - 
   displayResult.setNoYrs(0, "% Rate->");
   vars.setNextYear(vars.getStartYear());
   // initialise loop variable 
   vars.setYearRow(2);
   while (vars.getYearRow() != 11) {
     doNextRow ();
     vars.setNextYear(vars.getNextYear() + 1);
     vars.setYearRow(vars.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 () {
   vars.setNextInterest(vars.getStartInterest());
   
   vars.setInterestCol(1);
   while (vars.getInterestCol() != 10) {
     displayResult.setResult(0, vars.getInterestCol() - 1
	    , vars.getNextInterest());
     calculate();
     displayResult.setResult(vars.getYearRow() - 1
		    , vars.getInterestCol() - 1, vars.getNextResult());
     vars.setNextInterest(vars.getNextInterest() + 0.1);
     vars.setInterestCol(vars.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 () {
   vars.setIntdec(vars.getNextInterest() / (12.0 * 100.0));
   vars.setNummonths((double)vars.getNextYear() * 12.0);
   ...
 }
 


                       



  © 2017, SoftwareMining Technologies. All Rights Reserved. "SoftwareMining Technologies" is a trademark of Software Modernization Technologies Ltd (UK). Software Modernization Technologies Ltd. Registered in England company no: 7300248. Reg Offices: 8b Accommodation Road, London NW11 8ED, United Kingdom.