Configuring the 'Hello COBOL World' application

After taking a look at how Eclipse uses resources and the configuration options available in the IDE, you are going to see how to configure a project to locate copybooks that are not in the project directory. COBOL applications often consist of COBOL source files and copybooks that are not necessarily in the same location as the source files.

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

  1. Create a COBOL Copybook project in the same workspace with a single copybook.
  2. Move a part of the code of the helloworld program from your HelloCOBOLWorld project to the copybook in the copybook project.
  3. Replace the original code in helloworld with a copy statement.
  4. Use project references and define a project dependency to the copybook project to resolve the build issues that appear in HelloCOBOLWorld after you've modified the project.

Create a copybook project

  1. Open Enterprise Developer starting at the workspace in which you created your HelloCOBOLWorld project.
  2. Click File > New > COBOL Copybook Project.
  3. Specify a name for your project such as CopybookProj and click Finish.

    This creates the CopybookProj project in the same workspace and displays it in COBOL Explorer alongside the HelloCOBOLWorld project.

Add a source file

You need to create a program in your project to hold the COBOL source code:

  1. Right-click CopybookProj in COBOL Explorer and click File > New > COBOL Copybook.

    This starts the New COBOL Copybook wizard.

  2. Specify Hello.cpy as the file name and click Finish.

    This adds the copybook file to the project and opens it in the editor. Copybooks do not compile so the COBOL Copybook project type is not configured to build.

    You are now going to add some code to the file from the HelloCOBOLWorld project.

  3. Expand HelloCOBOLWorld in COBOL Explorer view and double-click helloworld.cbl to open it in the editor.
  4. Copy the following line from the file:
               display 'Hello COBOL World!'.
  5. Paste the code in the Hello.cpy.
  6. Back in helloworld.cbl, replace the line that you just copied with a COPY statement:
               COPY Hello.cpy.
  7. Save your changes.

    This starts a build that no longer compiles cleanly. There are some errors reported in the Output view and some error markers are added to the project in COBOL Explorer as well as in the editor.

    In situations such as this, you need to check all of the error messages Eclipse reports. Then, you need to try and eliminate the causes for them one by one until the project compiles cleanly again.

  8. Check the Problems view and expand the Errors list to see exactly what the error messages are.

    Alternatively, hover the error marker (or any of the error markers) in the editor and see the error message in a tooltip. The error that is reported is that there is an unknown copybook.

  9. Click the error message in Problems view and press F1 to search the product help for more details.

    This opens the Help view with the topic that corresponds to the error message. The reason for this problem is that Hello.cpy is unknown to the HelloCOBOLWorld project.

Create a project dependency

In order for HelloCOBOLWorld to recognize the copybook file, the project needs to have a dependency on the copybook project. Here's how you define the dependency:

  1. In COBOL Explorer, right-click HelloCOBOLWorld and click Properties.
  2. Expand Micro Focus and click Build Path.

    You can click the tabs in this pane to see what settings you can specify on these pages.

  3. Click the Projects tab.

    This is the tab where you add other projects your project depends on.

  4. Click Add and in the dialog box that starts check CopybookProj, then click OK.
  5. Click the Dependency Paths tab and ensure that the copybook path for CopybookProj is checked.
  6. Click OK to create the dependency.

    This triggers a build of HelloCOBOLWorld and, because the project now locates the copybook, the build completes without any errors.

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 section in this introduction to learn about the development life cycle used in Eclipse.