FUJITSU FS Logo
HomeMigrationsServicesNewsPartnersStudentPricingAbout Us
Quick Search  
 
DowloadSupport
Home > Information
 
Customer Stories
FAQ's
What COBOL for me?
Run-Time Licensing
White Papers
Batch: Hidden Asset
NeoSort World Record
Reuse vs Rewrite
COBOL from .NET Dox
ASCII (ACP) to Unicode
with NetCOBOL for .NET
Moving Cobol to .NET
Web Services
COBOL/Microsoft .NET
Best of GUI
OO COBOL
COBOL 2000 (2002)
Recommended Books
Reviews
COBOL and VB on .NET
Learn COBOL in 24 hours
Mastering COBOL

COBOL for Microsoft .NET Framework

Introduction

You've probably heard some of the buzz surrounding the Microsoft .NET Framework. With that buzz have come announcements from a wide variety of language vendors indicating support for the new initiative. The questions arise: "Why is Microsoft interested in having so many languages target the new environment? Why bother with a language as old as COBOL?" The answer lies in recognizing that most businesses do not have the luxury of rewriting their large code base every time they want to extend the use of their existing applications.

By supporting the new Microsoft .NET Framework, Fujitsu Software is endorsing Microsoft's philosophy that programmers want and need to be able to use the programming language best suited to their application. With an estimated 70 percent of production business applications written in COBOL, the answer to enhancing those applications lies not in throwing out the COBOL, but in finding better ways to make it do new things.

With that support, Fujitsu Software enhances the productivity of organizations that use COBOL. Not only will COBOL programmers have access to a wide variety of new technologies, including .NET class libraries and ASP+, they will be able to work seamlessly with developers of code in other languages, such as C++ and Visual Basic. Instead of having a development organization with a schism between COBOL programmers and other programmers, the new environment allows programmers to bridge the barriers using common interfaces and programming tools.

This article discusses some of the important applications of this technology for COBOL and what it takes for a programming language vendor, such as Fujitsu Software, to deliver on the new vision.

COBOL on the Web
With an increasing amount of business being conducted on the Web, organizations everywhere are asking themselves how to best take advantage of the enormous new business opportunities. Businesses with lots of COBOL are even more concerned, since most of their applications were built long before the Web became the business phenomenon that it is today. These businesses find that retraining their workforce to use other programming languages as well as retooling their applications for the Web is a daunting task. COBOL vendors, including Fujitsu, have been selling a variety of solutions for migrating COBOL applications to the Web. Fujitsu's support for the .NET Framework builds on that position and takes several steps forward, allowing COBOL programmers to program directly to the Web and to easily use their existing legacy code.

ASP+ (language="COBOL")
ASP+ is Microsoft's successor to Active Server Pages (ASP), which was designed to deliver dynamic Web content. ASP faced a number of weaknesses in the areas of performance and programmability, and ASP+ makes substantial improvements in those areas. Instead of being interpreted like ASP, ASP+ compiles pages to native code. This change results in enormous performance benefits, with only a one-time cost to compile the page when it is first deployed. The other important side effect of the design choice (to compile instead of interpret) is that it opens the door for compiled languages to provide code in ASP+ pages.

Fujitsu COBOL is taking advantage of this important benefit by allowing COBOL programmers to embed COBOL code in ASP+ pages. The following is a sample ASP+ page written using COBOL that displays "Hello COBOL world!" in increasing font sizes:

<%@ page language="COBOL" %>
<script runat="server">

OBJECT.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 FONT-SIZE PIC S9(9) COMP-5.
END OBJECT.

</script>
<% PERFORM VARYING FONT-SIZE FROM 1 BY 1 UNTIL FONT-SIZE > 7 %>
<font size="<%=FONT-SIZE%>"> Hello COBOL world! </font> <br>
<% END-PERFORM. %>

