Mastering+COBOL
Mastering+COBOL

COBOL debugging: is a concept used in COBOL programs. Let us go into details of this concept. Many COBOL programmers have a question, if debugging tools are there, why we need to go for COBOL debugging. Yes, it is true, but it has some advantages.

How to implement COBOL debugging?

Any program line with a D character in the indicator area is a debugging line. If the SOURCE-COMPUTER paragraph in the Configuration Section of the Environment Division contains the phrase WITH DEBUGGING MODE, the debugging lines are treated as regular COBOL source code.

IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM-NAME.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. HAL-2001 WITH DEBUGGING MODE.

If the WITH DEBUGGING MODE phrase is not present, the debugging lines are treated as comments.

In this way, you can insert debugging statements into your program and selectively turn them off or on by excluding or including the WITH DEBUGGING MODE phrase. Of course, you must recompile your program to remove or add the phrase, but you don’t need to remove any of the debugging lines.

Example for COBOL debugging:

A debugging line often contains a DISPLAY statement that shows the location of the statement. It also may contain the contents of critical data items that need to be monitored to find a particular problem. Here is an example:

001000 PERFORM A-200 THRU A-200_EXIT.

004000 A-200.
004010 some statements

004200 COMPUTE MAX-INTEREST = …

004201D DISPLAY “A-200-EXIT; MAX-INTEREST = “, MAX-INTEREST.

004210 A-200-EXIT.

004220 EXIT.

The debugging line (4201) is compiled and is a normal program statement when WITH DEBUGGING MODE is specified. In that case, the DISPLAY statement will be executed. If WITH DEBUGGING MODE is not specified, line 4201 is a comment.

Debugging lines are not restricted to the Procedure Division. They are allowed anywhere in the source program after the SOURCE-COMPUTER paragraph. You might define a file to which you write debugging information.

Advantages:

  1. if we are not in debugging mode, the ‘D’ lines will be treated as comments. So, we can save spool space
  2. Any layman can use this concept for testing of COBOL programs.
Advertisements

One thought on “2 More Ideas on COBOL Debugging

Comments are closed.