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

    DevSecOps & Peer Review – The Power of Automation

    In today’s fast-paced development environments, security can no longer be an afterthought. This session will explore how DevSecOps brings security into every phase of the DevOps lifecycle—early, consistently, and effectively.

    In this session, you’ll discover:

    • What DevSecOps is and why it matters?
    • Learn how to formalize your security concerns into a repeatable process
    • Discover the power of automation through pull requests, approval workflows, segregation of duties, peer review, and more—ensuring your data and production environments are protected without slowing down delivery.

    Whether you’re just getting started or looking to enhance your practices, this session will provide actionable insights to strengthen your security posture through automation and team alignment to bring consistency to the process.

    Watch Now!

    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

  • What You Will Find In IBM i 7.6 TR1 and IBM i 7.5 TR7
  • Three Things For IBM i Shops To Consider About DevSecOps
  • Big Blue Converges IBM i RPG And System Z COBOL Code Assistants Into “Project Bob”
  • As I See It: Retirement Challenges
  • IBM i PTF Guide, Volume 27, Number 41
  • Stacking Up Power11 Entry Server Performance To Older Iron
  • Big Blue Boosts IBM i Support In Instana, Adds Tracing
  • It Is Time To Tell Us What You Are Thinking And Doing
  • IBM i PTF Guide, Volume 27, Number 40
  • The GenAI Boom Is Only Slightly Louder Than The Dot Com Boom

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