ILE C/C++ Programmer's Guide

Example: CL Program that Passes Parameters to an ILE C++ Program

The CL program CLPROG1 passes the parameters v, d, h, i, j to an ILE C++ program MYPROG1.

Note:
To pass parameters to an ILE program when you run it, use the PARM option of the CL Call (CALL) command.

The parameters are null-terminated within the the CL program CLPROG1. They are passed by reference. All incoming arguments to MYPROG1 are pointers.

Figure 247. Example of CL Program that Passes Arguments to an ILE C++ Program


/* CLPROG1
 PGM        PARM(&V &D &H &I &J)
      DCL        VAR(&V) TYPE(*CHAR) LEN(10)
      DCL        VAR(&VOUT) TYPE(*CHAR) LEN(11)
      DCL        VAR(&D) TYPE(*DEC)  LEN(10 1)
      DCL        VAR(&H) TYPE(*CHAR) LEN(10)
      DCL        VAR(&HOUT) TYPE(*CHAR) LEN(11)
      DCL        VAR(&I) TYPE(*CHAR) LEN(10)
      DCL        VAR(&IOUT) TYPE(*CHAR) LEN(11)
      DCL        VAR(&J) TYPE(*LGL)  LEN(1)
      DCL        VAR(&JOUT) TYPE(*LGL)  LEN(2)
      DCL        VAR(&NULL) TYPE(*CHAR) LEN(1)  VALUE(X'00')
      /* ADD NULL TERMINATOR FOR THE C++ PROGRAM  */
      CHGVAR     VAR(&VOUT) VALUE(&V *TCAT &NULL)
      CHGVAR     VAR(&HOUT) VALUE(&V *TCAT &NULL)
      CHGVAR     VAR(&IOUT) VALUE(&V *TCAT &NULL)
      CHGVAR     VAR(&JOUT) VALUE(&V *TCAT &NULL)
      CALL       PGM(MYPROG1) PARM(&VOUT &D &HOUT &IOUT &JOUT)
 ENDPGM

The CL program CLPROG1 receives its input values from a CL Command Prompt MYCMD1 which prompts the user to input the desired values. The source code for MYCMD1 is:

Figure 248. Example of Generic CL Command Prompt


 CMD        PROMPT('ENTER VALUES')
 PARM       KWD(V) TYPE(*CHAR) LEN(10) +
              PROMPT('1ST VALUE')
 PARM       KWD(D) TYPE(*DEC) LEN(10 2) +
              PROMPT('2ND VALUE')
 PARM       KWD(H) TYPE(*CHAR) LEN(10) +
              PROMPT('3RD VALUE')
 PARM       KWD(I) TYPE(*CHAR) LEN(1) +
              PROMPT('4TH VALUE')
 PARM       KWD(J) TYPE(*LGL) LEN(10 2) +
              PROMPT('5TH VALUE')

After the CL program CLPROG1 has received the user input from the command prompt MYCMD1, it passes the input values on to a C++ program MYPROG1. The source code for this program is contained in myprog1.cpp:

Figure 249. Example of C++ Program that Receives Arguments (Pointers) by Reference


// myprog1.cpp
 
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <bcd.h>
 
// Arguments are received by reference from CL program CLPROG1
// Incoming arguments are all pointers
 
int main(int argc, char *argv[])
{
  char               *v;
  char               *h;
  char               *i;
  char               *j;
  _DecimalT <10, 1>  d;
 
  v =  argv[1];
  d = *((_DecimalT <10,1> *) argv[2]);
  h =  argv[3];
  i =  argv[4];
  j =  argv[5];
  cout << "  v= " << v
       << "  d= " << d
       << "  h= " << h
       << "  i= " << i
       << "  j= " << j
       << endl;
}

If the CL program CLPROG1 passes the following parameters to the C++ program MYPROG1:

'123.4', 123.4, 'Hi', LO, and '1'

the output from program MYPROG1 is:

+--------------------------------------------------------------------------------+
|v= 123.4     HI        LO        1  d= 123.4  h= HI        LO        1          |
|i= LO     1  j= 1                                                               |
|Press ENTER to end terminal session.                                            |
+--------------------------------------------------------------------------------+


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