• 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
    New Generation Software, Inc.

    IBM Query/400? DB2 Web Query?

    Compiled Report Programs?

    You believe in IBM i and Db2 on i, and your users might share your enthusiasm – if they weren’t dependent on unsupported query software, legacy report programs, and CSV file transfers.

    NGS-IQ is built for IBM i. It simplifies query creation, automates query execution, and empowers users with visualizations, reports, Excel files, multidimensional models, and more.

    Request a demo or watch an on demand video.

    Talk to us at COMMON PowerUp.

    www.ngsi.com – 800-824-1220

    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

    Using Parameter Markers with SQL Functions Admin Alert: The Pitfalls of Duplicating Data to a Test Library

    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

  • Brace Yourself: Another Power Systems Price Hike Coming May 1
  • Updates Announced for IBM i BRMS And SMTP Email Client
  • AI Will Be Front And Center At POWERUp 2026 Next Week
  • IBM i PTF Guide, Volume 28, Number 16
  • Spring IBM i Tech Refreshes Will Come A Bit Later This Year
  • You Are Much More Than Power Systems, And So Are We
  • Startup Seeks The “Golden Path” for IBM i Modernization
  • What Can IBM Do To Make The Future Power S1112 Mini System Compelling?
  • IBM i PTF Guide, Volume 28, Number 15
  • Bob 1.0 Users Bugged By Lack Of One Feature

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