ILE C/C++ Programmer's Guide

Using the Call (CALL) Command

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
Note:
If you need prompting for the command parameters, type CALL and press F4 (Prompt). If you need help on how to use the command, type CALL and press F1(Help).

Passing Parameters to the Called Program

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')

Example1:

The following example shows an ILE C/C++ program T1520REP that requires parameters at run time.

  1. Suppose the source code is stored as a member T1520REP in file QACSRC of library QCPPLE. To create the program T1520REP, enter:

    CRTBNDC PGM(MYLIB/T1520REP) SRCFILE(QCPPLE/QACSRC)

    The source code is shown in Figure 26.

  2. To run the program T1520REP, enter:

    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




/* Print out the command line arguments. */
#include <stdio.h>
void main ( int argc, char *argv[] )
{
int i;
for ( i = 1; i < argc; ++i )
printf( "%s\n", argv[i] );
}

Example 2:

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:

  1. Compile the source shown above with default compiler options. From the command line, enter:
    CRTBNDCPP PGM(MYLIB/XRUN1) SRCSTMF('xrun1.cpp')
    

    The resulting program object is created in the default library (in this example, MYLIB).

  2. To run the program from a command line, enter:
    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;
   }

Call (CALL) Command Parameter Conversions

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:
  • Folded to uppercase
  • Passed with a null character
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.

Note:
These changes only apply to calling a program from a command line, not to interlanguage calls. See Chapter 23, Using ILE C/C++ Call Conventions for information on ILE C/C++ calling conventions.

Using the Process Commands (QCAPCMD) API

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.


[ Top of Page | Previous Page | Next Page | Table of Contents ]