The "<%@" characters introduce the directive that allow us to set the programming language for the page to COBOL. The <script> block allows us to introduce COBOL code that declares the FONT-SIZE variable and the characters "<%" allow us to introduce inline COBOL code to loop over the HTML that displays "Hello COBOL world!"

ASP+ also makes programming interactive content much simpler by exposing standard HTML elements as controls and allowing programmers to create new controls. Web Forms is the name given to this type of control in the .NET Framework. The sample below shows the use of several Web Forms controls in an application that displays the image of a piece of fruit based on the fruit name selected in a drop-down box.

<html>
<head>

    <script runat="server" language="COBOL">

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.

REPOSITORY.

PROPERTY SELECT-VALUE AS "Value"
PROPERTY IMAGE-SRC AS "Src"
PROPERTY SPAN-VALUE AS "InnerHtml"
CLASS STRING-BUILDER AS "System.Text.StringBuilder"
CLASS SYS-STRING AS "System.String"
CLASS SYS-OBJECT AS "System.Object"
CLASS EVENTARGS AS "System.EventArgs".

OBJECT.
METHOD-ID. FRUITLIST-CLICK.

DATA DIVISION.
WORKING-STORAGE SECTION.
77 IMAGE-FILE-BUILDER OBJECT REFERENCE STRING-BUILDER.
77 IMAGE-FILE-STR OBJECT REFERENCE SYS-STRING.
LINKAGE SECTION.
77 EVENT-SOURCE OBJECT REFERENCE SYS-OBJECT.
77 EVENT OBJECT REFERENCE EVENTARGS.
PROCEDURE DIVISION USING BY VALUE EVENT-SOURCE EVENT.

MOVE SELECT-VALUE OF FRUITLIST TO SPAN-VALUE OF FRUITNAME.
INVOKE STRING-BUILDER "NEW" USING BY VALUE "images/"

RETURNING IMAGE-FILE-BUILDER.

INVOKE IMAGE-FILE-BUILDER "Append"

USING BY VALUE SELECT-VALUE OF FRUITLIST
RETURNING IMAGE-FILE-BUILDER.

INVOKE IMAGE-FILE-BUILDER "Append" USING BY VALUE ".jpg"

RETURNING IMAGE-FILE-BUILDER.

INVOKE IMAGE-FILE-BUILDER "ToString"

RETURNING IMAGE-FILE-STR.

MOVE IMAGE-FILE-STR TO IMAGE-SRC OF FRUITIMAGE.

END METHOD FRUITLIST-CLICK.
END OBJECT.

    </script>

</head>
<body>

 
<form runat="server">

<font face="Verdana">
<b>Please Select A Fruit : </b>

 

<select id="FRUITLIST" runat="server" size="1">

<option value="Orange">Orange</option>
<option value="Apple">Apple</option>
<option value="Mango">Mango</option>
<option value="Pear">Pear</option>
<option value="Banana">Banana</option>

</select>

<input type="submit" value="submit" runat="server" OnServerClick="FRUITLIST-CLICK">

 

<p>
<table>

    <tr>

<td>

   <img id="FRUITIMAGE" src="images\blank.gif" runat="server" />

</td>

<td>

   <font face="Verdana" size=6>

<span id="FRUITNAME" runat="server"/>

    </font>

</td>

     </tr>

</table>
</font>

</form>
</body>
</html>

The <form> tag block surrounds the set of Web Forms controls used in the page. The runat="server" attribute indicates to ASP+ that the behavior of the control is implemented using code running on the server. This example has four Web Forms controls, whose names are specified using the "id" attribute:

  • A select control called "FRUITLIST" that displays the list of five fruits to choose from.
  • An unnamed input button. The "OnServerClick" attribute specifies that the button has a programmed event associated with clicking it. The value of the attribute gives the name of the method that is the event handler—in this case "FRUITLIST-CLICK."
  • An image control called "FRUITIMAGE" that is used to display the image of the selected fruit.
  • A span control called "FRUITNAME" that displays the name of the selected fruit alongside the image.

