Calling a Program - IBM-ILE

When you call a program, the OS/400 system locates the corresponding executable code and performs the instructions found in the program.

Note: Only programs can run independently. Service programs or other bound procedures must be called from a program that requires their services.

There are several ways to call a program:

  • Issue the CL CALL command.
  • Issue the CL Transfer Control (TFRCTL) command.
  • Issue a user-created CL command.

In addition, you can run a program using:

  • The Programmer Menu
  • The Start Programming Development Manager (STRPDM) command.
  • The EVOKE statement from an ICF file.
  • The CAPEXC program.
  • A high-level language. See “Service Programs” for information on calling service programs and procedures).
  • The REXX interpreter.

Calling a Program Using the TFRCTL Command

You can run an application from within a CL program that transfers control to your program using the Transfer Control (TFRCTL) command. This command:

  1. Transfers control to the program specified on the command.
  2. Removes the transferring CL program from the call stack.

In the following example, the TFRCTL command in a CL program RUNCP calls a C++ program XRUN2, which is specified on the TFRCTL command. RUNCP transfers control to XRUN2. The transferring program RUNCP is removed from the call stack.

Figureillustrates the call to the CL program RUNCP, and the transfer of control to the C++ program XRUN2.

Calling Program XRUN2 Using the TFRCTL Command

Calling Program XRUN2 Using the TFRCTL Command

To create and run programs RUNCP and XRUN2, follow the steps below:

  1. Enter the source code below into a source physical file QCLSRC, in library MYLIB.
  2. create and run programs RUNCP and XRUN2

  3. Create the CL program RUNCP. From the command line, type:

    Program RUNCP uses the TFRCTL command to pass control to the ILE C++ program XRUN2, which does not return to RUNCP.

  5. Create program XRUN2 in library MYLIB from source file xrun2.cpp, shown below:
  6. Program XRUN2 receives a null terminated character string from the CL program and prints the string.

  7. Run program RUNCP from a command line, passing it the string ″nails″, with the command:

    The output from program XRUN2 is:

    output from program XRUN2 is

Running a Program from a User-Created CL Command

You can also run a program from your own CL command. To create a command:

  1. Enter a set of command statements into a source file.
  2. Process the source file and create a command object (type *CMD) using the Create Command (CRTCMD) command.
  3. The CRTCMD command definition includes the command name,parameter
    descriptions, and validity-checking information,and identifies the program that performs the function requested by the command.

  4. Enter the command interactively, or in a batch job.
  5. The program called by your CL command is run.

The following example illustrates how to run a program from a user-created CL command:

Program Description
A newly created command COST prompts for and accepts user input values. It then calls a C++ program CALCOST and passes it the input values. CALCOST accepts the input values from the command COST, performs calculations on these values, and prints results. Figure illustrates this example.

Calling Program CALCOST from a User-Defined Command COST

Calling Program CALCOST from a User-Defined Command COST

To create and run the example, follow the steps below:

  1. Enter the source code for the command prompt COST shown below into a source file QCMDSRC in library MYLIB:
  2. Create the CL command prompt COST. On a command line, enter:

    Use the CL command prompt COST to enter item name, price, and quantity for the ILE C++ program CALCOST.

  4. Create program CALCOST from the source file calcost.cpp shown below:
  5. This program receives the incoming arguments from the CL command COST, calculates a cost, and prints values. All incoming arguments are pointers.

  6. Enter data for the program CALCOST. From the command line, type COST and press F4 (Prompt).
  7. Type the data shown below into COST:


    The output of program CALCOST is:

    The output of program CALCOST is:

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

IBM-ILE Topics