Blue Theme Orange Theme Green Theme Red Theme
 
Discover the top 5 tips for understanding .NET Interop
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

In this article we'll take a look at some C# samples of code and then translate those samples into COBOL.

Author Rank :
Page Views : 13629
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Nevron Chart
Become a Sponsor
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Description 

Microsoft has done an outstanding job documenting the .NET Framework and providing a wealth of examples. The majority of all the examples provided will show a developer in detail how to utilize the Framework or concept in question, that is if you're a VB or C# programmer! What about NetCOBOL? Well Fujitsu Software is working on creating samples and making them accessible to the general public. In the meantime however, what's a COBOL developer supposed to do to solve a problem you currently have?

In this article we'll take a look at some C# samples of code and then translate those samples into 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.

A really neat trick!

One of the brightest people I know of has assisted Fujitsu Software in creating a dual set of CD's titled "Microsoft .NET for COBOL Programmers". (This set of CD's is currently available from Fujitsu Software). The author of the CD's is Howard Hinman, President and CEO of Hinman Consulting. Howard had a very good suggestion that I used while learning the .NET environment, create a duplicate project in either VB.NET or C#. During your development phase, create an additional project in your solution using either of Microsoft's languages. Howard is more comfortable with VB so he chose VB.NET, I am more comfortable with C# so I use it.

What we both do however is create an additional project in our COBOL solution. If I am creating a WinForm application then I create another WinForm application in C#. As I am  going through the COBOL development process if I have any questions on how a specific namespace is implemented I use the other language project to help me out. Now don't worry if you don't know C# at this point. You will only be using it to try and help determine what a certain objects method and properties are. In C# (and VB.NET) a feature called 'intellisense' has been implemented. Intellisense provides a programmer with additional information about an object when they are using that object. We'll get to more of this in a little bit.

Syntactical Differences

C# uses an OBJECT-DOT-PROPERTY syntax. The object in question may be a WinForm, a text box or any of the over 5,000 namespaces within the Framework. The key is when a developer presses the dot (.) . When the dot is pressed a context sensitive window appears showing the developer what options are available for that particular object. The window may contain other objects, properties or methods that are accessible to the object. Instead of remembering where a specific property or method is within an object, by using intellisense a developer can 'drill down' to the property or method they are looking for.

For instance, the following code shows intellisense for a command button object.

VS.NET is waiting for the developer to select an item or begin typing. When a developer begins typing intellisense will position the list based on the input. So instead of keying say 'Text', the developer would begin keying in 'T' and intellisense will move the list to show all items beginning with 'T'.

Notice also the presence of tool-tip text to inform the developer of what they are selecting. We are going to modify the text on the face of the command button to be "Call COBOL". To do this we need to select the 'text' property and set it to "Call COBOL". The following image details the code necessary to accomplish this. (We are interested in converting the code to COBOL so we will complete the C# code for you to compare).

COBOL utilizes a different syntax to call a method of an object or update it's properties. The syntax used to set a property to value is

 SET PROP-WHATEVER OF OBJECT TO SOMETHING.

The syntax used to invoke a method is

INVOKE OBJECT "METHOD" USING (any parameters) RETURNING (any parameters).

The items in blue are required and are case sensitive.  But what if the property or method you are looking for is contained within another object referenced by the current object? Simple, add another 'OF OBJECT' phrase to the statement. We'll assume you are going to update a property of an object that is called from another object. The syntax would be similar to:

SET PROP-WHATEVER OF OBJECT1 OF OBJECT2 TO SOMETHING.

Now let's convert our sample.

Conversion

Following the guidelines detailed in the preceding section, to update a button text in COBOL we would code the following:

SET PROP-TEXT OF button1 TO "CALL COBOL".

The completed method is:

Notice the use of the field PROP-TEXT. PROP-TEXT is a pseudonym for the actual 'Text' property value for the control. This is defined in the repository of the class and has the following syntax:

In COBOL, we use the AS clause to create aliases for names that cannot otherwise be written in COBOL. In other words, you create a name friendly to COBOL and put the external name that might not be so COBOL friendly in quotes after AS.

Wrap-Up

While the sample presented is a simple one, the theory behind it flows through to all of the NetCOBOL for .NET environment. Research what you are attempting to accomplish. Locate the objects, property and method you are attempting to use and then create either a C# or VB.NET project, if possible. Create the programming necessary to do what you are attempting and see how it is done in C# if no other sample are available. Next, copy the line of code into your COBOL project (commenting it out of course) and then following the above guidelines, translate it into COBOL. Over time this process will become second nature to you and soon you'll be coding native .NET calls without doing the research. Remember, one has to learn to crawl before you can run a marathon!

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 Systems Engineer with Fujitsu Software based in Minot, North Dakota. While his primary duties are pre-sales support, Rick also does Consulting and Training. 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 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. 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:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
display an image using cobol by anu On July 27, 2007
Hi Rick, Could you help me in below question: I have scanned iamge stored in oracle database. Now I want to dispaly that iamge on cobol screen. I am using MF-cobol and UNIX. how this can be done. thanks in advance.
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.