fhg
Volume 6, Number 40 -- November 1, 2006

The RUN Utility: Call a Program with Correctly Formatted Parameters

Published: November 1, 2006

by Ted Holt

Note: The source code for article can be downloaded here


One complaint I hear from time to time concerns the way CL's CALL command formats literal values that are used as parameters. I have a utility that I use when testing programs that overcomes this problem. It allows me to call a program and ensures that the parameters are formatted as they should be.

First, let's be sure we all understand the problem. When you use the CL CALL command to begin execution of a program, CL makes some assumptions about literal parameters. CL assumes that numeric values are 15-digit packed-decimal numbers with five decimal positions. Character literals of 32 characters or less are assumed to be 32 characters in length, and the value is padded with trailing blanks if necessary. A character literal of 33 bytes or more is assumed to be the length of the literal, which may not completely fill the parameter. These rules apply when the CALL command runs from a command line, is executed through QCMDEXC, is executed within a CL procedure (program or module), or executed in the CMD or RQSDTA parameters of the Submit Job (SBMJOB) command.

Common ways to get around this limitation are:

  1. Define all parameters as character in the called program
  2. Pass data to a program through the local data area rather than through parameters
  3. Declare numeric parameters as 15-5 in the called program
  4. Pass numeric values as hexadecimal literals
  5. Write a command interface for the called program

These are all fine, I suppose. Each has its advantages and disadvantages. I hate options one through three because they are workarounds. Option four is clumsy, but I have used it many times. Option five is elegant, but I don't like to write a command unless I'll need the command in the production environment.

I came up with another alternative that works well for me. I wrote a command that will call a program with literal parameters that fit the definition in the called program. I call my command RUN, because that's the shortest word I could think of that seemed appropriate. (DO and GO were already taken.)

Suppose I wish to call program MYPGM, passing it three parameters:

  • A 64-byte character value
  • A seven-digit packed decimal value with two decimal positions
  • An 11-digit packed decimal value with no decimal positions

Here's how it's done:

RUN PGM(MYPGM) PARM(('I like cheese a whole lot!' *CHAR (64)) +
   (3.14 *DEC (7 2)) (12345678901 *DEC (11)))

If I prefer to run in batch, that's OK, too.

SBMJOB CMD(RUN PGM(MYPGM) PARM(('I like cheese a whole lot!' *CHAR (64))
   (3.14 *DEC (7 2)) (12345678901 *DEC (11)))) JOB(MYJOB)

I know that looks messy, but I prompt the command and fill in the blanks, which is no big deal.

The RUN utility consists of two objects--the RUN command and RPG program RUNRG. The latter object is created from two modules--RUNRG and Cletus the Codeslinger's ASSERT, which was published in Four Hundred Guru. (See Programming with Assertions for more on that.) I have included revised source for ASSERT in the downloadable code that accompanies this article.

The RUN command has two parameters, which are the same as those defined to the CALL command. The first is the qualified name of the program to be called. The second is a list of parameters. Each element of the list consists of the parameter's value, the data type (*CHAR or *DEC), and the length. The length is a single number for character parameters. For decimal parameters you may specify one or two length values to indicate number of digits and decimal places. If you specify only one length value for a decimal value, the number is assumed to have zero decimal positions.

Before you can create the RUN utility, you will have to load the following source members in a library of your choosing.


Name

Type

Source file

ASSERT

RPGLE

PROTOTYPES

ASSERT

RPGLE

QRPGLESRC

QCMDEXC

RPGLE

PROTOTYPES

RUN

CMD

QCMDSRC

RUNRG

RPGLE

QRPGLESRC


To create the utility, first create the command, then the two modules, and finally bind the two modules into a program.

CRTCMD CMD(RUN) PGM(RUNRG) 

CRTRPGMOD MODULE(somelib/ASSERT) +
   SRCFILE(QRPGLESRC) SRCMBR(ASSERT)

CRTRPGMOD MODULE(somelib/RUNRG) +
   SRCFILE(QRPGLESRC) SRCMBR(RUNRG)

CRTPGM PGM(somelib/RUNRG) +
   MODULE(RUNRG ASSERT) ACTGRP(*CALLER)

Let me emphasize that for me, this is just a way to test programs that would normally be called from other programs. I have never used RUN in a production environment, nor do I plan to. I have not thoroughly tested all the error-handling logic, although I feel it would probably kick in if it had to. If you install RUN, please keep this disclaimer in mind.



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
E-mail: software@worksright.com
Web site: www.worksright.com



Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

ASNA:  Monarch is a better way to modernize your RPG applications
SafeData:  Cost-effective, subscription-based data protection services for the business community
COMMON:  Join us at the Spring 2007 conference, April 29 – May 3, in Anaheim, California

 


 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement