Previous Topic Next topic Print topic


Tutorial: Creating Your First Hello COBOL World Application

This tutorial walks you through the steps to create your first Hello COBOL World application and demonstrates the basic features of the Visual Studio Integrated Development Environment (IDE).

Create a project

  1. To start the Visual Studio IDE:
    Windows 7 and Earlier
    • From your desktop, click Start > Visual Studio 2017.
    Windows 8, 8.1, and Windows Server 2012
    • Click the Visual Studio 2017 tile.
    Windows 10 and Later
    • Click Start > Visual Studio 2017.

    If this is the first time you have started Visual Studio on your machine, you are prompted to specify default environment settings. Choose General Development Settings.

    The windows you see open in Visual Studio and their layout depend on whether you have used the IDE before and on the edition of Visual Studio that you might have installed on your machine. You can move, resize and minimize windows which is why they may not look exactly like described here.

    You can see:

    • The Start Page which you can close.
    • The Solution Explorer window which gives a direct view of what is on disk for your solutions.

      A solution is a holding place for projects that relate to the solution. For example, the solution you are going to work with contains two projects - a batch project and an online project.

    • Bottom right is a Properties window which shows the properties of the currently selected item in the Solution Explorer.
    • Output window - displays the results of tasks and from compiling your applications.
    • Error List Window - displays details about any errors that might be present in the code.
    • Project Details Window which gives a logical view of your COBOL application.
    • The main activity window at the top the IDE, the Editor, is where you edit or debug the sources. This window is currently empty.
    • Apart from the menus, there are a number of buttons in the toolbar, which vary depending on what you are currently doing with the IDE.
  2. Experiment with resizing, minimizing and restoring the windows.
    To move a window:
    1. Click the title bar of the window. Holding the mouse on the window title, drag the window to the left and down.

    Note: If you close a window, you can restore if from the View menu.

    If you wish to restore the default windows layout of the IDE, click Window > Reset Window Layout.

  3. Select File > New > Project.
  4. In the left-hand side of the New Project dialog box, ensure that COBOL is selected under Installed > Templates > COBOL.
  5. Click Native under COBOL and then select Console Application in the middle pane.
  6. Specify a name for your project such as HelloCOBOLWorld, specify a location as needed, and click OK.

    This creates a solution (which is a container for projects), and a project with a skeleton COBOL program. The solution and the project are displayed in the Solution Explorer view. The program is loaded in the Visual Studio editor.

Add a source file

To demonstrate how you create new files in a project, you are going to create a new source file that will hold the source code for the Hello COBOL World application:

  1. Right-click your project in the Solution Explorer, and click Add > New Item.
  2. In the Add New Item dialog box, ensure that COBOL program is selected.
  3. Specify a name such as helloworld.cbl and click Add.

    This creates the file in your project and opens it in the editor.

  4. You can delete the skeleton program that was created when you created the project - right-click Program1.cbl in your project in the Solution Explorer, and click Delete.

    Confirm that you want to delete the file.

  5. In the code within the new file, navigate to the line that contains procedure division. where you need to add your executable statements. Place the cursor at the end of the line and press Enter.

    This creates a new line in the file and the cursor is positioned right after the grey margin area in the AB area. By default, the COBOL editor is configured for smart editing and does not position the cursor in the COBOL margins areas.

  6. Type the code to write some text in the console:
           display 'Hello COBOL World!'.
  7. Click File > Save All.

Build the application

Now that you have added some code that can be executed, you can build your project. Because this is a project that creates a console application, building will produce an executable file in a subfolder of the project which is specified in the project's properties. To build the application:

  • Select the solution in Solution Explorer and click Build > Build Solution.

    The progress of the project build is displayed in the Output window. It shows that the build has succeeded and where the executable file is. If there were any issues with the build, the IDE displays the Error List window. You can open these windows manually from the View menu.

Your project was built successfully so you can now run the application.

Run Hello COBOL World

To run the application from Visual Studio:

  1. Click Debug > Start Without Debugging.

    This opens a command window that shows Hello COBOL World.

  2. Press any key to close the console.

Preserve this solution and project because you are going to use it again for a different demonstration included in this Introduction.

What Next?

Continue with the next tutorial, Configuring the Hello COBOL World Application, which shows how to configure a project to locate the copybooks that are not in the project directory.

Previous Topic Next topic Print topic