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.
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.
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:
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, Alpha Nerd 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 in the words of the most interesting man in the world: Stay thirsty my friend.
How to Install IBM Access Client Solutions (ACS)
IBM i Data Obfuscation – Making Data Foggy Murky and Squinty
How to rename Fresche (BCD) Presto Library – XL_PRESTO
What is AS400 modernization?
IBM i ACS 5250 EMULATOR FONT – and other ridiculous mumbo jumbo
IBM i SQL statement to convert or compare hundred year date format
How to compare ‘100 Year Date’ to a Timestamp – aka – Weird AS400 iSeries Date formats
Modernize AS400 iSeries Queries – Convert to IBM i SQL
Use IBM i SQL to validate email addresses in Customer Master File