TechTip: Create CL Commands from CL Program Source Code PDF Print E-mail
Written by MC Press Contributing Author   
Thursday, 29 July 2004

Use modified CL program source code to avoid the mismatched parameter problem. It is common for a CL program to submit a CALL command to a job queue for batch processing. That is, the programmer places a CALL command in the CMD parameter of the Submit Job (SBMJOB) command. Submitting a CALL command is risky because the command interpreter makes certain assumptions about parameter formats when loading and executing the called program. Numeric values are assumed to be 15-digit numbers with five decimal positions. Character values of 32 bytes or less in length are padded with trailing blanks to a length of 32. Trailing blanks are removed from character values longer than 32 bytes, potentially causing the submitted program to receive garbage in the rightmost part of a long character parameter.

Several methods exist to work around this problem, but my favorite by far is to write a CL command to run the program. I reference this command, rather than a CALL, in the CMD parameter of SBMJOB. While I occasionally see this method recommended in an online forum, I have found that many iSeries professionals have worked with the iSeries and/or AS/400 for years, yet have never written a command!

It is very easy to create command source code from CL program source code. Let me illustrate. Assume you have a CL program, CALLEDPGM, that is to be submitted to batch from another program, CALLER.

The first step is to provide a place to store command source code. You can use any source physical file you wish. For this illustration, I use a file called QCMDSRC, which is IBM's default name for command source. If necessary, create a source physical file.

CRTSRCPF MYLIB/QCMDSRC

Replace MYLIB with the name of one of your libraries.

Next, create a source physical file member to contain the command source. In this example, I use PDM and SEU because everybody has them and knows how to use them. From the Work with Members Using PDM panel, press F6 to create a new member. Name it CALLEDCMD and select CMD as the source member type. SEU creates an empty work member.

On the first line of the empty member, type CMD. Press F15 and enter CALLEDPGM and the name of the CL program's source file and library in the Browse/copy member entry fields. This permits you to view the CL program source as you build the command source code. At this point, you have a split display, with CALLEDCMD at the top and CALLEDPGM at the bottom.

Notice the PGM command that begins program CALLEDPGM. For this illustration, assume it looks like this:

PGM PARM(&COMPANY &WAREHOUSE &SHIPDATE &COMMENT)

There are four parameters, therefore your command will have four parameters. Copy the DCL statements for these four variables into the command source work member in the order in which they are listed on the PGM command. It is unlikely that any variable declaration has a VALUE parameter, since parameters receive their values from the caller, but if the VALUE parameter exists, remove it. The command source will look like this:

CMD
DCL VAR(&COMPANY) TYPE(*DEC) LEN(3) 
DCL VAR(&WAREHOUSE) TYPE(*CHAR) LEN(1) 
DCL VAR(&SHIPDATE) TYPE(*DEC) LEN(6) 
DCL VAR(&COMMENT) TYPE(*CHAR) LEN(40) 

