Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » COBOL.NET » Converting C# to COBOL

Converting C# to COBOL

. This article is intended to be used as a model for you to follow when you run into a C# example and need to convert it to COBOL.

Page Views : 3676
Downloads : 40
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
SyntaxDiagram.zip
 
 
DevExpress Free UI Controls
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Description

I did a previous article, (August 22, 2009) on converting the many C# examples to COBOL. At the time there were a few examples out in the world of how to perform this conversion. Since that article has been written more and more examples have been popping up.

In this article I'd like to introduce you to a co-worker of mine who has presented what I believe to be the ultimate wall chart. This article is intended to be used as a model for you to follow when you run into a C# example and need to convert it to COBOL.

Visual COBOL!

I recently published a blog about a new product being introduced by Micro Focus called 'Visual COBOL'. Visual COBOL will be a whole new product from Micro Focus, not a rebranded current version of one of the compilers. Visual COBOL will have new syntax available that will make coding COBOL in the .NET environment much simpler and stream lined. In my previous article I proposed creating two projects, one in COBOL and the other in either C# or VB.NET. This was to enable you to learn the art of utilizing, and hopefully understanding, the realm of .NET namespaces and classes. By using the other .NET languages you could see how the syntax was composed and then translate that into COBOL. I used this method because there was no really good reference material out there at the time.

Well guess what...someone created what I believe is the ultimate syntax example. A while ago I was in Newbury at our headquarters testing the latest release of Visual COBOL. I had the pleasure of meeting some very talented developers. One of them, Dr. Alex Turner, had mentioned he composed a chart showing the syntactical differences between C#, VB.NET and COBOL. NET. My initial thought was that's cool, a couple more examples that we can use and blog about. Man was I ever wrong! Alex, I publicly apologize for underestimating your resourcefulness!

Syntactical Differences, or the "Mother of all Syntax Charts"

Below is an example of the type of information Alex has composed in his chart.


Image01.jpg
 
If you'll notice on the chart there are three columns, one each for VB.NET, C# and COBOL. Alex has created one of the most in-depth, detailed charts of syntactical comparison for .NET that I have ever seen. Maybe these exist somewhere in the wide open internet but I doubt they exist with a COBOL version!
Alex has identified over 19 different areas for comparison, ranging from the basic program structure, to arrays, properties, enumerations and other key elements of .NET programming. From his chart you should be able to identify the basic constructs of a statement, be able to replicate that statement in your environment and finally expand upon what has been presented to further your coding.

As this topic has already been discussed I won't delve further. The intent of the article was to present updated material to you to keep you informed and hopefully make your task(s) easier to complete. The complete chart Alex has prepared is attached in the zip file. Please feel free to print and reference as necessary. It's become one of the key documents on my desk.

Wrap-Up

Micro Focus is continually expanding the breadth and depth of the COBOL language in the .NET environment. New syntax and expanded classes are being exposed and enhanced. While this article was short in nature it's intent, as with all the articles, is to provide you the reader with access to current and relevant information about developing with COBOL in the .NET environment. If you have any examples or questions please feel free to email me. As always...
Happy Coding!

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Rick Malek
Rick Malek is a Solutions Engineer with Micro Focus based in Minot, North Dakota. While his primary duties are pre-sales support, Rick is also a member of the Microsoft .NET overlay team to assist the field with COBOL and .NET integration. He has worked with COBOL since 1984, originally working on an IBM mainframe with CICS, VSAM and DB2.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
Nice article. A few comments/corrections ... by Matthew On March 19, 2010

I'm always in favor of converting C# to COBOL. Your zip file should make for hours of good
coding entertainment.

The $set ilusing directive is a nice trick. I also just saw Michael Bleistein's excellent article
about COBOL's alternative methods for referencing types -- namely the ilusing directive,
repository declarations, and the type keyword.

I'd lightly rework the sample code as follows. The changes here are to:

  • add some inherently hairy sample code in C++/CLI
  • fix a few coding and formatting errors in the VB sample
  • standardize variable names across languages
  • take advantage of .NET's composite string formatting
  • upgrade to terse, elegant, fixed-format COBOL
  • outdent COBOL comments by one space for better visual alignment
  • crack a few jokes

Granted, the C++/CLI and COBOL examples are unnecessarily complicated by insisting on
using HelloWorld::Main as the startup object.

// C#
using System;

namespace Hello
{
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            string who = "C#";

            if (args.Length > 0)
            {
                who = args[0];
            }

            // Writing to the console is extremely tedious in C# ...
            Console.WriteLine("Hello, {0}!", who);
        }
    }
}



' VB.NET
Imports System

Namespace Hello
    Class HelloWorld
        Overloads Shared Sub Main(ByVal Args() As String)
            Dim who As String = "VB.NET"
            
            If args.Length = 1 Then
                who = args(0)
            End If
            
            ' ... and equally tedious in VB.NET.
            Console.WriteLine("Hello, {0}!", who)
        End Sub
    End Class
End Namespace


// C++/CLI
#include "stdafx.h"

using namespace System;

namespace Hello
{
    class HelloWorld
    {
    public:
        static int Main(array
^args)
        {
            String ^who = "C++/CLI";

            if (args->Length > 0)
            {
                who = args[0];
            }

            // Oh, the tedium of it all!
            Console::WriteLine(L"Hello, {0}!", who);
            return 0;
        }
    };
}

static int main(array
^args)
{
    return Hello::HelloWorld::Main(args);
}


      *> Finally some COBOL!
      $set ilusing"System"
      
       class-id.     HelloWorld as "Hello.HelloWorld".
       static.
       method-id.    Main.
       local-storage section.
       01  who   string  value "COBOL".
       linkage section.
       01  args  string  occurs any.
       procedure division using by value args.
           if args::"Length" = 1
               move args(1) to who
           end-if

          *> COBOL can be tedious, if you insist ...
           invoke type "Console"::"WriteLine"("Hello, {0}!", who)
           
          *> ... but since 1959 has supported a more expressive style:
           display "Goodbye, " who "!"
           .
       end method    Main.
       end static.
       end class     HelloWorld.

At the end of the day, only one of these languages is COBOL.

Reply | Email | Modify 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.