Code Samples

Figure 1. Example of Source Code that Transfers Control to Another Program
/* Source for CL Program RUNCP                               */
PGM        PARM(&STRING)
DCL        VAR(&STRING)   TYPE(*CHAR) LEN(20)
DCL        VAR(&NULL)     TYPE(*CHAR) LEN(1) VALUE(X'00')

/* ADD NULL TERMINATOR FOR THE ILE C++ PROGRAM               */
CHGVAR     VAR(&STRING) VALUE(&STRING *TCAT &NULL)
TFRCTL     PGM(MYLIB/XRUN2) PARM(&STRING)

/* THE DSPJOBLOG COMMAND IS NOT CARRIED OUT SINCE            */
/* WHEN PROGRAM XRRUN2 RETURNS, IT DOES NOT RETURN TO THIS   */
/* CL PROGRAM.                                               */
DSPJOBLOG
ENDPGM
Note: In the example Example: Creating and Running a Program that Uses the TFRCTL Command, program RUNCP uses the TFRCTL command to pass control to the ILE C++ program XRUN2, which does not return control to RUNCP.
Figure 2. Example of Source Code that Receives and Prints a Null-Terminated Character String
// xrun2.cpp
// Source for Program XRUN2
// Receives and prints a null-terminated character string

#include <iostream.h>

int main(int argc, char *argv[])
{
   int    i;
   char * string;
   string = argv[1];
   cout << "string = " <<  string << endl;
}
Note: In the example Example: Creating and Running a Program that Uses the TFRCTL Command, program XRUN2 receives a null-terminated character string from the CL program and prints the string.