Previous Topic Next topic Print topic


Tutorial: Debugging the Hello COBOL World Application

This tutorial uses the Hello COBOL World application you created previously and modified in the Configuring the Hello COBOL World Application tutorial. The current tutorial demonstrates some of the debugging features of Visual Studio.

Modify your application

You are going to add some extra code to the application that will help demonstrate some of the debugging features:

  1. Open the helloworld.cbl program in the editor.
  2. Add the following code on a new line immediately after the line for the Working-Storage section:
    01 source-string pic x(10) value "AAbbAAbbCC".
  3. Add the following code after the line for the procedure division section and before the line for the COPY statement:
    inspect source-string replacing all 'A' by 'D'
    display source-string
    inspect source-string replacing characters by 'Q' 
            before initial 'C'
    display source-string
    

The source-string variable is a string that has an initial value of "AAbbAAbbCC". Some of the characters in this string are replaced during the execution of the application.

Prepare for debugging

Before you start debugging a multi-project application, you need to specify which the startup project is. This needs to be the HelloCOBOLWorld project. To make this the startup project:

  1. Right-click HelloCOBOLWorld in Solution Explorer and click Set as StartUp Project.
  2. Click Debug > Step Into to start debugging.

    This triggers a build of the project and starts the debugger. A few news windows and toolbars appear in the Visual Studio main window.

    The first line in the Procedure Division of the helloworld.cbl program is highlighted showing the line the debugger will execute next.

    The console window of the application is also opened but is empty because there is no information to display yet.

  3. Look at the various tabbed windows that are displayed - Autos, Locals, watch 1, Call Stack, Breakpoints and so on that are all windows assisting you with debugging.

    Note that Autos is showing the source-string variable and its initial value. This value will change as you step through the code.

Step through the code

You can now step through the code and see how the value of the SOURCE-STRING changes:

  1. Press F11, Step Into, to step the highlighted line.

    The first line in the program executes and the cursor moves to the next line in the code.

  2. Check the Autos window to see that the value of SOURCE-STRING has changed as instructed by the first line of code.
  3. Press F11 again.

    This executes the DISPLAY statement. Check the Windows Task bar for the application's console window which now also displays the value of SOURCE-STRING.

  4. Step through the next two lines in the same way and see how the value of the SOURCE-STRING variable changes.

    The cursor moves to the line that has the COPY statement and the debugger opens the HELLO.cpy copybook inline in the editor in the helloworld.cbl file.

  5. Press F11 to execute the DISPLAY statement in the copybook.

    This prints "Hello COBOL World" to the console window.

  6. Press F11 to execute the GOBACK statement.

    The application terminates and debugging stops and the IDE hides the windows and toolbars that are used during debugging.

You can save the solution and keep it in case you need to experiment with the Hello COBOL World application again.

What Next?

Continue with the more advanced tutorials available in this product help.

Previous Topic Next topic Print topic