• 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
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    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