• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Prompting Stored Procedures

    February 22, 2021 Paul Tuohy

    In this tip I would like to touch on two items, in relation to stored procedures, that may have escaped your notice: prompting stored procedures and/or parameters (in Run SQL Scripts) and passing parameters by name.

    I must admit that, as I have gotten older, my ability to remember the names and parameters for stored procedures has, shall we say, decreased. At this stage, I am lucky if I can remember which library/schema one of my stored procedures is in!

    A case in point. I recently received an e-mail about a stored procedure I had written about (back in 2015) which performed a PIVOT on a table. The email did not mention the article (An SQL Pivot Procedure). or more importantly, the name of the stored procedure. Now, I could have gone to the IT Jungle website and used the wonderful search feature to find my article but I must admit to a dislike of reading my own articles and Run SQL Scripts happened to be open in front of me.

    I did have an idea of which library (schema) the procedure was in, so I started by setting my path to that schema. I then typed in CALL and pressed F4. I was presented with a list of all the procedures in my path:

    I guessed that DO_PIVOT was the one I was looking for (as opposed to DO_PIVVOT), so I selected it in the list and pressed enter. DO_PIVOT was duly placed after my call.

    But I had no idea of the parameters or their sequence, so I typed in open and close parentheses after the procedure name, placed the cursor between the parentheses and pressed F4 again. I was duly presented with a list of the parameters. If you move the cursor down the list you will see the definition of each parameter.

    I selected all parameters (I held down the Shift key and clicked on the first and last parameters in the list) and pressed Enter.

    Unfortunately, the parameters were all placed on one line, so I performed a quick tidy up and placed a parameter on each line. Then I assigned values to each parameter and ran the statement.

    And that brings us to the second part of the tip. When you call a stored procedure, you have the choice of defining parameters by position or by name. The procedure could have been called using positional parameters:

    call DO_PIVOT('SQLSTAND',
                 'SALES', 
                 'SALES_PERSON', 
                 'SALES', 
                 DEFAULT, 
                 'REGION');
    

    But one of the advantages of naming the parameters (apart from the obvious legibility) is that you do not need to be concerned about the sequence of the parameters — the name defines the parameter. The call could just as easily have been written as:

    call DO_PIVOT(GROUP_COLUMN => 'REGION',
                 AGG_FUNCTION => DEFAULT,
                 VALUE_COLUMN => 'SALES', 
                 PIVOT_COLUMN => 'SALES_PERSON', 
                 FOR_TABLE => 'SALES', 
                 FOR_SCHEMA => 'SQLSTAND');
    

    Or you could use a combination of positional and named parameters but once you use a named parameter then all following parameters must be named as well.

    call DO_PIVOT('SQLSTAND',
                 'SALES', 
                 PIVOT_COLUMN => 'SALES_PERSON', 
                 VALUE_COLUMN => 'SALES', 
                 AGG_FUNCTION => DEFAULT, 
                 GROUP_COLUMN => 'REGION'); 
    

    I also find the ability to prompt parameters invaluable when it comes to using some of the myriad of IBM i Services and Db2 for i Services.

    I am truly thankful to the ACS team in Rochester for developing features that keep me productive as I totter toward old age.

    Paul Tuohy, IBM Champion and author of Re-engineering RPG Legacy Applications, is a prominent consultant and trainer for application modernization and development technologies on the IBM Midrange. He is currently CEO of ComCon, a consultancy firm in Dublin, Ireland, and partner at System i Developer. He hosts the RPG & DB2 Summit twice per year with partners Susan Gantner and Jon Paris.

    RELATED STORY

    An SQL Pivot Procedure

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, DB2 for i, FHG, Four Hundred Guru, IBM i, Run SQL Scripts

    Sponsored by
    Rocket Software

    Two Steps Forward, No Steps Back

    For over 35 years, Rocket Software’s solutions have empowered businesses to modernize their infrastructure, unlock data value, and drive transformation – all while ensuring modernization without disruption.

    LEARN MORE

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    As I See It: Sunshine Or Oxygen? Tech Data’s Take On Certified Pre-Owned IT Gear

    Leave a Reply Cancel reply

TFH Volume: 31 Issue: 14

This Issue Sponsored By

  • Fresche Solutions
  • IBM
  • Precisely
  • WorksRight Software
  • New Generation Software

Table of Contents

  • iTech Solutions Keeps You In The Know With VERIFi
  • Tech Data’s Take On Certified Pre-Owned IT Gear
  • Guru: Prompting Stored Procedures
  • As I See It: Sunshine Or Oxygen?
  • Looking For Some Insight On IBM i Security

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