fhg
Volume 11, Number 19 -- June 22, 2011

Forcing Keyword Parameters

Published: June 22, 2011

by Ted Holt

Programming languages use two conventions for passing arguments (commonly referred to as parameters) to a called routine. Some languages use positional parameters. That is, the parameters must be passed to the routine in a certain order. The other (and less error-prone) method is to password parameters in keyword format. IBM i allows you to force callers to use keyword format--to a point--when they use your CL commands. Here's how.

But first, let's review the two major problems inherent in positional parameters. First, it is easy to get a parameter value into the wrong position. Take the following OCL command for example.

LIBRLIBR HISLIB,HERLIB,,REPLACE,,REPLACE

OCL uses commas to separate positional parameters. Adjacent commas mean that you are not passing a value for a parameter. If you omit one of the commas or add an extra comma, the system will not pass the correct values to the parameters of the LIBRLIBR routine.

The second problem is that the meaning of each parameter is not obvious. Two parameters have the value REPLACE. What does each REPLACE mean in this context?

In addition to OCL, other languages that use positional notation are the CALLP opcode in RPG and Unix (and Unix-like) shells, including Qshell.

Keyword parameters do not have these problems because the order in which the parameters are coded does not matter, and each parameter's function is documented by its keyword. Look at the following CL command.

CPYSRCF FROMFILE(HISLIB/QRPGLESRC)
        TOFILE(HERLIB/QRPGLESRC)
        FROMMBR(REPLACE)
        MBROPT(*REPLACE)

Is the meaning of any parameter in doubt?

When you create a CL command of your own, give some thought to whether or not you want to force callers to enter keywords. The only advantage (of which I'm aware) of allowing users to enter parameters positionally is that the source code is sometimes cleaner and easier to read. Compare the following equivalent CL commands:

IF (&OPTION *EQ 'W') DO

IF COND(&OPTION *EQ '1') THEN(DO)

Both are legible, but I prefer the first one. The second one is too cluttered for my taste. But the IF command only has two parameters. If there were, say, a half dozen or more, the absence of keywords would decrease readability.

To force users to enter parameters in keyword format, use the MAXPOS parameter of the Create Command (CRTCMD) command.

CRTCMD CMD(MYLIB/DOIT)
       PGM(*LIBL/DOITC)
       SRCFILE(MYLIB/QCMDSRC)
       SRCMBR(DOITX)
       <b>MAXPOS(1)<b>

The help text for MAXPOS appears to me to be in error. It reads that the MAXPOS value must be greater than the number of required parameters, but my experience is that the MAXPOS value must be greater than <b>or equal to</b> the number of required parameters.

And that brings up one little feature of which I am not fond. The preceding paragraph implies that you cannot force required parameters to be entered in keyword format. That is true, and I don't like it, but nobody asked my opinion.

If a caller passes too many parameters positionally, the system responds with two error messages: CPD0065 (Number of positional parameters exceeds limit of 1); and CPF0001 (Error found on DOIT command).

For more information about positional and keyword formats, follow this link to IBM's website.




                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
PRODATA COMPUTER SERVICES

Have you been DBU'ed?

Use DBU Audit to monitor your databases. DBU Audit journals all
adds, changes, deletes, reactivation or viewing of data
made through DBU to a standalone IBM journal.

                                                  DBU Audit enables aministrators to:
                                                   monitor access & changes to DB2 data
                                                   display audit information
                                                   generate SOX reports

                                                    And MORE!

Download today!
800.228.6318
www.DoDBU.com


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
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

VAULT400:  Stuck in the 70's with Tape Backup? Get modern, secure back-up and DR
Enforcive:  Enterprise security for the IBM i. Formerly Bsafe Information Systems
SEQUEL Software:  FREE White Paper: The Race To Access Enterprise Data


 

IT Jungle Store Top Book Picks

BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

The iSeries Express Web Implementer's Guide: List Price, $49.95
The iSeries Pocket Database Guide: List Price, $59
The iSeries Pocket SQL Guide: List Price, $59
The iSeries Pocket WebFacing Primer: List Price, $39
Migrating to WebSphere Express for iSeries: List Price, $49
Getting Started with WebSphere Express for iSeries: List Price, $49
The All-Everything Operating System: List Price, $35
The Best Joomla! Tutorial Ever!: List Price, $19.95


 
The Four Hundred
You're Only As Old As The Programs You Run With

KS2 Expands IBM i Managed Services Biz Into Hosting, Co-Lo

DB2 for i: The Beating Heart of the IBM i Platform

As I See It: Nostalgic for Normal

Survey Says: 24 Hours Is The Disaster Recovery Target

Four Hundred Stuff
Flux Delivers Automation for Changing Workloads

Two-Tier ERP Deployments Gain Steam

IBM Ships New Collaborative Lifecycle Management Suite

Skybot: When Automated Scheduling is Not for IBM i

IBM Distributing WSDL2RPG via Integrated Web Services for i

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
September 25, 2010: Volume 12, Number 39

September 18, 2010: Volume 12, Number 38

September 11, 2010: Volume 12, Number 37

September 4, 2010: Volume 12, Number 36

August 28, 2010: Volume 12, Number 35

August 21, 2010: Volume 12, Number 34

TPM at The Register
GlobalFoundries shuffles top brass

HP dubs Oracle 'bitter antagonist' in Itanic spat

Can Big Blue survive another century?

HP sues Oracle over Itanic withdrawal

SGI boasts of Altix UV installs

T-Platforms CPU-GPU hybrid hits 1.3 petaflops at Moscow State

IBM slashes prices on Opteron 6100 racker

Lenovo chases SMBs with Xeon E3 towers

IBM: Palmisano mulls Big Blue line of succession

VMware eats Digital Fuel

ARM server hero Calxeda lines up software super friends

Xeround reinvents MySQL atop Amazon cloud

THIS ISSUE SPONSORED BY:

SEQUEL Software
ProData Computer Services
WorksRight Software


Printer Friendly Version


TABLE OF CONTENTS
SQL Implicit Cast of Character Strings and Numeric Values

Forcing Keyword Parameters

Admin Alert: Things to Think About in a Power i Development Environment

Four Hundred Guru

BACK ISSUES




 
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-2011 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement