October 2017 : Online course in ASP.NET MVC / Core. Conducted by Bipin Joshi. Read more...
Registration for October 2017 batch of ASP.NET MVC / Core online course has already started. Conducted by Bipin Joshi. Book your seat today ! Click here for more details.

<%@ Page %>

"Hello World" - the COBOL Way

Introduction

One of the excellent feature of .NET is multiple language support. If you already have skills in one of the supported languages the learning curve will be much less. There are more than 20 languages (including C#, VB.NET, Managed C++ and JScript.NET) that can be used to develop applications targeted at .NET framework. Fujitsu has developed a dialect of COBOL called NetCOBOL for .NET. You can download the compiler from their web site. This simple application is Hello World application developed in COBOL.NET.

COBOL Reference Formats

The COBOL code must be written according to the "reference format". The Reference Format is rule stating which element is being placed in which position on the line. The 3 Types of Reference Formats are:
  • Fixed Format
  • Variable Format
  • Free Format (Specific to Win32 and Sun)
Below given is the configuration of the Source code using either Fixed or Variable Reference format. (Note: Position here refers to column Number.)
  • Position 1-6 - Sequence Number Area
  • Position 7 - Indicator Area
  • Position 8- 11 - Area A
  • Position 12-72 - Area B
  • Position 73 - 80 Program Identification Number Area (For Fixed Formats only).

COBOL Divisions

COBOL consists of several divisions which are as follows:
  • IDENTIFICATION DIVISION : Specifies name of program and program attributes. Must be placed at the beginning of the program
  • ENVIRONMENT DIVISION (Optional) : Followed by the IDENTIFICATION DIVISION. Specifies the environment suited for the computer that runs the program
  • DATA DIVISION.(Optional) : Consists of 7 sections.
    1.BASED STORAGE SECTION
    2.FILE SECTION
    3.WORKING-STORAGE SECTION
    4.CONSTANT SECTION
    5.LINKAGE SECTION
    6.REPORT SECTION
    7.SCREEN SECTION
    The entries in the DATA DIVISION must be in the above order
  • PROCEDURE DIVISION : Contains the procedures to be executed by the object Program

Source Code

Open VS.NET and select COBOL Projects -> Console Application. Alternatively, you can also write it in Notepad and save the file as simpleHello.cob. Write the code snippet given below:
000330 IDENTIFICATION DIVISION.
000340 PROGRAM-ID. MAIN.
000350 AUTHOR. Sushila Bowalekar.
000360 DATE-WRITTEN. 25 June 2002.
000370
000380 ENVIRONMENT DIVISION.
000390
000400 DATA DIVISION.
000410 WORKING-STORAGE SECTION.
000420
000430 PROCEDURE DIVISION.
000440     DISPLAY "Hello World! "
000450     DISPLAY "From COBOL.NET!!"
000460 END PROGRAM MAIN.

Compiling the code

You can compile the application directly from VS.NET or you can compile it by typing following command :
cobolc -main:MAIN simpleHello.cob
Now run the application go to the specific folder and start the .exe generated.

In the next article we will see how to display message box using COBOL.NET.


Sushila Bowalekar, is presently working as Training Consultant in Mumbai, India. Her skill set includes HTML, JavaScript, VBScript, ASP, Site Server Commerce Edition 3.0 and presently she is working on .NET.

Posted On : 29 June 2002


Tags : .NET Framework Visual Studio Components