The <script> block at the top of the ASP+ page implements the "FRUITLIST-CLICK" event handler in COBOL for the input button control. The method extracts the selected name from the "FRUITLIST" control, uses the StringBuilder class from the .NET base framework to construct the path to an image file of the fruit, and sets the appropriate values for the "FRUITIMAGE" and "FRUITNAME" controls.

This technology enhances the programmability of Web pages and helps to overcome limitations of static HTML technology. With this technology you can imagine constructing sophisticated Web systems, including applications like electronic storefronts, inventory management systems, shipping management, and much more. Best of all, these applications can be programmed using COBOL if that is what your workforce is trained to use.

Web Services: Programming the Web
While ASP+ allows programmers to package dynamic content onto server-side Web pages, Web Services go a step further. They provide the opportunity to expose programming interfaces to the Web for use by clients to package in any way they see fit. This allows businesses to truly componentize their product offerings in ways that end-users can customize to suit their own applications.

The following is an example of a very simple Web Service written in COBOL:

<%@ webservice language="COBOL" %>

CLASS-ID. FOO.
FACTORY.
PROCEDURE DIVISION.
METHOD-ID. ADDME.
DATA DIVISION.
LINKAGE SECTION.
01 OPND-1 PIC S9(9) COMP-5.
01 OPND-2 PIC S9(9) COMP-5.
01 RET PIC S9(9) COMP-5.
PROCEDURE DIVISION USING BY VALUE OPND-1 OPND-2 RETURNING RET.

COMPUTE RET = OPND-1 + OPND-2.

END METHOD ADDME.
END FACTORY.
END CLASS FOO.

The example is just a COBOL class definition with a method called "ADDME" that adds two numbers together. The "webservice" directive at the beginning tells the .NET Framework that we want to expose methods as Web Services and identifies the programming language in which the methods are written. (In future versions, users will probably need to use a compiler directive to specify an attribute for each method that is to be exposed as a Web Service.)

As simple as this seems, a number of technologies all have to work together for Web Services to function. For example, SOAP is a protocol that Microsoft would like to see adopted as a standard; it is used for marshaling data using XML. SOAP is needed for clients and servers to communicate their arguments and results in a format that can ultimately be transmitted over HTTP. Microsoft has also defined a Service Description Language (SDL), which describes the services being exposed and provides clients the mechanism through which they can find those services.

Web Services open up new opportunities for application deployment. Instead of packaging business logic applications with wrappers that predetermine the Web presentation style and content, companies can expose their business logic as a Web Service to be customized for use by their customers.

Frameworks and Language Interoperability
The Microsoft .NET Framework SDK comes with frameworks that implement a wide variety of operations, such as I/O, data type manipulation, and graphical application development. Because Fujitsu COBOL is targeting the .NET Framework, the language in which these libraries are implemented is immaterial. COBOL programs can use these features as if they were written in COBOL. The infrastructure for this language interoperability is a common language runtime.

The previous ASP+ fruit list example has already demonstrated some of the uses of .NET frameworks. The COBOL method "FRUITLIST-CLICK" was embedded in a class that inherited from classes in the .NET frameworks. This allowed direct access to inherited properties. The "StringBuilder" class is another example of a class from the .NET base framework. The following sample shows the use of the Win Forms framework that allows developers to construct Win32-based GUI applications:

CLASS-ID. HELLO INHERITS FORM.
ENVIRONMENT DIVISION.

CONFIGURATION SECTION.
REPOSITORY.

PROPERTY WIN-TEXT AS "Text"
CLASS APPLICATION AS "System.WinForms.Application"

CLASS FORM AS "System.WinForms.Form".

FACTORY.
PROCEDURE DIVISION.

METHOD-ID. MAIN.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 APP-OBJ USAGE OBJECT REFERENCE FORM.
PROCEDURE DIVISION.

INVOKE HELLO "NEW" RETURNING APP-OBJ.
MOVE "Hello COBOL World!" TO WIN-TEXT OF APP-OBJ.
INVOKE APPLICATION "Run" USING BY VALUE APP-OBJ.

