PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Little or unknown "Debugger" functions

View previous topic View next topic Go down

Little or unknown "Debugger" functions

Post  maran on Thu Jul 28, 2011 12:03 pm

%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'

- 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 WorkDS1 ds occurs(3)
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.)

Posts : 442
Join date : 2009-07-24

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum