• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Parameterized RUNSQLSTM

    June 21, 2002 Timothy Prickett Morgan

    Hey, Ted:

    Can I pass parameters to an SQL statement in a source member before executing the Run SQL Statement (RUNSQLSTM) command? I’m sure there must be a simple way, but I’ve never seen any examples of this.

    For example, today I might like to have the SQL statement select company 005. Tomorrow I might want it to select company 007.

    — Darrell

    What you want is the ability to put placeholders in the SQL source and specify replacement arguments on the RUNSQLSTM command, as you can do with the Start Query Management Query (STRQMQRY) command.

    It may be worth the effort to write an RPG, COBOL, or C program that will build or update a source member for you.

    Another option is to use Qshell’s stream editor, sed. Most source-code editors I’ve used are for interactive editing, but batch editors do exist, although they’re rare. Sed is such a batch editor.

    As an exercise to prove the concept, I created a source member called UPDTCUSPAT (PAT to indicate pattern) with an SQL command in it. I put CCC as a placeholder for the company number:

    update customer         
       set creditlim = 0 
       where company = CCC  
    

    I copied source member UPDTCUSPAT to source member UPDTCUS in order to create a source member to hold the SQL statement that will be executed.

    I developed the necessary sed command in an interactive Qshell session:

    sed "s%CCC%002%g" 
       /qsys.lib/tholts.lib/sqlsrc.file/updtcuspat.mbr 
       >/qsys.lib/tholts.lib/sqlsrc.file/updtcus.mbr  
    

    This command tells Qshell to read updtcuspat, replacing every occurrence of CCC with 002, and to put the output into updtcus. That is, the stream editor doesn’t change the updtcuspat source member, but makes an updated copy of it.

    Then I wrote a CL program that takes a company number as a parameter, builds the sed command, executes the sed command to build UPDTCUS, and finally runs RUNSQLSTM:

    pgm &company                                               
                                                                   
    dcl &lib        *char  10 value('tholts')                  
    dcl &file       *char  10 value('sqlsrc')                  
    dcl &patternmbr *char  10 value('updtcuspat')              
    dcl &sqlcmdmbr  *char  10 value('updtcus')                 
    dcl &company    *char   3                                  
    dcl &shellcmd   *char 256                                  
                                                                   
    chgvar var(&shellcmd) +                                    
      value('sed "s%CCC%' *cat &company *cat '%g"' *bcat +
               '/qsys.lib/' *cat +                           
               &lib *tcat '.lib/' *cat +                     
               &file *tcat '.file/' *cat +                   
               &patternmbr *tcat '.mbr' *bcat +              
               '>/qsys.lib/' *cat +                          
               &lib *tcat '.lib/' *cat +                     
               &file *tcat '.file/' *cat +                   
               &sqlcmdmbr *tcat '.mbr')                      
    QSH       CMD(&SHELLCMD)                           
    RUNSQLSTM  SRCFILE(&LIB/&FILE) SRCMBR(&SQLCMDMBR) +
                              COMMIT(*NONE)                       
    

    It works, but I haven’t tried it in a production environment.

    — Ted

    Sponsored By
    TRAMENCO

    Introducing a New Source for Training and Mentoring. Follow this link to a vital new source for how-to technical information: www.tramenco.com.

    Unlike companies that offer training as an afterthought, The Training and Mentoring Company (Tramenco) is dedicated to just one thing: Advancing your career by giving you the skills you need to solve real-world business problems.

    You get the best information from the world’s leading experts–Howard Arner, Kelly Conklin, Don Denoncourt, Susan Gantner, Skip Marchesani, Glen Marchesani, Shannon O’Donnell, Craig Pelke, and Richard Shaler.

    Choose from a menu of training options to fit your needs: onsite seminars, public seminars, mentoring, consulting, books, CBTs, and Web-based training.

    And make plans to attend the 2002 iSeries Connection Conference, the multi-day, multi-track conference that was the only sold-out iSeries training event this year, co-sponsored by the Education Connection and Tramenco.

    For more information about Tramenco’s career enhancing opportunities, call (800) 421-8031 or go to www.tramenco.com.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: mgo_rc, Volume 2, Number 48 -- June 21, 2002

    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

    LAYOUT: An Improved DSPFFD Searching Message Text

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 48

This Issue Sponsored By

    Table of Contents

    • RPG II
    • Determining Whether a User Is Already Signed On, Take Two
    • Parameterized RUNSQLSTM

    Content archive

    • The Four Hundred
    • Four Hundred Stuff
    • Four Hundred Guru

    Recent Posts

    • Liam Allan Shares What’s Coming Next With Code For IBM i
    • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
    • VS Code Will Be The Heart Of The Modern IBM i Platform
    • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
    • IBM i PTF Guide, Volume 27, Number 25
    • 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

    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