You can use the Call (CALL) command to run a program interactively, or as part of a batch job.
The syntax for this command is:
>>-CALL PGM--(library-name/program-name)-----------------------><
For example, the command
CALL PGM(MYLIB/MYPROG)
invokes the program MYPROG located in the library MYLIB.
If the program object specified by program-name exists in a library that is contained in your library list, you can omit the library name in the command, and the syntax is:
>>-CALL--program-name------------------------------------------><
For example, if MYLIB appears in your library list, you can simply enter:
CALL MYPROG
When you request prompting with the Call command, a display appears that allows you to supply the parameters to the program you are calling.
You can also type the parameters directly onto the command line, following the Call command.
If the program requires only one parameter, enter:
CALL MYPROG 'parameter 1'
If the program requires more than one parameter, you must use the PARM keyword. For example:
CALL MYPROG PARM ('parameter 1' parameter 2')
The following example shows an ILE C/C++ program T1520REP that requires parameters at run time.
CRTBNDC PGM(MYLIB/T1520REP) SRCFILE(QCPPLE/QACSRC)
The source code is shown in Figure 26.
CALL PGM(MYLIB/T1520REP) PARM('Hello, World')
The output is:
+--------------------------------------------------------------------------------+ | Hello, World | | Press ENTER to end terminal session. | +--------------------------------------------------------------------------------+
The source file for program T1520REP is shown in the following figure:
Figure 26. T1520REP -- ILE C Source to Pass Parameters to an ILE C Program
|
The following example demonstrates how to pass the value 'Hello, World' to program XRUN1 which expects parameters at run time.
Follow the steps below to create and run program XRUN1:
CRTBNDCPP PGM(MYLIB/XRUN1) SRCSTMF('xrun1.cpp')
The resulting program object is created in the default library (in this example, MYLIB).
CALL PGM(MYLIB/XRUN1) PARM('Hello, World')
The output of program XRUN1 is:
+--------------------------------------------------------------------------------+ | Hello, World | | Press ENTER to end terminal session. | | | +--------------------------------------------------------------------------------+
The source file xrun1.cpp for program XRUN1 is shown in the following figure:
Figure 27. Source File for a Program that Passes the Value 'Hello, World' to Another Program
// xrun1.cpp // Prints out command line arguments. #include <iostream.h> int main ( int argc, char *argv[]) { int i; for ( i = 1; i < argc; ++i ) cout << argv[i] << endl; } |
When you call a program from a CL command line, the parameters you pass on the
Call command are changed, depending on how you state the parameters. Table 5 shows how parameters are converted.
Table 5. Call (CALL) Command Parameter Conversions
Conversion Rules | Examples | Conversion Results |
---|---|---|
String literals are passed with a null terminating character. | CALL PGM(T1520REP) PARM(abc) | ABC\0
(converted to uppercase; passed as a string) |
Numeric constants are passed as packed decimal digits. | CALL PGM(T1520REP) PARM('123.4') | 123.4
(passed as a packed decimal (15,5)) |
Characters that are not enclosed in single quotation marks are:
| CALL PGM(T1520REP) PARM(123.4) | 123.4\0
(passed as a string) |
Characters that are enclosed in single quotation marks are not changed. Mixed case strings are supported, and are passed with a null terminating character. | CALL PGM(T1520REP) PARM('abc')
and CALL PGM(T1520REP) PARM('abC') | abc\0
(passed as a string) and abC\0 (passed as a string) |
The REXX interpreter treats all REXX variables as strings (without a null terminator). REXX passes parameters to OS/400 which then calls the ILE C/C++ program. Conversion to a packed decimal data type still occurs, and strings are null terminated.
You can use the Process Commands (QCAPCMD) API to:
The QCAPCMD API is used to perform command analyzer processing on command strings. You can check or run CL commands from HLLs as well as check syntax for specific source definition types.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.