Modifying program logic
This section describes the Code Debug TSO commands that let you modify program logic by bypassing code segments, adding statements, and forcing logic changes.The SKIP, INSERT, and GOTO commands let you try out fixes dynamically without requiring any source code modification.
Bypassing code with the SKIP command
A code that you do not want to execute can be bypassed using the SKIP command. The SKIP command can be used with a statement, a range of statements, a label name, or an external procedure name.
With the SKIP command, there is no need to comment out code and recompile the procedure for it to take effect. For example, a call to a procedure that is not yet written can be simply bypassed without requiring a stub to be developed. For example, to skip procedure TRITSTP, the following commands are issued:
AFTER 29
KEEP TRIANGLE_TYPE
KEEP WORK_REC
GO
The KEEP commands were issued for TRIANGLE_TYPE and WORK_REC so the effect of the SKIP command can be seen for these variables. The following figure shows the results:
Note that WORK_REC and TRIANGLE_TYPE are automatically kept in the window as a result of the execution arrow at statement 29. The Keep window has been expanded with the SET KEEP n command so that the explicit keeps and automatic keeps are all displayed.
Result of Entering the SKIP Command
COMMAND ===> SCROLL===> CSR
NEXT LOGICAL INSTRUCTION IS TRIMINP1:30
000010 K TRIANGLE_TYPE > +0 PACKED
IN_REC @0020CBC0
---
000011 K 01 WORK_REC > 345
IN_REC @0020CBC0
---
000011 01 WORK_REC > 345
000010 TRIANGLE_TYPE > +0 PACKED
------ ----------------------------------------- After TRIMINP1:29/AMODE 31 <>
000028 TRIANGLE_TYPE = 0;
====>> A CALL TRITSTP (WORK_REC,
------ TRIANGLE_TYPE);
000030 TX = TRIANGLE_TYPE;
The parameter TRIANGLE_TYPE is left untouched as it has been initialized; however, the procedure can continue execution by processing any data that you move to the variable.
There are a couple of situations to be aware of when using the SKIP command. Setting a skip at a procedure statement or a PROC label bypasses the statement but not the entire procedure. All of the instructions generated by the statement, including the initialization code to set up the registers are bypassed and may cause unpredictable results. Also, use caution when skipping BEGIN and END statements.
When you skip a statement that sets a switch or flag, the execution path could change or end in an infinite loop. More subtly, the PL/I compiler generates multiple instructions for each PL/I verb. Some of these instructions can load base registers for instructions. Since a skip bypasses all instructions associated with the verb, a S0C1 or S0C4 can result.The SKIP command should be deleted in this case.
Use the DELETE SKIP command or the DS line command to delete the SKIP.
Inserting statements
You can insert Code Debug TSO commands, such as PEEK, GOTO, and PAUSE, using the IF...ELSE... constructs to your program. The capability to insert statements allows you to test fixes before you update the source code and actually recompile the program. Inserted statements are executed after the last logical statement as if they are part of the source code. Only one inserted command per line is permitted.
You can also dynamically insert SQL statements and prototype Db2 applications if you have Code Debug Db2 Extension and File-AID for Db2 installed. See to Using Code Debug for Db2 Extension for more information.
The following figure shows the effect of the inserted statements being executed. The PAUSE command can be used to set a breakpoint within a block of inserted Code Debug TSO commands or SQL statements. When the pause breakpoint is encountered, Code Debug TSO temporarily pauses execution, issues a message, and returns control to you, as shown.
Result of Executing Inserted Statements and Taking PAUSE
COMMAND ===> SCROLL===> CSR
PAUSE REQUESTED BY INSERTED COMMAND
IN_REC @0020FD50
---
000030 K 01 WORK-REC > 111
** END **
------ ---------------------------------------- Before TRIMINP1:27/AMODE 31 <>
000025 ANALYZE_NEXT_REC: PROC;
000026 READ FILE(INFILE) SET(IN_REC_PTR);
000027 IF ¬OUT_OF_RECS THEN DO;
'''''' IF WORK_REC = '345'
'''''' KEEP WORK_REC
MOVE '111' TO WORK_REC
=====> PAUSE
'''''' END-IF;
000028 TRIANGLE_TYPE = 0;
000029 CALL TRITSTP (WORK_REC,
------ TRIANGLE_TYPE);
000030 TX = TRIANGLE_TYPE;
000031 N_CNTR(TX) = N_CNTR(TX) + 1;
000032 END;
The Source display screen is designed after the ISPF/PDF editor. The source code itself cannot be edited, however, you can insert Code Debug TSO commands to the display-only source code by typing over the statement number area with the I (Insert) line command. Use the D (Delete) line command to delete any lines. The P (Peek) and K (Keep) line commands cannot be used on lines of inserted code. The syntax of the inserted statements is checked by Code Debug TSO before they are executed. If the syntax is incorrect, an error message is generated and the incorrect statement is highlighted when you press Enter.
INSERT Processing
You can enter the I (Insert) line command on a statement containing an executable verb and enter Code Debug TSO commands following the statement. Only one inserted command per line is permitted and the inserted line must be less than 61 characters long. You cannot insert at a line that will not accept a breakpoint. That is, the line must be executable. Be aware that unpredictable results could occur if you insert lines after the IF of an IF...THEN statement, an internal procedure call, or an internal function call. The reason for this is that Code Debug TSO internally generates an after breakpoint on the statement where the I line command is entered and interpretively executes the inserted statements only if the internal after breakpoint is reached. In other words, the inserted statements are associated with the code above them.
Placing the I line command on branching verbs such as END and RETURN is not permitted. A message INSERT NOT PERMITTED FOLLOWING verb is issued when you attempt to do so. If you wish to execute statements following the return from the actual performed paragraph, insert the statement after the last executable code in the out-of-line paragraph.
See to the INSERT command in the Command-and-syntax-reference for a list of commands that can and cannot be inserted in your program.
Redirecting logic with the GOTO command
The GOTO command forces logic changes by redirecting the next executable statement to elsewhere in the program. The command can be used to execute a branch, to bypass statements, to test a loop repeatedly, or to take an alternate path.