• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • How To Print a Pointer Value

    November 3, 2010 Ted Holt

    Over the past few months I’ve been working on more articles dealing with the use of pointers in RPG programs. While I was working on my demo programs, I ran into a little snag while verifying that everything was working correctly. Let me tell you what I ran into and how I got around it.

    I wanted to double-check the value of all the pointer variables. In the interactive green-screen debugger, which I was using, seeing the value of a pointer is no problem. Place the cursor on the pointer variable name and press F11, or use the EVAL command. The debugger displays the pointer’s value in hexadecimal.

    But I don’t always want to step through a program pressing F11. Another favorite technique I use is to write miscellaneous information to a spool file, which I can then read to track the behavior of a program (or module).

    So how do you print the hex representation of a pointer? You can’t put the pointer in printer file DDS or O specs. (DDS has no pointer type. Put a pointer in O specs and you’ll get error RNF7601.) I ended up writing a function subprocedure that, given a pointer, builds a string of hex digits, the same string you see when you press F11 in the debugger. I call it PtrToHex (Pointer to Hexadecimal), and that’s what I want to share with you today.

    First, here’s the command to create a printer file for the debugging trail.

    CRTPRTF FILE(xxx/DEBUGPRTF)
    

    Of course, you can use QSYSPRT or some other program-described printer file if you prefer.

    Here’s a short program that reads QIWS/QCUSTCDT, allocating memory for each record and printing the pointer value in hex for each allocation.

    /define debugging
    
    H dftactgrp(*no) actgrp(*new)
    H option(*srcstmt: *nodebugio)
    
    FQCustCdt  if   e             disk
     /if defined(debugging)
    FDebugPrtf o    f  132        printer
     /endif
    
    D gPtr            s               *
     /if defined(debugging)
    D DbgPrtLine      ds           132
     /endif
    
    D PtrToHex        pr            16a   varying
    D  inPtr                          *
    D  inSize                        5u 0 value options(*nopass)
    
     /free
         *inlr = *on;
         dow '1';
            read qcustcdt;
            if %eof();
               leave;
            endif;
            gPtr = %alloc(20);
     /if defined(debugging)
            DbgPrtLine = LstNam + ' ' + PtrToHex (gPtr);
            write DebugPrtf DbgPrtLine;
     /endif
            // do other stuff
            dealloc gPtr;
         enddo;
         return;
     /end-free
    
    P PtrToHex        b
    D                 pi            16a   varying
    D  inPtr                          *
    D  inSize                        5u 0 value options(*nopass)
    D** locals
    D DS              ds
    D  Ptr
    D  Num                          20u 0 overlay(DS: 9)
    D Size            s                   like(inSize)
    D MaxSize         s                   like(inSize)
    D MaxPtrAddrSize  c                   const(16)
    D HexString       s             16a   varying
    D Digits          s             16a   inz('0123456789ABCDEF')
    D Number          s             20u 0
    D Rem             s              5u 0
    D Base            c                   const(16)
     /free
         Ptr = inPtr;
         Number = Num;
         if Number = *zero;
            return '*NULL';
         endif;
    
         select;
         when %parms()< 2;
            MaxSize = MaxPtrAddrSize;
         when inSize = *zero or inSize > MaxPtrAddrSize;
            MaxSize = MaxPtrAddrSize;
         other;
            MaxSize = inSize;
         endsl;
    
         dow Size < MaxSize;
            Rem = %rem(Number: Base);
            HexString = %subst(Digits:Rem+1:1) + HexString;
            Number = %div(Number: Base);
            Size += 1;
         enddo;
         return HexString;
     /end-free
    P                 e
    

    Here’s the report.

    Henning  E1D840C14A002000
    Jones    E1D840C14A002030
    Vine     E1D840C14A002060
    Johnson  E1D840C14A002090
    Tyron    E1D840C14A0020C0
    Stevens  E1D840C14A0020F0
    Alison   E1D840C14A002120
    Doe      E1D840C14A002150
    Thomas   E1D840C14A002180
    Williams E1D840C14A0021B0
    Lee      E1D840C14A0021E0
    Abraham  E1D840C14A002210
    

    PtrToHex has a second, optional parameter that I didn’t use in this example. When working on the demo programs, I realized that I only needed to see the last four or five hex digits of each pointer value. The second parameter tells the number of low-order digits to print. The default is 16.

    Notice that all the debug code is conditioned to the debugging compiler condition. If this were a real program, I would change the /DEFINE to /UNDEFINE before putting this code into production.

    If you use pointers in your programming, I hope you find the PtrToHex routine beneficial. If you don’t use pointers, you’re in for some fun! In the near future I will show you what I mean.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Raz-Lee Security

    Start your Road to Zero Trust!

    Firewall Network security, controlling Exit Points, Open DB’s and SSH. Rule Wizards and graphical BI.

    Request Demo

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Bytware:  FREE Webinar! Scan your IBM i, AIX, and Linux Directories for Viruses. Nov. 17, 9 am PT
    iSeries DevCon2010:  Get 3 days of IBM i training and 365 DAYS OF VALUE, Nov 15-17, Las Vegas
    neuObjects:  Introducing NEUEDIT, a unique and powerful GUI database editor. FREE 60-day download

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    SoftLanding Announces Sale on New IBM i Package Smackdown: Linux on X64 Versus IBM i on Entry Power 7XXs

    Leave a Reply Cancel reply

Volume 10, Number 34 -- November 3, 2010
THIS ISSUE SPONSORED BY:

SEQUEL Software
neuObjects
WorksRight Software

Table of Contents

  • An Introduction to Python on IBM i, Part 2
  • How To Print a Pointer Value
  • Admin Alert: Risk and the Power i Hardware Upgrade

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23
  • SEU’s Fate, An IBM i V8, And The Odds Of A Power13
  • Tandberg Bankruptcy Leaves A Hole In IBM Power Storage
  • RPG Code Generation And The Agentic Future Of IBM i
  • A Bunch Of IBM i-Power Systems Things To Be Aware Of
  • IBM i PTF Guide, Volume 27, Numbers 21 And 22

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle