• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Optional Parameters and CL Procedures: Valuable Info from IBM

    September 22, 2004 Hey, Ted

    In “Optional Parameters and CL procedures,” you said that ILE CL procedures can handle unpassed parameters by monitoring for message MCH3601. While it’s perfectly safe to test for omitted parameters (those for which the caller specified the special value *OMIT) by monitoring for MCH3601, it’s dangerous to depend on MCH3601 for unpassed parameters. RTV-type commands are also safe; they work like *OMIT parameters by passing null pointers.

    It is possible for the system to fail to send MCH3601 when a parameter was not passed. This failure occurs when the system still has a pointer to a parameter from a previous call. If you then change that parameter, you will be changing the storage, which the old pointer happens to reference.

    Here’s a little test to prove it. The caller is an RPG program.

    D parmclle        pr
    D p1                             1a
    D p2                             1a   options(*nopass)
    
    D v1              s              1a   inz('x')
    D v2              s              1a   inz('y')
    
    c                   callp     parmclle (v1)
    
    c                   eval      v1 = 'm'
    c                   eval      v2 = 'n'
    c                   callp     parmclle (v1 : v2)
    
    c                   eval      v1 = 'p'
    c                   eval      v2 = 'q'
    c                   callp     parmclle (v1)
     * v2 should not have been changed
    
    c                    eval      *inlr = '1' 
    

    Here’s the called ILE CL procedure.

    pgm parm(&p1 &p2)
    
    dcl &p1 type(*char) len(1)
    dcl &p2 type(*char) len(1)
    
    chgvar &p1 'a'
    monmsg mch3601 exec(sndpgmmsg 'p1 not passed')
    chgvar &p2 'b'
    monmsg mch3601 exec(sndpgmmsg 'p2 not passed')
    

    Here are the compilation instructions I used to create a program from the two modules.

    crtclmod    qtemp/parmclle 
    crtrpgmod   qtemp/parmrpgle 
    crtpgm      qtemp/pimple +
                  module(qtemp/parmrpgle qtemp/parmclle) +
                  endmod(parmrpgle) 
    

    The first call behaves as expected; the CL procedure receives message MCH3601. Here’s the debugger output from the RPG module.

    > EVAL v1 
    V1 = 'a' 
    > EVAL v2 
    V2 = 'y' 
    

    The job log contains the message “p2 not passed.”


    The second call passes both parameters. Two pointers get put on the call stack.

    > EVAL v1 
    V1 = 'a' 
    > EVAL v2 
    V2 = 'b' 
    

    The third call is like the first call, but the second pointer is still on the stack from the previous call, so the CL procedure behaves as if it received two parameters.

    > EVAL v1 
    V1 = 'a' 
    > EVAL v2 
    V2 = 'b' 
    

    But V2 should still have the value q. In this case, it’s my own storage that got corrupted by the call, but it’s very common to have completely unrelated pointers on the stack.

    My first attempt at this test used a DSPLY operation after each call; with that version, I didn’t get the MCH3601 in the CL, but the V2 variable didn’t get updated, either. I have no idea what did get updated by the bad third call. It’s actually a bit dangerous even to do this test: you really don’t know what you might be changing when you do this.

    There are a couple of options when you want to have a CL procedure with optional values, to prevent having to change all the callers.

    1. Create an RPG wrapper procedure with the name of the old CL procedure. Have the RPG wrapper call through to the new CL, passing the number of passed parameters in the first parameter, or passing *OMIT in the unpassed parameters. You would need several calls, depending on the number of parameters.

    if %parms = 0; 
        callp cl (*omit : *omit : *omit); 
    elseif %parms = 1; 
        callp cl (p1 : *omit : *omit); 
    elseif %parms = 2; 
        callp cl (p1 : p2 : *omit); 
    elseif ... 
    else; 
        callp error ('Too many parms'); 
    endif; 
    

    2. Create a new ILE CL procedure with a new name, and change the old one to call through to the new one, passing *OMIT for the new parameters. Callers would have to remember to use the new name.

    –Barbara Morris
    RPG Compiler Development
    IBM Toronto Lab

    Thanks yet again to Barbara Morris for sharing inside information with the iSeries community. I did not run her test; I didn’t want to take a chance of messing up the NetShare/400 machine.

    –Ted Holt

    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:

    Sponsored by
    Lightedge

    Your IBM Power Cloud Strategy Should Start With “Why?”

    Moving IBM i to the cloud isn’t just an infrastructure decision.

    A hardware refresh, data center exit, IBM i skills gap, disaster recovery requirement, or broader cloud initiative can each lead to a very different architecture.

    At Lightedge, we start by understanding what you’re trying to accomplish. Then we look at the workload, application dependencies, resiliency requirements, operating model, and long-term strategy to determine where that workload belongs.

    Managed IBM Power cloud? IBM Power Virtual Server? DR in the cloud? A hybrid architecture connecting IBM Power with AWS or Azure?

    There isn’t one right answer for every IBM i environment.

    Start with the business requirement. Understand the workload. Then decide where it belongs.

    Explore IBM Power cloud, managed services, and hybrid solutions from Lightedge.

    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

    A Generic Command Choice Program OS/400 Shops in Limbo During Oracle-PeopleSoft Fight

    Leave a ReplyCancel reply

Volume 4, Number 32 -- September 22, 2004
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
WorksRight Software
Bug Busters Software Engineering

Table of Contents

  • A Generic Command Choice Program
  • Optional Parameters and CL Procedures: Valuable Info from IBM

Content archive

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

Recent Posts

  • MIMIX 11 Ships As Tech Outages Dominate Headlines
  • Could You Recover Tomorrow? A CISO’s Perspective On IBM i Security In 2027
  • Guru: RPG’s New %INFO BIF. Is It Time to Retire the SDS?
  • Big Blue Backs Off On Power Memory Redundancy As Memory Prices Soar
  • IBM i PTF Guide, Volume 28, Number 42
  • IBM i Delivers New Development Tooling With 2026 Fall Tech Refreshes
  • Big Blue Says AI Is Not Behind The Big Uptick In IBM i Security Alerts
  • Guru: Web Service With Pagination
  • The GenAI Revolution And Product Shortages Send IT Budgets Skyward
  • IBM i PTF Guide, Volume 28, Number 40

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