Debugging the Batch Application

You are going to debug the batch Bankdemo application using the JCL debugger.
Important: You need Enterprise Developer to debug applications as this feature is not supported in Enterprise Developer Personal Edition.

Starting the Bankdemo enterprise server

If the enterprise server is not yet started, you need to start it as follows:

  1. In Server Explorer, right-click BANKDEMO under Micro Focus Servers, then click Start.
  2. Right-click Micro Focus Servers again, and then click Refresh to see that the server has started.

    GUID-8BBA813D-63E6-4F46-9377-09CC16845DFF-low.png

Starting the debugger

The demonstration application includes around 60 programs and just eight of them, the ones which are included in the project, are debuggable. The default debugger in Enterprise Developer is the CICS Debugger. You need to select the JCL debugger to debug the batch Bankdemo application:

  1. In Solution Explorer, right-click the BankDemo project and click Properties.
  2. Click the Debug tab in the properties.
  3. Set Active Settings to JCL.
  4. Click File > Save All to save your changes.

To start the debugger:

  1. Click Debug > Step Into.

    Visual Studio enters debug mode and opens a few new windows.

    The application is now waiting for an event that will trigger the debugging.

Simple debugging

You can now look at some simple features inside the debugger. To submit the JCL job:

  1. In Solution Explorer, right-click ZBNKSTMT.jcl and click Submit JCL.
  2. Check the Output window (click View > Output to show the window, if it is hidden) to see the job has been submitted successfully.

    GUID-D9A33348-423E-4B87-8268-905E50D5D911-low.png

    The debugger starts, and the IDE opens ZBNKEXT1.cbl for debugging, with the execution point set on the first line of Procedure Division.

    GUID-727D937E-2620-4FD2-9442-89136172346A-low.png

Stepping through the code

The highlighted line of code is the one the IDE will execute next.

  1. Press F11 (Step Into) to execute the highlighted line.

    The PERFORM statement executes and takes you to the line starting with IF TIMER-START.

  2. Press F11 slowly a few more times until you reach line 18000.

Using Run To Cursor

  1. Scroll down the file and position the cursor on a line further down the code.
  2. Right-click the line in the editor and click Run To Cursor.

    The application runs and executes the instructions till the line you selected.

Using the debug windows

There are a number of default windows which you can use while debugging the application such as:

Autos
Shows the values of the data items on the current line you have stepped into.

GUID-FDF89DD7-D94B-42EA-8FA8-BC0D85DD3EF8-low.png

Watch
This window shows the values of data items you have added to the watch list. To set a watch on a data item:
  1. Scroll up to line 5900 in ZBNKEXT1.cbl.
  2. Right-click WS-RECORD-COUNTER1 and click Add Watch.

    This adds the item to the Watch window so you can see how it changes as you step through the code.

    GUID-43973591-A851-4A10-9CEB-B177C3518B51-low.png

There are some additional windows you can use as well. To open them:

  1. Click Debug > Windows and select a window from the list.
  2. Open the windows for Breakpoints, Watchpoints, Program Breakpoints, a number of one to four Memory windows:

    GUID-49120C70-D2C1-4755-ACDC-AE7DFF2ABC8E-low.png

    Note that the windows are stacked, with a tab running along the bottom of the window.

Looking at data values in debug mode

While debugging, you can preview the values of data items in the current context as follows:

  1. Open the ZBNKEXT1.cbl file and scroll down the code to line 24700.
  2. Hover over the WS-RECORD-COUNTER2 data item.

    This opens a pop-up with the value of the item in the current context:

    GUID-6CF5C2DC-C1EE-44A1-9C14-E24095C1CB52-low.png

  3. You can click GUID-1D6F43CE-1DE2-4A43-8AE0-7FC7496F1265-low.pngto pin the pop-up to the editor window.

Setting a simple breakpoint

Open the Breakpoints window - currently, there are no breakpoints set in the program. You can set a simple breakpoint as follows:

  1. Scroll up the code to line 019100 of the ZBNKEXT1.cbl file.
  2. Double-click in the grey area to the left of this line or right-click the line and click Breakpoint > Insert Breakpoint.

    GUID-90921912-E7CC-4165-B7E5-2795B6ECF8C4-low.png

  3. Do the same for line 019700.
    Note: You can enable and disable the breakpoints from the Breakpoints window.

    GUID-EA79A511-8BD8-4390-BE8A-E8AC91A49C02-low.png

  4. Click F5 to run the code.

    The execution of the code stops at the first breakpoint.

  5. Press F5 to resume the execution.

    You can see that ZBNKEXT1.cbl finishes and the debugger starts to debug the second program defined in the JCL.

    This program executes to completion and the job completes.

Setting a COBOL watchpoint

In native COBOL, you can set COBOL watchpoints on data items in the code, and watch the memory associated with that data item. You can add a COBOL watchpoint as follows:

  1. Scroll to line 9100 in the code of ZBNKEXT1.cbl file.
  2. Right-click WS-EXEC-PARM-LL and click Add COBOL Watchpoint.

    This adds the item to the COBOL Watchpoints window.

  3. Notice how the value of this data item changes as you step through the code.

    GUID-D564775D-C6A5-4F58-85C2-2800AA718ED1-low.png

Note: To view watchpoints, you need to restart debugging as previously shown.

Running CSI queries

You can use the COBOL Source Information (CSI) functionality and its Quick Browse dialog to obtain information about your program when you are debugging it.

  1. Open the SBANK00P.cbl file in the editor.
  2. Click Quick Browse button, Quick Browse, in the COBOL toolbar to start the CSI query control.

    See COBOL toolbar in the product help for more information.

  3. Enter a simple query such as WS-*.

    GUID-BC6F1C57-47A3-4A8B-A350-C227BAB47292-low.png

  4. Press Enter to run the query.

    The results are shown in the Micro Focus Code Analysis window:

    GUID-8A98099C-70B7-4BF7-91C4-7991B9DACA34-low.png

Running COBOL reports

Enterprise Developer provides a few COBOL reports which you can run against your COBOL programs to help you understand and optimize them. For example, to run a report to identify any code that cannot be reached or executed, you need to run an unreferenced data report:

  1. With the SBANK00P.cbl file still opened in the editor, click the down arrow next to Quick Browse button, Quick Browse, in the COBOL toolbar and click Unreferenced Data.

    The IDE shows the results in the Micro Focus Code Analysis window:

    Dead Code report

  2. Expand any of the lines in the report and double-click a line in the result to highlight the lines of code that include unreferenced data.
  3. Use the rest of the commands available from the down arrow next to Quick Browse button, Quick Browse, in the COBOL toolbar to run any of the other available reports.

Stop debugging

Although the job has completed, the debugger is still waiting for the next event. To stop debugging:

  1. Click Debug > Stop Debugging.