Execute Command (QCMDEXC) is an IBM-supplied program that runs a single command. This command is used to activate another command:
The QCMDEXC program is called from within the HLL or CL procedure or
program. The command that is to be run is passed as a parameter on the
CALL command.
After the command runs, control returns to your HLL or CL procedure or program.
The command runs as if it was not in a program. Therefore, variables cannot be used on the command because values cannot be returned by the command to CL variables. Additionally, commands that can only be used in CL procedures or programs cannot be run by the QCMDEXC program. The format of the call to the QCMDEXC program is the following:
CALL PGM(QCMDEXC) PARM(command command-length)
Enter the command you wish to run as a character string on the first parameter. You must specify the command library.
CALL PGM(QCMDEXC ) PARM('QSYS/CRTLIB LIB(TEST)' 22)
Remember that you must enclose the command in apostrophes if it contains blanks. The maximum length of the character string is 6000 characters; never count the delimiters (the apostrophes ) as part of the string. The length that is specified as the second value on the PARM parameter is the length of the character string that is passed as the command. Length must be a packed decimal value of length 15 with 5 decimal positions.
Thus, to replace a library list, the call to the QCMDEXC program would look like this:
CALL PGM(QCMDEXC) PARM('CHGLIBL LIBL(QGPL NEWLIB QTEMP)' 31)
It is possible to code this statement into the HLL or CL program to replace the library list when the program runs. The QCMDEXC program does not provide run-time flexibility when used this way.
Providing run-time flexibility is accomplished by:
For instance:
Figure 6-1. Example of Call PGM
The command length, passed to the QCMDEXC program on the second parameter, is the maximum length of the passed command string. Should the command string be passed as a quoted string, the command length is exactly the length of the quoted string. Should the command string be passed in a variable, the command length is the length of the CL variable. It is not necessary to reduce the command length to the actual length of the command string in the variable, although it is permissible to do so.
Not all commands can be run using the QCMDEXC program. The command passed on a call to the QCMDEXC program must be valid within the current environment (interactive or batch) in which the call is being made. The command cannot be one of the following:
IBM has provided online information to help you determine if you can pass a CL command on a call to the QCMDEXC program. Refer to the command in the CL section of the Programming category in the iSeries Information Center. To find the environment in which you can run the command, look at the syntax diagram for the command. The small box in the upper right corner of the diagram indicates the environment in which you can run the command. For example, JOB: I indicates that the command can be run interactively; JOB: B indicates that you can run the command in a batch job; Exec indicates that you can run the command with QCMDEXC.
You can precede the CL command with a question mark (?) to request prompting or use selective prompting when you call QCMDEXC in an interactive job.
If an error is detected while a command is being processed through the QCMDEXC program, an escape message is sent. You can monitor for this escape message in your CL procedure or program using the Monitor Message (MONMSG) command. For more information about monitoring for messages, see "Defining Messages" and "Working with Messages".
If a syntax error is detected, message CPF0006 is sent. If an error is detected during the processing of a command, any escape message sent by the command is returned by the QCMDEXC program. You monitor for messages from commands run through the QCMDEXC program in the same way you monitor for messages from commands contained in CL procedures and programs.
See the appropriate HLL reference for information on how HLL programs handle errors on calls.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.