Comparison of Code Generated by SoftwareMining's COBOL to C# Converter

This page presents a side-by-side comparison between a small COBOL program and the equivalent C# code produced by SoftwareMining's COBOL to C# Converter and Refactoring Tool. It highlights how business logic and data structures are preserved while generating modern, maintainable, and object-oriented code.


Download COBOL Converter Free Trial


COBOL to C# Success Stories

The goal of this example is to demonstrate the readability, maintainability, and structural clarity of the translated code. This simple example does not attempt to show advanced features such as the removal of GO TO statements, dead-code elimination, handling of REDEFINEs, CICS integration, or pointer translation.

For details on how these advanced cases are handled, see our comprehensive guide: COBOL to Java / C# Conversion FAQ for C# Projects .

Key Features and Enhancements in COBOL to C# Conversion

  1. 01-level COBOL declarations are converted into Data Access Objects (DAO) capable of handling REDEFINES, COMPUTATIONAL, OCCURS-DEPENDING, and other COBOL data features (see the WS-DATA structure).
  2. 01-level declarations in the FILE SECTION are translated into Object Relational Model (ORM) classes.
  3. 01-level WORKING-STORAGE definitions used in CICS READ / WRITE statements are also converted into ORM classes.
  4. Unreferenced 01-level declarations are automatically commented out to keep the generated code clean.
  5. The translator removes references to unused DAOs and reuses shared structures where possible.
  6. Many GO TO statements are removed automatically; remaining ones are supported through the SoftwareMining Framework libraries.
  7. Batch programs: The translated C# code can be executed from the command line or through Unix Shell scripts translated from JCL.
  8. Online applications: The translated C# system can be deployed on Application servers such as Microsoft IIS.

COBOL to C#: Side-by-Side Code Comparison

  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 C# translated code
namespace Softwaremining.Cobol2CSharp.Example
{
 public sealed class Loan : BaseService {
  
// Note: 01 level WS-VARS name is simplified (Optional)
// and converted to a DAO
// The DAO handles REDEFINES, COMP, OCCURS-DEPENDING, ...
  
  private Vars ;
  
// 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;
  
  ...
  /// constructor
  public Loan(BaseService parent) : base(parent)
  {
    vars = new Vars(this);
    // 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.
/// <summary>
/// Main entrance to program
/// </summary>
protected void LoanMain ()
{
  
  //  -
  // CLEAR SCREEN AND READ DATA
  //  -
  
  if (vars.LoanLength > 4)
  {
    vars.StartYear = vars.LoanLength - 4;
  }
  else
  {
    vars.StartYear = 0;
  }

  if (vars.InterestRate > 0.4)
  {
    vars.StartInterest = vars.InterestRate - 0.4;
  }
  else
  {
    vars.StartInterest = 0;
  }

  vars.YearRow = 1;
  vars.setYearRow(1);

  
  //  -
  // GO THRU THE NUMBER OF YEARS
  //  -
  
  displayResult.SetNoYrs(0, "% Rate->");
  vars.NextYear = vars.StartYear;
  vars.YearRow = 2;

  while (vars.YearRow != 11)
  {
    DoNextRow();
    vars.NextYear = vars.NextYear + 1;
    vars.YearRow = vars.YearRow + 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.
/// <summary>
/// Calculates values for individual rows
/// </summary>
protected void DoNextRow ()
{
  vars.NextInterest = vars.StartInterest;

  vars.InterestCol = 1;

  while (vars.InterestCol != 10)
  {
    displayResult.SetResult(
      0,
      vars.InterestCol - 1,
      vars.NextInterest
    );
    Calculate();
    displayResult.SetResult(
      vars.YearRow - 1,
      vars.InterestCol - 1,
      vars.NextResult
    );
    vars.NextInterest = vars.NextInterest + 0.1;
    vars.InterestCol = vars.InterestCol + 1;
  }
}
  *
  * The next paragraph calculates CELL values
  *
   CALCULATE.
       COMPUTE INTDEC = NEXT-INTEREST / (12.0 * 100.0)
       COMPUTE NUMMONTHS = NEXT-YEAR * 12.0
       ...
/// <summary>
/// The next paragraph calculates CELL values
/// </summary>
protected void Calculate ()
{
  vars.Intdec = vars.NextInterest / (12.0 * 100.0);
  vars.Nummonths = (int)((double)vars.NextYear * 12.0);
  ...
}



  © 2025 SoftwareMining is a trademark of Software Modernization Technologies Ltd (UK). Registered in England company no: 07300248. Reg Offices: 79 Stevens House, Jerome Place, Kingston Upon Thames, KT1 1HX, United Kingdom.