Exercises — Chapter 33: Debugging Strategies
Exercise 33.1: Debug Level Implementation (Coding)
Write a COBOL program that implements a multi-level debug system:
- Define a WS-DEBUG-LEVEL field (0-9) that is read from a JCL PARM
- Create a standard debug display paragraph that includes timestamp, level, paragraph name, and message
- Add Level 1 traces (paragraph entry/exit) to at least 5 paragraphs
- Add Level 2 traces (key data values) at decision points
- Add Level 3 traces (detailed field values) for data inspection
- Test the program with debug levels 0, 1, 2, and 3, showing the difference in output volume
Exercise 33.2: Abend Code Identification (Analysis)
For each scenario below, identify the most likely abend code and explain why:
- A program moves SPACES to a PIC S9(7)V99 COMP-3 field, then adds 1 to it.
- A program CALLs 'CALCMOD1', but the load library does not contain CALCMOD1.
- A program defines a table with OCCURS 50 TIMES and uses a subscript value of 51.
- A batch program processes a file with 10 million records and each record takes 0.5 seconds of CPU.
- A program reads a VSAM file with LRECL=200 but the record is defined as PIC X(300) in the FD.
- A COMP-3 field PIC S9(3)V99 contains the value 999.99 and the program adds 1 to it.
- A program references a LINKAGE SECTION field without the corresponding USING clause.
Exercise 33.3: Reading a Dump (Analysis)
Given the following abend information, diagnose the problem:
SYSTEM COMPLETION CODE=0C7
ACTIVE LOAD MODULE: PAYROLL1
OFFSET: 0000B4A2
Compiler listing excerpt (with OFFSET option):
LINE OFFSET SOURCE
002340 00B498 MOVE WS-HOURS TO WS-DISP-HOURS
002341 00B4A0 MULTIPLY WS-RATE BY WS-HOURS
002342 00B4A2 GIVING WS-GROSS-PAY ROUNDED
002343 00B4B0 ADD WS-GROSS-PAY TO WS-TOTAL-PAY
MAP listing excerpt:
WS-RATE BL=01 0A8 PIC S9(5)V99 COMP-3
WS-HOURS BL=01 0AC PIC S9(3)V99 COMP-3
WS-GROSS-PAY BL=01 0B0 PIC S9(7)V99 COMP-3
Dump at BL=01 + 0A8:
0A8: 01 234 5C (WS-RATE: valid packed +12345)
0AC: F4 F0 F0 (WS-HOURS: ???)
0B0: 00 000 000 0C (WS-GROSS-PAY: valid packed +0)
Tasks: 1. Which field caused the S0C7? 2. What does the hex value F4F0F0 represent? 3. How did this value likely get into WS-HOURS? 4. What fix would you apply?
Exercise 33.4: Bug Hunting Challenge (Coding)
The following COBOL program has five bugs. Find and fix all of them:
IDENTIFICATION DIVISION.
PROGRAM-ID. BUGGY01.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TABLE.
05 WS-ENTRY PIC X(10) OCCURS 10 TIMES.
01 WS-COUNT PIC 9(2).
01 WS-TOTAL PIC S9(7)V99 COMP-3.
01 WS-AMOUNT PIC S9(5)V99 COMP-3.
01 WS-INPUT-REC.
05 IN-NAME PIC X(20).
05 IN-AMOUNT PIC 9(5)V99.
01 WS-STATUS PIC X(2).
88 END-OF-FILE VALUE '10'.
PROCEDURE DIVISION.
0000-MAIN.
OPEN INPUT INFILE.
PERFORM UNTIL END-OF-FILE
READ INFILE INTO WS-INPUT-REC
AT END SET END-OF-FILE TO TRUE
END-READ
ADD 1 TO WS-COUNT
MOVE IN-NAME TO WS-ENTRY(WS-COUNT)
MOVE WS-INPUT-REC TO WS-AMOUNT
ADD WS-AMOUNT TO WS-TOTAL
END-PERFORM
DISPLAY 'TOTAL: ' WS-TOTAL
CLOSE INFILE.
STOP RUN.
Hint: The bugs involve initialization, table bounds, data movement, group moves, and processing sequence.
Exercise 33.5: CICS Debugging Scenario (Analysis)
A CICS transaction XINQ displays customer information. Users report that sometimes the screen shows data from the wrong customer. The programmer added CEDF tracing and captured this:
EXEC CICS READ FILE('CUSTFILE') INTO(X'00A34000')
LENGTH(250) RIDFLD(X'C3F0F0F0F0F2F0F0F0F1') RESP(NORMAL)
[several EXEC CICS SEND MAP commands]
EXEC CICS READ FILE('CUSTFILE') INTO(X'00A34000')
LENGTH(250) RIDFLD(X'C3F0F0F0F0F1F0F0F0F1') RESP(NORMAL)
Tasks: 1. What do the hex RIDFLD values represent in EBCDIC? 2. Why are there two READs with different RIDFLDs? 3. What is the likely cause of the "wrong customer" display? 4. How would you fix this?
Exercise 33.6: SQL Debugging (Coding)
Write a COBOL paragraph that provides comprehensive SQL diagnostics. The paragraph should:
- Accept a statement identifier as input (e.g., "CUSTOMER-SELECT")
- Display SQLCODE with explanation for common codes (-180, -204, -206, -305, -530, -803, -811, -904, -911, -922)
- Display SQLERRMC (error message text)
- Display SQLERRD(3) (rows affected)
- Display the statement identifier for context
- For SQLCODE -911, recommend retry
- For SQLCODE -803, display "DUPLICATE KEY"
- Write the diagnostic information to both SYSOUT and a DB2 error log table
Exercise 33.7: Debugging Toolkit (Project)
Create a reusable COBOL copybook called DEBUGKIT that includes:
- Debug control fields (level, start/end record, active flag)
- A debug display paragraph with timestamp formatting
- An SQL diagnostic paragraph
- A file status diagnostic paragraph (interpreting common status codes: 00, 10, 22, 23, 35, 39, 46, 47, 48, 93, 97)
- A hex display utility paragraph
- An abend handler that displays diagnostic information before calling CEE3ABD
Test the copybook by COPY-ing it into a simple program and exercising each diagnostic facility.