• 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:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

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

    Sponsored by
    JAMS Software

    One Scheduler. IBM i, Windows, Linux, and More.

    IBM i teams trust JAMS to schedule and orchestrate jobs across every platform in their environment. Centralized visibility, cross-platform dependency management, and alerts that reach the right person before the business feels it.

    Fewer than 5% of IBM i shops run IBM i only. The rest are managing cross-platform dependencies — often without a clear picture of how they connect. JAMS draws that map, enforces those dependencies automatically, and gives your team a single place to monitor, manage, and recover when something goes wrong.

    If you are running hundreds of CL scripts and custom RPG processes, bring them as-is. JAMS runs them exactly as they do today — except now they are visible, monitored, and part of an orchestrated workflow instead of scattered across folders only one person knows about.

    No consumption-based pricing. No surprise bills when your workload spikes. You pay based on how many machines JAMS talks to — that’s it.

    Learn More → https://jamsscheduler.com/lp/ibm-i

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) 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 ReplyCancel 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

  • IBM i PTF Guide, Volume 28, Number 28: A Crazy Number of Security Vulnerability Patches
  • Inside The Encryption Key Management Changes In IBM i 7.6
  • FalconStor Moved To The Blue Lagoon, And Is Poised For Growth Because Of It
  • Guru: Claude’s SQL Tip
  • Astera Makes Extracting Legacy Report Data an AI Specialty
  • IBM i PTF Guide, Volume 28, Number 27
  • Welcoming The New IBM i Chief Architect And Other New Top Brass
  • A Deep Dive Into That Power S1112 Entry Power11 Server
  • Guru: Beyond Three-Part Naming – Running SQL Across Remote IBM i Systems
  • How IBM Bolstered IBM i Resilience In The Summer Tech Refreshes

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