Previous Topic Next topic Print topic


Tutorial: Configuring the Hello COBOL World Application

COBOL applications often consist of COBOL source files and of copybooks - files that include code that is copied into other programs. Copybooks might not be stored in the same location as the source files. This tutorial demonstrates how to configure a project to locate any copybooks that are not in the project directory.

You are going to modify and configure the Hello COBOL World application which you created in the tutorial Hello COBOL World Application to use a copybook which is external to the project. This is what you are going to do as part of this tutorial:

  1. Create a project in the same solution that only contains a copybook.
  2. Move a part of the code from the helloworld.cbl program in your HelloCOBOLWorld project to the new copybook.
  3. Replace the original code in helloworld.cbl with a copy statement.

    The changes you make to your project will cause some build issues.

  4. Modify the project's properties to add the path to the copybook file in order to resolve these build issues.

Create a project for the copybook file

  1. In Solution Explorer, right-click your solution and click Add > New Project.
  2. Ensure that COBOL > Native is highlighted, and select Console Application.
  3. Specify a name such as CobybookProj and click OK.

    This creates the project in the same solution alongside the HelloCOBOLWorld project.

  4. Delete the skeleton program that was created in this project.

    This project will only store a copybook file.

Create a copybook

  1. Right-click CopybookProj in Solution Explorer, and click Add > New Item.
  2. In the Add New Item dialog box, click Copybook.
  3. Specify a name such as Hello.cpy and click Add.

    This creates the file in your project and opens it in the editor. You are now going to add some code to the file from the HelloCOBOLWorld project.

  4. Click helloworld.cbl in the editor.
  5. Copy the following line from the file:
               display 'Hello COBOL World!'.
  6. Paste the code in the Hello.cpy copybook.
  7. Back in helloworld.cbl, replace the line that you just copied with a COPY statement:
               COPY Hello.cpy.
  8. Save your changes.

    Note that the line for the COPY statement in helloworld.cbl is now underlined with a red wavy line in the editor.

    helloworld.cbl now has a red error icon in Solution Explorer. Open the Error List window (click View > Error List) to see the error about the specified copybook not being known. The same error message is displayed when you hover the line for the COPY statement.

  9. Click the error message in the Error List window and press F1 to see the information in the product help about this issue.

    Note that the help preferences must be set to Launch in Help Viewer from Help > Set Help Preference.

    The cause for this issue is that Hello.cpy is not known to the HelloCOBOLWorld project because it is not in the project directory. To resolve this, you need to add the path to the location of the copybook to the project's properties to enable the project to use the copybook.

    You are going to look at exactly where the copybook file is located.

  10. Right-click CopybookProj in Solution Explorer, and click Open Folder in File Explorer.

    This opens Windows Explorer and shows the contents of the project on the hard disk.

  11. Navigate one folder up in the location of the project.

    This opens the solution folder and you can see that both project folders,CopybookProj and HelloCOBOLWorld, are subfolders within the solution folder.

Specify a copybook path in HelloCOBOLWorld

In order for the HelloCOBOLWorld project to locate the copybook file, the project needs to be configured with the path to the location of the copybook. To do this:

  1. Select HelloCOBOLWorld in Solution Explorer and click Project > HelloCOBOLWorld Properties.

    This opens the tabbed pages with the project's properties inside the IDE.

  2. Click the Copybooks tab.
  3. Click the New Line button.
  4. Type ..\CopybookProj to specify a relative path to the copybook and press Enter to confirm, then click File > Save All.
  5. Select the helloworld.cbl program in the editor and notice that the red wavy underline has disappeared and that there are no error messages in the Error List window.
  6. Build the solution again.

    The build should be successful.

Preserve these projects because you are going to use them for a demonstration of how to debug an application.

What Next?

Continue with the next tutorial, Debugging the Hello COBOL World Application, which shows some of the debugging techniques in Visual Studio.

Previous Topic Next topic Print topic