• 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
    Manta Technologies

    The Leader in IBM i Education!
    Need training on anything i?
    Manta is all you need.

    Spring Sale! Save 20% off any Manta Combination Package, including the complete IBM i Training Library. Now through April 30.

    130 courses and competency exams on:
    · IBM i operations
    · System Management and Security
    · IBM i Programming Tools
    · Programming in RPG, COBOL, CL, Java
    · Web Development
    · SQL, DB2, Query

    Product features:
    · Runs in every popular browser
    · Available 24/7/365
    · Free Student Reference Guides
    · Free Student Administration
    · Concurrent User License
    · Built-In IBM i Simulator

    You can download our 200-page catalog and take sample sessions at MantaTech.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

  • IBM i Has a Future ‘If Kept Up To Date,’ IDC Says
  • When You Need Us, We Are Ready To Do Grunt Work
  • Generative AI: Coming to an ERP Near You
  • Four Hundred Monitor, March 22
  • IBM i PTF Guide, Volume 25, Number 12
  • Unattended IBM i Operations Continue Upward Climb
  • VS Code Is The Full Stack IDE For IBM i
  • Domino Runs on IBM i 7.5, But HCL Still Working on Power10
  • Four Hundred Monitor, March 6
  • IBM i PTF Guide, Volume 25, Number 11

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 © 2023 IT Jungle