RPG Debug – Display Pointer Data 

 July 21, 2017

By  NickLitten

Pointing at Pointers and laughing aka “How to Display Pointer Data”

RPG has all kinds of different data types. In the olden days of RPG, we only really thought in terms of character variables and numeric variables (signed numeric and packed numeric).  But as the language has advanced and adopted new technologies, methods of talking to the web and kept up with enormous increases in data sizes and hardware technology – lots of new variables  have become available to us: variable length fields, timestamps, datefields, binary, graphics, blobs, clobs and of course – POINTERS.

So what is a Pointer?

I like to think that a pointer is like an address to a house – it’s not the house itself –  it is just pointing at something and leading you to it. So, you cant DEBUG an address and expect to the the contents of the house. You need to follow it to the house first. Once you understand that, you might ask how to Display Pointer Data while debugging.

Debugging programs that use pointers manes you need to format your requests for “looking at the pointer data” in a aslightly differnet way.

I just found this excellent section in the ILE RPG PROGRAMMERS GUIDE which says:

Displaying Data Addressed by Pointers

If you want to see what a pointer is pointing to, you can use the EVAL command with the :c or šŸ˜” suffix. For example, if pointer field PTR1 is pointing to 10 bytes of character data,

EVAL PTR1:c 10

will show the contents of those 10 bytes.

You can also show the contents in hexadecimal using:

EVAL PTR1:x 10

This would be especially useful when the data that the pointer addresses is not stored in printable form, such as packed or binary data.

If you have a variable FLD1 based on basing pointer PTR1 that is itself based on a pointer PTR2, you will not be able to evaluate FLD1 using a simple EVAL command in the debugger.

Instead, you must explicitly give the debugger the chain of basing pointers:

===> EVAL PTR2->PTR1->FLD1

For example, if you have the following definitions:

debug RPG Pointers
dcl-s pPointers pointer; dcl-ds pointers based(ppointers);   p1 pointer;   p2 pointer; end-ds; dcl-s data1 char(10) based(p1); dcl-s data2 char(10) based(p2);

you can use these commands in the debugger to display or change the values of DATA1 and DATA2:

===> eval pPointers->p1->data1

===> eval pPointers->p2->data2 = 'new value'

To determine the expression to specify in the debugger, you start from the end of the expression with the value that you want to evaluate: data1

Then you move to the left and add the name that appears in the BASED keyword for the definition of data1, which is p1: p1->data1

Then you move to the left again and add the name that appears in the BASED keyword for the definition of p1, which is pPointers: pPointers->p1->data1

The expression is complete when the pointer that you have specified was not defined with the BASED keyword. In this case, pPointers is not defined as based, so the debug expression is now complete.

===> eval pPointers->p1->data1


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

Iā€™m always looking for awesome input, feedback and critique!