One of my coworkers was having a strange problem the other day, and we were using the source debugger to trace down the cause. We figured out the problem eventually, but in the course of our work, I discovered some debugger commands and options that I was previously unaware of. Since I have been using the debugger for...umm...awhile now, I was surprised to discover something new, so I thought I'd share what I learned with you.
%SUBSTR Built-In Function
This function is great when you're working with large strings. You can view a segment of a string as shown below (assume that StringFldA = 'abcdefghijklmnopqrstuvwxyz'):
Debug command: EVAL %SUBSTR(StringFldA 12 5)
Displayed result: %SUBSTR(StringFldA 12 5) = 'lmnop'
This is convenient when working with larger string fields. You can also use the %SUBSTR function to set the value of a specific portion of a string. For me, this is the more useful of these two functions.
Debug command: EVAL %SUBSTR(StringFldA 12 5) = 'xxxxx'
Displayed result: %SUBSTR(StringFldA 12 5) = 'xxxxx'
Debug command: EVAL StringFldA
Displayed result: StringFldA = 'abcdefghijkxxxxxqrstuvwxyz'
You can also use %SUBSTR to set a conditional breakpoint or watch condition. For example, the following code would stop execution only when positions 12 thru 16 of StringFldA are 'xxxxx':
Debug command: BREAK 100 when %SUBSTR(StringFldA 12 5) = 'xxxxx'
Or you could watch for those same positions to change by using this watch condition:
Debug command: WATCH %SUBSTR(StringFldA 12 5)
This way, anytime the contents of positions 12 thru 16 change, program execution stops and you are notified.
%INDEX Built-In Function
The %INDEX function is handy when you're using multiple-occurrence data structures. It's also useful in combination with _QRNU_DSI_xxxx (where xxxx = the name of a multi-occurrence data structure). The command EVAL _QRNU_DSI_xxxx returns the current occurrence of a multiple-occurrence data structure. Using the %INDEX function will change the current occurrence. See the example below:
d StringA 10a
d StringB 25a
Debug command: EVAL _QRNU_DSI_WorkDS1
Displayed result: 1 (or whatever the current occurrence of WorkDS1 is)
Debug command: WorkDS1 = %INDEX(3)
Displayed result: WorkDS1 = %INDEX(3) = 3
(Interrogated subfields will now reflect the values the of third occurrence of the data structure.)
Parting Shot
In our shop, many of the field names are really long, so if you don't type well (or just don't like to type), then using the EQUATE debug command can help you. This command allows you to define an "alias" for a field name, expression, or command. For instance...
Debug command: EQUATE SmName This_is_a_really_long_field_name
You can then find the value of "This_is_a_really_long_field_name" by keying the command shown below:
Debug command: EVAL SmName
The EQUATE command can also be used to create a macro of sorts. This is done by assigning an alias to a complete command. Here's an example:
Debug command: EQUATE SmCmd EVAL %substr(StringA,5,5)
By keying SmCmd and pressing Enter, you can display the value of positions 5 thru 9 of the StringA variable.
So the next time you start testing a program or chasing a bug, remember these, and you might save yourself some headaches. Good luck and happy hunting.
Jeff Olen is an analyst in the IS department at Costco Wholesale in Issaquah, Washington (just outside Seattle). He has nearly 20 years of experience on midrange systems and has developed software for a wide range of applications. He may be reached at
LATEST COMMENTS
MC Press Online