• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • A Solution to the Numeric Parameter Problem

    May 19, 2004 Hey, Ted

    A common gripe I hear over and over again in midrange circles concerns the way numeric parameters of a CL CALL command are passed from the command line and from the CMD and RQSDTA parameters of the Submit Job (SBMJOB) command. I found a way around this problem.

    A brief explanation of the problem seems in order. When a CALL command is executed within a CL program, variable parameters are passed as they are defined, but literals are passed with default formats.

    • Character literals that are less than 32 characters are padded with blanks to a length of 32 characters.

    • Trailing blanks are removed from character literals longer than 32 characters so that only significant characters are passed to the caller.

    • Numeric literals are passed as if they were defined as 15-digit packed-decimal numbers with five decimal digits.

    When CALL is executed from a command line or from within SBMJOB, all parameters are passed according to these rules. This results in screwy errors, like garbage in character fields and data decimal errors.

    I faced this issue when I wanted to change a CL program to submit another program to batch, rather than call the program directly. At first I thought my only choice was to change the way the numeric parameters were defined in the called program. That is, I would have had to redefine the numeric parameters as 15,5. However, that would have been too much trouble, since the program is still called from other programs, and those calling programs also would have had to be modified to pass the parameters to the called program in the 15,5 format.

    The method I found lets me have my cake and eat it, too. I was able to change the program to accept numeric parameters in their original formats or as 15,5 packed-decimal numbers. To illustrate, here is an RPG IV program that accepts one numeric parameter, defined as five digits with no decimal places.

    FQSysPrt   O    F  132        Printer                            
                                                                     
    C     *Entry        PList                                        
    C                   Parm                    TheNumber         5 0
    C                                                                
    C                   Except    PrintLine                          
    C                   Eval      *InLR = *On                        
                                                                     
    OQSysPrt   E            PrintLine      1                         
    O                                              'The number is '  
    O                       TheNumber     J                          
    

    This program can be called from RPG programs. It can be called from CL programs if the parameter is passed as a five-digit packed-decimal variable with zero decimal places. Calling it from a command line only works if you use a trick like passing a three-byte hexadecimal literal, a technique I use during development and testing but not in production.

    Here is the revised source code. This version accepts the parameter in the original format, as well as in 15,5 format.

    FQSysPrt   O    F  132        Printer                        
                                                                 
    D PNumber         DS             8                           
    D  Number3                1      3P 0                        
    D  Byte3                  3      3A                          
    D  Number8                1      8P 5                        
    D  Byte8                  8      8A                          
    D                                                            
    D TheNumber       s              5P 0                        
                                                                 
    C     *Entry        PList                                    
    C                   Parm                    PNumber          
    C                                                            
    C                   Select                                   
    C                   When      %BitAnd(Byte3:X'0F') = X'0D' OR
    C                             %BitAnd(Byte3:X'0F') = X'0F'   
    C                   Eval      TheNumber = Number3            
    C                   When      %BitAnd(Byte8:X'0F') = X'0D' OR
    C                             %BitAnd(Byte8:X'0F') = X'0F'     
    C                   Eval      TheNumber = Number8              
    C                   Other                                      
     * error: invalid parameter format
    C                   Eval      TheNumber = -99999               
    C                   EndSl                                      
    C                                                              
    C                   Except    PrintLine                        
    C                   Eval      *InLR = *On                      
                                                                   
    OQSysPrt   E            PrintLine      1                       
    O                                              'The number is '
    O                       TheNumber     J                        
    

    If the parameter is passed to this program in the original 5,0 format, the digit portion (rightmost four bits) of the third byte will contain a hexadecimal digit of D or F. If the parameter is passed in the 15,5 format, the eighth byte will contain hex D or F.

    The %BITAND built-in function “ands” these bytes with hex 0F, which zeros out the zone (leftmost four bits) and leaves the digit portion intact. The resulting value is compared to hex D (the sign of a negative number) and hex F (the sign of a positive number) in order to determine which of the two formats the calling program used.

    As a result, I did not have to change any callers of the program and was able to change the CALL in one program to SBMJOB. As a bonus, I can also run the program directly from the command line.

    –Dominic Lefevre

    This illustration reminds me of a technique I have used in the System/36 environment. RPG II programs pass numeric parameters in zoned decimal format, while native programs pass them in packed decimal format. I have written RPG III and RPG IV programs that could accept either format.

    Thanks for sharing this technique with readers of Four Hundred Guru, Dominic.

    –Ted

    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

    Robot/SAVE Picks Up Where Bad Backups Leave Off IBM Chases Vintage OS/400, HP-UX Servers with the i5

    Leave a Reply Cancel reply

Volume 4, Number 17 -- May 19, 2004
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
iTera
WorksRight Sofware
Damon Technologies

Table of Contents

  • Date Handling in RPG IV
  • A Solution to the Numeric Parameter Problem
  • Read a Data Area As a One-Row Table with SQL
  • Admin Alert: A Lotus Notes Adjustment for Fighting Spam

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