This program shows you some typical steps in creating a program that uses several ILE programming languages.
This program is an ILE version of the small transaction-processing program described in the ILE-OPM CL Example: Calling OPM, COBOL, and RPG Programs from an ILE C++ Program.
The program consists of the following components:
Figure 237 shows the ILE structure.
![]() |
The programs T2123CL3 and T2123ICB are created with the CRTPGM default for the ACTGRP parameter, ACTGRP(*NEW). When the CL program calls the ILE C++ program, a new activation group is started.
Figure 238. Basic Object Structure
![]() |
The service programs are created with the CRTSRVPGM default for the ACTGRP parameter, ACTGRP(*CALLER). When they are called, they are activated within the activation group of the calling program.
Figure 238 shows the basic object structure used in this example.
This program includes an externally described file, a CL program, a command prompt, two C++ source files, and ILE COBOL source file and an ILE RPG source file.
:
Figure 239. Example of the Interlanguage Call Capabilities of an ILE C++ Program
// This program demonstrates the interlanguage call capability // of an ILE C++ program. This program is called by a CL // program that passes an item name, price, quantity and user ID. // A COBOL procedure is called to calculate and format total // cost. An RPG procedure is called to write an audit trail. #include <iostream.h> #include <stdlib.h> #include <string.h> #include <bcd.h> // The #pragma map directive maps a function name to the bound // procedure name so that the purpose of the procedure is clear. // Tell the compiler that there are bound procedure calls and // arguments are to be passed by value-reference. extern "COBOL" void CalcAndFormat(_DecimalT <10,2>, short int, char[], char *); #pragma map(CalcAndFormat,"T2123CB2") extern "RPG" void WriteAuditTrail(char[], char[], _DecimalT<10,2>, short int, char[]); #pragma map(WriteAuditTrail,"T2123RP2") int main(int argc, char *argv[]) { // Incoming arguments from a CL program have been verified by // the *CMD and null-terminated within the CL program. // Incoming arguments are passed by reference from a CL program. char *user_id; char *item_name; short int quantity; _DecimalT<10, 2> price; char formatted_cost[22]; // Remove null terminator for RPG program. Item name is null // terminated for C++. char rpg_item_name[20]; char null_formatted_cost[22]; char success_flag = 'N'; int i; //Incoming arguments are all pointers. item_name = argv[1]; price = *((_DecimalT<10, 2> *) argv[2]); quantity = *((short *) argv[3]); user_id = argv[4]; // Call the COBOL program to do the calculation, and return a // Y/N flag, and a formatted result. CalcAndFormat(price, quantity, formatted_cost, &success_flag); memcpy(null_formatted_cost,formatted_cost,sizeof(formatted_cost)); // Null terminate the result. formatted_cost[21] = '\0'; if (success_flag == 'Y') { for (i=0; i<20; i++) { // Remove null terminator for the RPG program. if (*(item_name+i) == '\0') { rpg_item_name[i] = ' '; } else { rpg_item_name[i] = *(item_name+i); } } // Call an RPG program to write audit records. WriteAuditTrail(user_id, rpg_item_name, price, quantity, formatted_cost); cout <<"plus tax =" << quantity << item_name << null_formatted_cost <<endl <<endl; } else { cout <<"Calculation failed" <<endl; } } |
|
IDENTIFICATION DIVISION. PROGRAM-ID. T1520CB2 INITIAL. ****************************************************** * parameters: * * incoming: PRICE, QUANTITY * * returns : TOTAL-COST (PRICE*QUANTITY*1.TAXRATE) * * SUCCESS-FLAG. * * TAXRATE : An imported value. * ****************************************************** ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-ISERIES. OBJECT-COMPUTER. IBM-ISERIES. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-TOTAL-COST PIC S9(13)V99 COMP-3. 01 WS-TAXRATE PIC S9V99 COMP-3 VALUE 1. 01 TAXRATE EXTERNAL PIC SV99 COMP-3. LINKAGE SECTION. 01 LS-PRICE PIC S9(8)V9(2) COMP-3. 01 LS-QUANTITY PIC S9(4) COMP-4. 01 LS-TOTAL-COST PIC $$,$$$,$$$,$$$,$$$.99 DISPLAY. 01 LS-OPERATION-SUCCESSFUL PIC X DISPLAY. PROCEDURE DIVISION USING LS-PRICE LS-QUANTITY LS-TOTAL-COST LS-OPERATION-SUCCESSFUL. MAINLINE. MOVE "Y" TO LS-OPERATION-SUCCESSFUL. PERFORM CALCULATE-COST. PERFORM FORMAT-COST. EXIT PROGRAM. CALCULATE-COST. ADD TAXRATE TO WS-TAXRATE. COMPUTE WS-TOTAL-COST ROUNDED = LS-QUANTITY * LS-PRICE * WS-TAXRATE ON SIZE ERROR MOVE "N" TO LS-OPERATION-SUCCESSFUL END-COMPUTE. FORMAT-COST. MOVE WS-TOTAL-COST TO LS-TOTAL-COST. |
Figure 242. ILE RPG Module T2123RP2
|
T2123ICB is considered the main program. It runs in the new activation group that is created when the CL program T2123CL3 is called.
To enter data for the program T2123ICB enter the command: T2123CM2 and press F4 (Prompt). You can enter the sample data in Invoking the ILE-OPM Program.
The output is the same as for the OPM version of this program.
The physical file T2123DD2 contains the same data as shown in the OPM version in Invoking the ILE-OPM Program.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.