Cobol for Microsoft .NET

1. Summary

This article gives you introduction about how the age old COBOL can take a new energetic look under Microsoft.NET.

2. Introduction   

In the article titled IL "THE LANGUAGE OF CLR" - A PLATFORM FOR CROSS-LANGUAGE I already talked about the cross language capabilities of Microsoft.NET architecture. In this section I would like to draw your attention towards one of the popular languages COBOL and would like to present some examples to show how COBOL extends its capability to deliver wide range of applications under .NET.   

Fujitsu has taken up the task of writing COBOL compiler that targets Common Language Runtime Environment to exploit the best features of Common Language Infrastructure. Fujitsu Software is an active member that is participating in the standardization of many of the drafts relating to .NET. It had brought many solutions and products relating to COBOL in the past and is working very hard to bring many other products that target Microsoft.NET  

I happened to go through all the previews provided by Fujitsu Software and take this privilege to present my own examples and feeling about this new compiler.   Though its not the final version of the release, I would like to provide future prospects of thislanguage. 

3. Installation Instructions   

If you dont have the COBOL preview III software from Fujitsu then you can download the file PackageFujitsuCOBOLPreviewIII (954KB), a Windows Installer Package, from http://www.adtools.com or http://www.fujitsu.com

Software Requirements:  

  • Windows 2000 Server
  • Windows 2000 SP1 or higher
  • .NET SDK Beta 2 ( Doesnt work with Beta1)
  • PackageFujitsuCOBOLPreviewIII

Installation Procedure 

  • Run PackageFujitsuCOBOLPreviewIII Windows Installer and follow the instructions.
  • Create a virtual directory named COBOL and map this to Examples folder which can be found at the following location drivename\Program Files\Fujitsu COBOL .NET Preview III\Examples\Web
  • Create directory named COBSAMPLES under drivename\Program Files\Fujitsu COBOL .NET Preview III\Examples\Web  

Note

If you create a virtual directory than the specified above and map it to any other location you may not be able to run the COBOL.NET applications.

Installing the COBOL.NET software  

Double click the Windows Installer you will find the following screen. Follow the instructions and it setups the required things to support ASP.NET applications, Windows Applications and VS.NET.  

Cobol43.jpg

Mapping a Virtual Directory

Cobol44.jpg

Open the Internet Service Manger. If required expand the node on left-hand side pane to find Default Web Site. Right click on Default Web Site and choose new/virtual directory option. Give the alias name as COBOL and then you will find the screen with browse option. Now map this to Examples directory as show in the below diagram.  

4. ASP.NET Applications using COBOL  

Look at the following example. It is just like any other aspx page with language attribute set to COBOL. For those who are migrating from COBOL and writing .NET applications for the first time it might take some time to understand the technology. But for time being type in your code in by opening a notepad and save as cobol.aspx. The extension of ASP.NET applications is .aspx. Ensure to save this in COBSAMPLES directory.  Thats all. Type in the following URL: http://localhost/cobol/web/cobsamples/cobol.aspx

<%@ page language="COBOL" %> 
<script runat="server">
       OBJECT.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 I PIC S9(5) COMP-5.
       END OBJECT.  
</script>
<% PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5 %> 
<% IF I=1 THEN %> 
<center><font size="<%=I%>">COBOL IN 1970'S</font>
<br></center> 
<% END-IF %>
<% IF I = 2 THEN %> 
<center><font size="<%=I%>">COBOL IN 1980'S</font>
<br></center>
<% END-IF %>  
<% IF I = 3 THEN %> 
<center><font size="<%=I%>">COBOL IN 1990'S</font>
<br></center> 
<% END-IF %>  
<% IF I = 4 THEN %> 
<center><font size="<%=I%>">COBOL IN 2000</font> <br></center>
<% END-IF %>   
<% IF I = 5 THEN %> 
<center><font size="<%=I%>">COBOL.NET IN 2001</font><br> </center> 
<% END-IF %>
<% END-PERFORM. %> 
 

The tag <script runat="server"> ensures the COBOL language understand the ASP.NET framework and makes it run at the server side. The remaining code is a combination of html mixed with simple asp code. This shows how simple and easy for COBOL programmers to migrate to ASP.NET. What all they need to understand is, what .NET is all about?.

Cobol45.jpg
  

The following is the output generated by the above code:
   

5. Creating Web Services Using COBOL

Many authors have written about Web Services. So I wont be saying all the details about Web Services here. In sample terms Web Services are distributed applications accessible across Internet using standard protocols such as SOAP and XML.The following is the COBOL Code for a Web Service called CalculateArea. This Web Service takes two inputs and returns the area of a rectangle. The extension for Web Services in ASP.NET is .asmx. The COBOL used is not procedural COBOL but Object COBOL. 

<%@ WebService Language="COBOL" Class="AreaOfRect" %>
       CLASS-ID. AreaOfRect. 
       OBJECT. 
       PROCEDURE DIVISION. 
       METHOD-ID. calculateArea. 
       DATA DIVISION. 
       LINKAGE SECTION. 
       01 SideA PIC S9(5) COMP-5. 
       01 SideB PIC S9(5) COMP-5. 
       01 RectangleArea PIC S9(5) COMP-5. 
      PROCEDURE DIVISION USING BY VALUE SideA SideB RETURNING RectangleArea.
       COMPUTE RectangleArea = SideA * SideB. 
       END METHOD calculateArea. 
       END OBJECT. 
       END CLASS AreaOfRect.
 

Key-in the above code in notepad and save it as CalculateArea.asmx and save it in COBSAMPLES directory. To view the result type in the following URL: http://localhost/cobol/web/cobsamples/calculatearea.asmx

The following is the output
Cobol46.jpg

Click on the CalculateArea link. You will get the following screen.

Cobol47.jpg 

Enter the values of SideA and SideB and click invoke. It throws the result in XML format. Needless to mention about the usefulness of XML format, it can be consumed by any application.

Once upon a time writing distributed applications using COBOL was unthinkable dream. But now with Microsoft.NET, languages have become equal and any language could produce same results. Thats not what COBOL can do for you. It can be useful for writing Windows application and can be used for cross language development etc. In the forthcoming articles I will be dealing with many other aspects of .NET using COBOL. Hope by now you might have felt the power of COBOL under .NET.

6. Conclusion

Fujitsu is trying to get COBOL.NET as soon as possible to the market. They got very good reputation for delivering COBOL related products and solutions. Its actively participating in standardization efforts of CLI (ECMA). The other participants include Hewlett-Packard, Intel Corporation, IBM, ISE, Microsoft, Monash University, Sun Micros Systems etc. There is no doubt that COBOL could be used more effectively than ever, for delivering wide range of applications. All those people using COBOL can now think of designing distributed applications, writing server-side programming, writing windows applications and so on. Be tuned for further developments in this area, as this is one of the popular languages used across the globe even today. Wait for my up coming articles in the same section.

7. Articles by the same Author

IL "THE LANGUAGE OF CLR" - A PLATFORM FOR CROSS-LANGUAGE  

Microsfot.NET An insight into code reusability and COM Interoperability Part 1


Similar Articles