Chapter 3: Tutorial: Developing a Simple COBOL Application

This tutorial introduces the Visual Studio IDE.

Overview

This tutorial introduces the Visual Studio IDE, and shows how to create, build and debug a simple console application using supplied COBOL programs that use ACCEPT/DISPLAY statements.

Starting Visual Studio

To run this tutorial, you must have both Microsoft Visual Studio and reUZE Developer installed.

To start Visual Studio:

  1. On the Start menu, click All Programs > Micro Focus reUZE Developer 6.0 > Microsoft Visual Studio 2008.
  2. You might be prompted to set the environment, depending on the version installed. If you are prompted, choose General development environment.

The IDE is shown in the figure below, although the information displayed in the large pane will be different.

The large pane is where your solutions and projects will be opened. At the moment, this shows the Start Page, with up-to-date information on Visual Studio. When you start work, this pane is where your code is displayed.

The pane at the bottom is the Output window, where messages from the IDE and Compiler are displayed.

The right-hand pane is the Solution Explorer, which displays the structure of your solution and projects. At the bottom of the Solution Explorer pane are some tabs. Solution Explorer appears by default.

If any of these panes is hidden, you can show it from the View menu.

Create a Solution and a Project

The first task is to create a solution and a project. A solution is a container holding one or more projects that work together to create an application. The solution has the extension .sln, and is a readable text file. Microsoft recommends you do not edit the file outside of Visual Studio.

A COBOL project has the extension .cblproj, and again this is a readable file, but Microsoft recommends that you do not edit it. Different types of project have different extensions, so for example a C# project has the extension .csproj.

In this section, you create a project and solution, as follows:

  1. In Visual Studio, create a new project by clicking File > New > Project.
  2. Under Project Types, expand COBOL Projects and click Native.
  3. Select the Console Application template.
  4. In the Name field, specify Locking as the name of the project.

    Notice that the Name and New Solution Name fields have the same name. Changing either one of them automatically changes the other.

  5. In the Location field, browse to a directory where you want to put this tutorial.

    For example, if you create a folder on your c: drive called tutorials, change the location field to c:\tutorials. The solution will be stored in a subdirectory Locking, according to the project name.

  6. Click OK.

This creates a solution and a project. The Solution Explorer shows the Locking project. It contains:

Add Files to the Project

You can add existing files to the project, as follows:

  1. Right-click the project in the Solution Explorer.
  2. Click Add>Existing Item.
  3. Browse to the Examples\Net Express IDE\Locking folder in the installation of your reUZE Developer development system. By default this is c:\Program Files\Micro Focus\reUZE Developer 6.0\Examples\Net Express IDE\Locking.
  4. Select all .cbl files.
  5. Click Add.

Build for Debugging

There are two default build configurations for each project type: Debug and Release. These configurations define how to build the project for the different situations.

To build the project for debugging and to run it:

  1. Check the build configuration in use, by clicking Build > Configuration Manager.
  2. In Active solution configuration, choose Debug and click Close.

    Notice in the Standard toolbar at the top of the IDE, that Debug shows as the active configuration.

  3. Build the project, by clicking Build > Build Solution.

    The Build option builds only those files that have changed since they were last built, whereas the Rebuild option builds all the files in the project, regardless of whether they have changed since they were last built.

  4. Check that the project compiled successfully by looking in the Output view. To display this view, click View > Output.
  5. Run the application, by clicking Debug > Start Without Debugging or .

    A console window opens, showing this character-based application running.

  6. Go to the console by clicking it. Then type 5 and press Enter.

    "5" is the code that tells this application to finish and the console closes.

  7. Check that the application has finished by clicking Debug. Notice that the Start Debugging option is now available and Stop Debugging is not. Click elsewhere in the IDE, to close the Debug menu again.

Project Properties

Project properties define characteristics of the project and enable you to control a project's behavior among other things. Different properties are set by default for different types of projects.

  1. To see a summary of the project properties, select the project or solution in the Solution Explorer. By default, the Properties window is displayed below the Solution Explorer.

    If the Properties window is not visible, you can show it by clicking View > Properties Window.

    A description of the selected property is displayed dynamically at the bottom of the Properties window. To turn this description on and off, right-click in the description.

  2. To display the full project properties, right-click the project in Solution Explorer and click Properties.
  3. Go to the COBOL page of the properties, to display the selected properties for building the project. Notice that:
  4. Go to the Debug page and notice that Start project is checked, so that the application starts debugging in the current project.
  5. Browse the other properties pages to see what is available and what is set by default for a console application.

Debug the COBOL Project

The IDE provides debugging facilities, such as stepping, examining data item values and setting breakpoints. To see some of these facilities:

  1. Click Debug > Step Into, or .

    A console opens for running the built programs.

    The source code for locking.cbl opens in the COBOL editor. The first statement DISPLAY SPACE is highlighted in yellow, with a yellow arrow pointing to it. This is the statement to be executed next.

  2. Execute the first statement, by clicking Debug > Step Into, or .
  3. Step the next statement, DISPLAY LOCKING01-00, in the same way.

    This statement displays some information about the application in the console.

  4. Execute the whole of the next PERFORM statement. To do this, click Debug > Step Over, or .

    Step Over executes all the code for a PERFORM or CALL statement in a single step.

  5. Continue stepping into the code, until you reach the ACCEPT statement.

    The console now appears and waits for your input.

  6. Type 5 as before and press Enter.

    Notice that the statement "EVALUATE CHOICE" is now highlighted ready for execution and that the value of the choice variable is now "5". You can see this by hovering over the choice variable in the Evaluate statement, and also by looking in the Autos pane at the bottom.

    If the Autos pane is not visible, open it by clicking Debug > Windows > Autos.

  7. To add the choice variable to the Watch list, right-click it and click Add Watch.

    This opens a separate pane, the Watch pane, which shows the values of watched variables.

  8. Continue stepping to the end.

You can close Visual Studio now. You do not need to explicitly save anything, because the files are automatically saved when you build them.


Copyright © 2009 Micro Focus (IP) Ltd. All rights reserved.