• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Another Way to Pass Parms to SBMJOB

    October 5, 2011 Bruce Guetzkow

    Note: The code accompanying this article is available for download here.

    A couple of years ago I needed to develop a process where a group of items could be selected from a screen and a report listing those items could be generated. On the surface, a simple task. Of course, if you give a mouse a cookie, they’re going to want a glass of milk, or another report. . . and another. Again, not too complicated. All that should be needed is a way to submit a call to a variable list of programs. As long as each program being called has the exact same parameter list, you can use a program variable to contain the program name and submit the call.

    What happens if the parameter list is not the same for each program? What if the parameters for each program are vastly different? Although you can dynamically build the Submit Job (SBMJOB) command with different parameter lists, there is another way.

    Environment variables can be passed from a calling job to a called job in much the same manner as the Local Data Area (*LDA) is passed. When a job is submitted, a copy of the *LDA from the calling job is passed to the called job. There are now two separate jobs, each with its own independent copy of the data. Environment variables can be passed by changing one parameter on the SBMJOB command:

    CPYENVVAR(*YES) - the default is *NO
    

    Before you can submit the job you first need to set your environment variables. There are both CL commands and APIs at your disposal for managing them. The commands are:

    • ADDENVVAR–Add Environment Variable
    • CHGENVVAR–Change Environment Variable
    • RMVENVVAR–Remove Environment Variable
    • WRKENVVAR–Work with Environment Variables

    There are 10 APIs, but the three of most interest are:

    1. putenv–Change or Add Environment Variable
    2. getenv–Get Value of Environment Variable
    3. Qp0zDltEnv–Delete Environment Variable

    You will find prototypes for these APIs in the downloadable code.

    Environment variables are a “name=value” pair. The case-sensitive names can be just about anything, but should be something meaningful to you. You should also use the WRKENVVAR command to make sure that you don’t replace any existing variables.

    In the calling program, setting or changing an environment variable in RPG is as easy as:

    putenv( 'MyEnvVar=' + value );
    

    Remember that the environment variable name is case-sensitive. There must not be a space either before or after the equal sign. Values assigned must always be character, so if you have a date or numeric value you’ll have to convert it to character first. You can also check the return value to confirm that the environment variable has been set successfully (success is a return value of zero):

    if ( putenv( 'MyEnvVar=' + value ) = *zeros );
    

    You can submit the call to a program without passing a single parm as the values will be retrieved from the environment variables, provided that you change the CPYENVVAR parm on the SBMJOB command as indicated above. In the called program, retrieving the environment variables is just as easy:

    charvalue = %str( getenv( 'MyEnvVar' ) );
    		or
    numvalue = %dec( %str( getenv( 'MyEnvVar' ) ) : dec : pos );
    

    Since the “getenv” API returns a pointer you’ll need to use the “Get” or “Store Null-Terminated String” (%STR) built-in function to assign the value to a program variable. The first example is for character values, the second for numeric. All environment variables are stored as character, so you’ll need to use an appropriate method to convert that character value to the numeric or date data type desired.

    The result of this process is that you have a simple method of using the SBMJOB command from any HLL program, and no restriction as to the number of parms a program can have. You can learn more about environment variables in the IBM Information Center.

    Bruce Guetzkow, an independent IBM i programming consultant with GmanTech Consulting in southeastern Wisconsin, is a firm believer in practical programming. For over 25 years he has developed applications for IBM systems from mainframe to System/36 to IBM i on Power. You can read his Website blog, follow him on Twitter (@gmantechi), or catch him at a meeting of the Wisconsin Midrange Computer Professional Association (WMCPA), where he is the current webmaster. Send your questions or comments for Bruce to Ted Holt via the IT Jungle Contact page.



                         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

    System i Developer:  Join the Gurus at the RPG & DB2 Summit in St. Louis, October 17-19
    The 400 School:  LIVE Online Training RPG IV & COBOL Boot Camps
    Shield Advanced Solutions:  Access IBM i data & objects from Linux & Windows Servers using PHP

    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

    CYBRA Signs European Distributor for RFID and Barcode Products IBM Readies October Power Systems Announcements

    Leave a Reply Cancel reply

Volume 11, Number 29 -- October 5, 2011
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
The 400 School

Table of Contents

  • Call Again and Again and Again…
  • Another Way to Pass Parms to SBMJOB
  • Admin Alert: How to Retrieve Password Parameters for Auditors
  • Call Again and Again and Again…
  • Another Way to Pass Parms to SBMJOB
  • Admin Alert: How to Retrieve Password Parameters for Auditors

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