You are finished with the CL program source code and can close the window in which it is displayed. SEU shows the DCL commands in reverse image because DCL is not valid in CL command source code. SEU also sends the error message "Command DCL not allowed in this setting." Use global search and replace operations to change DCL to PARM and VAR(& to an empty string. You can use SEU's CHANGE command for this purpose.

C DCL PARM A
C VAR(& '' A

Even after you make these changes, SEU is still not satisfied. Remove the closing parenthesis following each variable name and the reverse image should disappear from the PARM commands. The command source looks like this:

CMD 
PARM COMPANY TYPE(*DEC) LEN(3) 
PARM WAREHOUSE TYPE(*CHAR) LEN(1) 
PARM SHIPDATE TYPE(*DEC) LEN(6) 
PARM COMMENT TYPE(*CHAR) LEN(40)

This is barebones command source, inadequate as a user interface but sufficient for your purpose. Close and save the source member.

Use the Create Command (Create Command) command to build the command object.

CRTCMD CMD(MYLIB/CALLEDCMD)  +
       PGM(MYLIB/CALLEDPGM) +
       SRCFILE(MYLIB/QCMDSRC) +
       SRCMBR(CALLEDCMD)

Once the command has been created, you can use it in program CALLER.

SBMJOB     CMD(CALLEDCMD COMPANY(&COMP) WAREHOUSE(&WHS) + 
             SHIPDATE(&SDATE) COMMENT('URGENT')) +    
             JOB(MYJOB)

By submitting the command instead of CALL, OS/400 will format the parameters as they are defined in program CALLEDPGM.

For more information about creating your own CL commands, see Power CL, published by MC Press.

Paul Amsden has worked with AS/400 and iSeries systems for more than 10 years.


Last Updated ( Thursday, 29 July 2004 )
 
Discuss (5 posts)
avrahamn@coop.co.il
TechTip: Create CL Commands from CL Program Source Code
Aug 15 2004 02:06:00
Therefore: <p>1. If it is possible to call a simple command like CPYF or RTVSYSVAL from within the Main RPG Program, why use an interin CL program just for one or 2 lines of code. Besides that Command Keywords are eazy to use and self=Documenting. For example: The command CPYF has more than a dozen parameters, If I would need to call it from within an RPG Program, I would need to count the positional parameters. In order to encourage programmers to write and use User Commands, it need to have a way to use the directky from within RPG, Otherwise We do not gain nothing by it. About the working environment - overrites, why no to do it directly from within the RPG Prgram and not need to write a separate program just for one or two lines of code. it will be easier Also if wee need to read the code, no need to open another source to see wat it is doing. <p>2. I did not understand what did You want to say or You did not understood what i wanted. The repetitive things of the command like parameters could be automaticaly created from within the *entry Plist, it is not needed to define the same thing twce, unless there are additional options. <p>3. Search The Keywords and prameters within the command. Example: command CPYF has so many options and pramaters, why do not give an engine to search by a pratial name of the keyword, text or options. Same is true abaut RTVSYSVAL. If users would start writing commands, and there would be a command with many parameters, it will have automaticaly a serach engine to find things easier.
#115209
coteijgeler@chello.nl
TechTip: Create CL Commands from CL Program Source Code
Aug 04 2004 05:40:00
(Strange title for an advice to create a CDO for each programme to call or submit) <p>Avrahamn, <p>a lot of strange wishes, in my opinion. <p>There is nothing wrong with a command interface. It uses UIM. This is definitely not limited. <p>1) why want to call commands from RPG? Write a appropriate CLP, which set the working environment (overwrites) for the RPG PGM, then call the RPG PGM. <p>2) Is this not a developpers task? Many PGMs run in the background, they do not require a CDO. And how is the system to decide the parameters, the data type, the length, the special values, the conditions (dependencies), etc? <p>3) This I can not grasp. Search for what? Search in what? A command can have a VCP,POP and COP; each different PGMs. <p>Regards, <BR>
Carel Teijgeler. <p>PS: <BR>
VCP=Validity Checking PGM, POP=Prompt Overrride PGM, COP=Choice Override PGM.
#115208
avrahamn@coop.co.il
TechTip: Create CL Commands from CL Program Source Code
Aug 04 2004 05:01:00
Commands are one of the best things that exist only on OS400 ISERIEIS an I5. To call a program or procedure that has many parameters without a command interface is very dificult. Imagine if instead of the easy to use command CPYF, we would need to use a call to an API program. But there are some shortcomings to the command interface and if Rochester improves it, it will become more popular. <p>Here are some suggestions: <p>1. Ability to call OS400 Commands Directly From RPG4 and COBOL Programs without using QCMDEXC, similar to the excution of commands from CL. <p>2. Automate the design of OS400 commands. Every Program uppon compilation (or option on compilation) becomes automaticaly a COMMAND, and it could be used with keywords. The name of the parameters become the KEYWORD names. additional options on prototypes or PLIST would specify the additional options that are in a command definition. <p>3. Evey Command should automaticly have a search engine to find keywords, text or options. The search would be both on the command itself and on the HELP of a command
#115207
Guest.Visitor
TechTip: Create CL Commands from CL Program Source Code
Aug 03 2004 03:40:00
I also don't understand why more don't create commands. I create many at every new job, because I work closely with the operators who are required to do jobs like reset password, without needing security officer authority. <p>What I have found best about commands is the ability to do validation. You can get fancy and have a validation program, but commands allow you to only allow specific responses. For example a Y/N field and only allow them to put in y or n and it is so easy to set up. <p>An expanded article showing this advantage would be good.
#115206
MC Press Web Site Staff
TechTip: Create CL Commands from CL Program Source Code
Aug 15 2004 02:06:00
This is a discussion about <B>TechTip: Create CL Commands from CL Program Source Code</b>.<p align='center'><a href=http://www.mcpressonline.com/mc?1@232.1KNKfHX1eQT.17@.6aec1623>Click here for the article</a>.</p>
#115205


Discuss...
User Rating: / 0
PoorBest 
Related Articles
< Prev   Next >

The following trial software can be found at the MC Press Software Center.   



   MC-STORE.COM