ILE C/C++ Programmer's Guide

Source Code for a User Entry Procedure (UEP)

In the source code for T1520IC1, the main() function:

Figure 56. ILE C Source to Call Functions in Other Modules


          /* This program demonstrates how to use multiple modules, service     */
          /* programs and a binding directory.  This program accepts a user ID, */
          /* item name, quantity, and price, calculates the total cost, and     */
          /* writes an audit trail of the transaction.                          */
          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h.>
          #include <decimal.h>
          int calc_and_format (decimal(10,2),
                               short int,
                               char[]);
          void write_audit_trail (char[],
                                  char[],
                                  decimal(10,2),
                                  short int,
                                  char[]);
          int main(int argc, char *argv[])             (1)
          {
           /* Incoming arguments from a CL program have been verified by      */
           /* the *CMD and null ended within the CL program.        */(2)
             char             *user_id;
             char             *item_name;
             short int        *quantity;
             decimal (10,2)  *price;
             char             formatted_cost[22];
           /* Incoming arguments are all pointers.                  */(3)
             item_name =                      argv[1];
             price     = (decimal (10, 2) *)  argv[2];
             quantity  = (short *)            argv[3];
             user_id   =                      argv[4];
           /* Call an ILE C function that returns a formatted cost. */(4)
           /* Function calc_and_format returns true if successful.  */
             if (calc_and_format (*price, *quantity, formatted_cost))
             {
               write_audit_trail (user_id,             (5)
                                  item_name,
                                  *price,
                                  *quantity,
                                  formatted_cost);
               printf("\n%d %s plus tax = %-s\n", *quantity,
                                                  item_name,
                                                  formatted_cost);
             }
             else
             {
               printf("Calculation failed\n");
             }
             return 0;
           }

Notes:

  1. The main() function in this module is the user entry procedure (UEP), which is the target of a dynamic program call from the CL program T1520CL1. The UEP receives control from the program entry procedure (PEP). This module has a PEP that is generated by the ILE C compiler during compilation. The PEP is an entry point for the ILE C/C++ program on a dynamic program call from the CL program T1520CL1. The PEP is shown in the call stack as _C_pep.

  2. The main() function in this module receives the incoming arguments from the CL program T1520CL1 that are verified by the CL command prompt T1520CM1.

  3. All the incoming arguments are pointers. The variable item_name is null terminated within the CL program T1520CL1.

  4. The main() function in this module calls calc_and_format in module T1520IC2 to return a formatted cost. If the calc_and_format returns successful a record is written to the audit trail by write_audit_trail in the service program T1520SP1.

  5. The function write_audit_trail is not defined in this module (T1520IC1), so it must be imported.


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