END METHOD MAIN.
END FACTORY.

END CLASS HELLO.

This very simple application brings up a frame window with the title "Hello COBOL world!" It demonstrates inheritance from the Win Forms "Form" class and use of methods and properties in the Win Forms class library.

Migrating COBOL Code to the Microsoft .NET Framework
The Microsoft .NET Framework provides interoperability between code targeted for the common language runtime, also known as managed code, and existing native code and COM applications. This means that developers can write new managed code that makes calls to their existing code. In the case of existing COM applications, this is as simple as using a type library import tool (TLBIMP) that makes COM interfaces visible to managed code. For other native code, users simply need to provide a COBOL prototype declaration for the code they want to call. To call from native code to managed code, developers can use a type library exporter (TLBEXP) and an assembly registration tool (REGASM) to export their managed code as COM objects.

Eventually, users will also have the option of compiling their existing code with the new compiler to run completely using the common language runtime. While Fujitsu Software is committed to enabling this scenario, early releases of the compiler are likely to not support all of COBOL's features.

Delivering on the Vision
As the only COBOL vendor to currently target the new Microsoft environment, Fujitsu Software has a commitment to a vision of seamless interoperability and powerful programming tools. The price of this commitment is the development of an enhanced COBOL compiler with language extensions to support the new platform, a completely new code generator targeting Microsoft's Intermediate Language (IL), and ASP+ support code for COBOL, among other things.

Code samples shown in this article are based on the implementation found in the preview release of the compiler. The precise syntax of COBOL language extensions shown here is subject to change in released versions.

Language Extensions
The common language runtime is based heavily on an object-oriented programming model. This does not mean that all programs that run in the environment have to be object-oriented, but object-oriented language constructs are needed to use some features of the environment. The Fujitsu COBOL implementation will conform to the most current COBOL draft standard where possible.

Some features of the common language runtime are not supported by the current state of the COBOL draft standard. For example, constructs like delegates, custom attributes, and visibility attributes have no existing representation in COBOL. For these constructs, Fujitsu will try to ensure that standards conforming programs are not affected by the existence of language extensions targeted to the common language runtime.

Code Generation
The common language runtime achieves its goals of interoperability, security, and robustness by operating on MSIL instead of native code. This means that compilers that target the environment have to develop new code generators that generate MSIL instead of native code. The common language runtime uses just-in-time (JIT) compilation strategies to ultimately translate code for the platform into fast native code.

Enhanced interoperability also means that applications with code written in different programming languages can also be seamlessly debugged. This is an important productivity benefit, particularly since most current development environments for COBOL (with the exception of Fujitsu COBOL) make debugging cross-language applications quite cumbersome.

ASP+ Support
In addition to a new compiler, language-specific support is also required for the new ASP+ infrastructure. Because ASP+ compiles its pages, it has to be able to generate code to represent the HTML and ASP+ content in the language in which the page is written. For example, the "Hello COBOL world!" ASP+ sample shown earlier results in generated code that includes the following fragment:

PERFORM VARYING FONT-SIZE FROM 1 BY 1 UNTIL FONT-SIZE > 7

INVOKE ASP_output "Write" USING BY VALUE " <font size="""
INVOKE ASP_output "Write" USING BY VALUE FONT-SIZE

INVOKE ASP_output "Write" USING BY VALUE

"""> Welcome to ASP+ (now in COBOL!) </font> <br> "

END-PERFORM.

The Future of COBOL
The long-term benefits of integration with the Microsoft .NET Framework are that COBOL will more easily adapt to new technologies. New frameworks that are developed for the .NET Framework (in any programming language) immediately become accessible to COBOL programmers. Fujitsu Software has always been committed to ensuring that COBOL programmers have the tools they need to develop applications using the latest technologies. Support for the .NET Framework lends assurances to that commitment.

 

 


 © 2003 - 2006 Fujitsu Computer Systems Corporation. All Rights Reserved.