• 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
    ARCAD Software

    Modern IBM i development is no longer about choosing between reliability and agility. With ARCAD, IBM i teams can adopt true Git-based DevOps while preserving the control, automation, and stability their business-critical applications require.

    In this short customer video, hear directly from organizations including HSBC, Heartland Co-op, and BWI as they share how ARCAD helped them transform their development and delivery processes.

    Their results speak for themselves: shorter delivery times, reduced downtime, improved developer efficiency, better traceability, streamlined release processes, and easier rollback when needed.

    From Git integration with platforms such as GitHub, GitLab, Bitbucket, and Azure DevOps, to parallel development, automated deployment, and modernized IBM i workflows, ARCAD enables development teams to move faster without compromising quality or governance.

    Don’t just take our word for it. Hear what ARCAD customers have to say.

    Watch the 4-minute video now.

    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

    An Introduction to Python on IBM i, Part 2 Admin Alert: Risk and the Power i Hardware Upgrade

    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 Is Still Talking About Future Power Processors, Which Is Good
  • Who To Consult With On Your Cloud Strategy, And Who To Manage It
  • Guru: DateTime Rules Of Thumb
  • i-Rays Performance Analyzer Now Ready for Prime Time, Omniology Says
  • CNX Adds AI To Valence Development Tool
  • Q&A With IBM’s New GM Of Power, Hillery Hunter
  • When IBM i Skills Become A Resilience Risk
  • Guru: Load A Varying-Dimension Array With One SQL Fetch
  • You Have To Speak IBM’s Language If You Want To Be Heard
  • Raz-Lee Revs iSecurity Suite With 2026 Updates

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