• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Stuffing Five Digits Into Four, Take 2

    October 25, 2006 Hey, Ted

    Your recent article, Stuffing Five Digits into Four, is a trip in the way, way back machine for me. I had to do this very thing on System/3 in RPG II! I’m writing to let you know that there is a way to stuff those five digits into four using native I/O.

    As you’ve discovered, RPG’s ‘B’ data type limits you to 4 digits; it’s in the manual, but that’s where data types ‘B’ and ‘I’ differ. ‘B’ is intended to preserve x digits, from 0000 to 9999 (including sign) but the newer ‘I’ is intended to emulate the C world’s maximum value based on number of bits used for storage.

    You may be scratching your head as to why the heck I’m babbling about ‘I’ data type. Well, using RPG IV’s H specification EXTBININT(*YES), we can make RPG read and write those binary fields as though they were integers.

    Note that we still can’t read/write a full 5 (or 10) digits; integer storage is based on the number of bits available, so a B4 can only hold 15 bits (minus one) of information, along with the sign (16th bit) or 32767. A normal RPG packed-decimal, five-digit number could hold a number as large as 99999 (with sign.) So there’s still a limitation on the range of numbers that can be stored in a DDS B type field.

    Here’s a little example that may help. First, consider the DDS for a physical file BINARY, which contains binary fields.

    A          R SAMPLER             
    A            KEY            5S 0 
    A            B4             4B 0 
    A            B9             9B 0 
    A            TEXT          50A
    

    Now, let’s put some data in the file. First, we use the SQL method you wrote about.

    INSERT INTO "BINARY" VALUES(4, 32767, 2147483647, 'Inserted via sql')
    

    Now, let’s use native I/O.

    h extbinint(*yes) debug                                
    fqad1000pf uf a e             disk                     
                                                           
    c/free                                                 
          *inlr = *on;                                     
          read sampler;                                    
          dump;                                            
          key = 1;                                         
          text = %char(%len(b4)) + ', ' + %char(%len(b9)); 
          dsply text;                                      
          b4 = (2**15)-1;                                  
          b9 = (2**31)-1;                                  
          text = 'test with extbinint(*yes)';              
          write sampler;                                   
          return;
    

    Note that the dump will show the full values.

    Use SQL to take a look at the data that was inserted and you’ll see that both methods do the trick.

    select * from binary
    
    KEY       B4              B9   TEXT                     
    ===  =======   =============   =========================
      4   32,767   2,147,483,647   Inserted via sql         
      1   32,767   2,147,483,647   test with extbinint(*yes)
    

    Nice tip–it might be a great lead-up to an explanation of binary versus integer, and why we should never use the B data type in RPG IV (APIs want/supply integer data, and B will truncate.)

    –Buck Calabro

    I want to thank Buck for this information and for his excellent example. My thanks also to Barbara Morris (of IBM), Birgitta Hauser, Larry Hegler, ” rgad”, and Kevin Wright for giving me the same information. I am thrilled to learn I was mistaken, because I happen to need to use native I/O to stuff five digits into a four-digit binary field in a project I’m currently working on.

    I often feel that I need to know more than I am capable of knowing. There is so much information to keep up with. Am I alone?

    Also, the article that Buck recommends I write was actually written more than three years ago in this newsletter. You can see it here: When a 10-Digit Variable Won’t Hold a 10-Digit Number.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Maxava

    Migrate IBM i with Confidence

    Tired of costly and risky migrations? Maxava Migrate Live minimizes disruption with seamless transitions. Upgrading to Power10 or cloud hosted system, Maxava has you covered!

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    nuBridges:  Leading provider of secure FTP on the iSeries
    Magic Software Enterprises:  Design IT, Control IT, Monitor IT with iBOLT
    COMMON:  Join us at the Spring 2007 conference, April 29 – May 3, in Anaheim, California

    iTera Offers Big Discounts on Echo2 Software for New CBUs SoftLanding Systems Acquired By CICS Specialist Unicom Systems

    Leave a Reply Cancel reply

Volume 6, Number 39 -- October 25, 2006
THIS ISSUE SPONSORED BY:

Advanced Systems Concepts
Profound Logic Software
Guild Companies

Table of Contents

  • Using Parameter Markers with SQL Functions
  • Stuffing Five Digits Into Four, Take 2
  • Admin Alert: The Pitfalls of Duplicating Data to a Test Library

Content archive

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

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • 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

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