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

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    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

  • To Comfort The Afflicted And Afflict The Comfortable
  • How FalconStor Is Reinventing Itself, And Why IBM Noticed
  • Guru: When Procedure Driven RPG Really Works
  • Vendors Fill In The Gaps With IBM’s New MFA Solution
  • IBM i PTF Guide, Volume 27, Number 27
  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26

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