• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Creating An RPG Stored Procedure With Parameters

    January 20, 2025 Mike Larsen

    There are times we need to build processes that will be used across different platforms. An example is a pricing routine. When a system needs to get pricing, we need to make sure the price the customer pays is the same regardless of how the order was created in our system.

    One way to create this functionality is using web services. Another way we can provide this functionality is through stored procedures. This series of tips will focus on different ways we can build stored procedures on IBM i.

    For the first part, I created an RPG program (Figure 1) that accepts an input parameter and sends an output parameter back. The program is very simple, but illustrates what we’re looking to achieve. The source code for the program is available to download.

    Figure 1. RPG program

    The program receives a message as input, then creates an output message to return to the consumer. It’s not very exciting, but it satisfies the requirement. Next, I build an SQL script to catalog the RPG program as a stored procedure (Figure 2).

    Figure 2. Catalog the RPG program as a stored procedure

    Let’s step through this script. On line 17, I’m telling the system that I’d like to create or replace a stored procedure that resides in library MLLIB. The stored procedure name is MLRSTRPRC1.

    Lines 19 and 20 define the input and output parameters for the stored procedure. They are defined the same as I defined them in the RPG program.

    Line 23 indicates the stored procedure will be utilizing an RPG program. Not Deterministic means the procedure might not return the same result each time it is called.

    Line 24 points to the location of the RPG program that will be invoked in the procedure.

    Finally, on line 25, Parameter Style General indicates the parameters are passed to an external program.

    In the comments section of the program (line 8), I’ve included the statement I used to create the stored procedure.

    Once the script is created, I can test it by running it in ACS. In Run SQL Scripts, call the procedure (Figure 3).

    Figure 3. Call the stored procedure from ACS

    I’m passing a parameter Hello as input to the script. Since the second parameter is an output parameter being passed back to me, I use a placeholder (question mark) indicating so. When I run the script, ACS displays the result in the messages view (Figure 4).

    Figure 4. Stored procedure result

    This is the first part of a series that will show different aspects of using stored procedures. In the next part, I’ll show how to create a stored procedure that uses RPG to return a result set back to the consumer.

    Mike Larsen is a director of information technology at Auburn Pharmaceutical and has been working with IBM i systems for over 20 years. He specializes in RPG, CL, and SQL and recently has been working with PHP and Python. Current projects have given Mike the opportunity to work with generating and parsing XML and JSON from SQL and consuming SOAP and REST web services. Although his main area of expertise is on IBM i, Mike has a passion for learning other languages and how he can integrate other platforms with IBM i.

    RELATED STORIES

    Guru: Creating A Web Service With Basic Authentication

    Guru: Parsing JSON That Has Spaces In The Key

    Guru: Partitioning Result Sets Using SQL

    Guru: Comparing IFS Directories Using SQL

    Guru: String Manipulation Using SQL

    Guru: Regular Expressions, Part 1

    Guru: Regular Expressions, Part 2

    Guru: Debugging SQL Stored Procedures With ACS

    Guru: Creating PDF Documents With Python

    Guru: Creating Excel Spreadsheets With Python

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, ACS, FHG, Four Hundred Guru, IBM i, RPG, Run SQL Scripts

    Sponsored by
    New Generation Software

    “Tricks with Spool Files using SQL“

    A FREE Webinar featuring Simon Hutchinson, founder of RPGPGM.com

    We know you want to learn new skills. But you don’t live near a user group, and your job and other responsibilities make it difficult to attend conferences. So, we’re bringing IBM i Champion, Simon Hutchinson, to you.

    February 6, 2025, 11am Pacific/2pm Eastern

    RSVP: ngsi.news/spool

    This session is open to all IBM i professionals.

    Visit www.ngsi.com to learn more about our NGS-IQ query, reporting, and analytics solution.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Beta For RPG Coding Assistant On Track for 2Q25 2025 IBM i Predictions, Part Two

    One thought on “Guru: Creating An RPG Stored Procedure With Parameters”

    • ema tissani says:
      January 21, 2025 at 1:12 pm

      I noticed that in simple cases (i.e. not output parms) via external interfaces like JDBC, you can CALL lib.pgm1 without declaring the stored procedure construction, just a *PGM suffices

      Reply

    Leave a Reply Cancel reply

TFH Volume: 35 Issue: 2

This Issue Sponsored By

  • Maxava
  • WorksRight Software
  • New Generation Software
  • Manta Technologies
  • Raz-Lee Security

Table of Contents

  • Talking Power Systems And IBM i With Bargav Balakrishnan
  • 2025 IBM i Predictions, Part Two
  • Guru: Creating An RPG Stored Procedure With Parameters
  • Beta For RPG Coding Assistant On Track for 2Q25
  • IBM i PTF Guide, Volume 27, Numbers 1 And 2

Content archive

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

Recent Posts

  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

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