Calling OPM Programs - IBM-ILE

This program demonstrates some typical steps in creating a program that uses several ILE and OPM programming languages.

Program Description

The program is a small transaction-processing program that takes as input the item name, price, and quantity for one or more products. As output, the program displays the total cost of the items specified on the display and writes an audit trail of the transactions to a file.

Thisshows the basic flow of the program.

Basic Program Structure

Basic Program Structure

Program Structure

The program consists of these components:

  • A CL command T2123CM2 that accepts the users input and passes it to an OPM CL program
  • An OPM CL program T2123CL2 that processes the input and passes it to an ILE C++ program
  • An ILE C++ program T2123IC5 that calls an OPM COBOL program to process the input, and an OPM RPG program to write the audit trail to an externally described file
  • An OPM COBOL program T2123CB1 that completes the calculation and formats the cost
  • An OPM RPG program T2123RP1 that updates the audit file with each transaction
  • An externally described file T2123DD2 that receives the audit trail

Program Activation

The ILE C++ program T2123IC5 is 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.

The OPM CL, COBOL, and RPG programs are activated within the OPM default activation group.

This shows the structure of this program in ILE.

Structure of the Program in ILE C++

Structure of the Program in ILE C++

Program Files

The source code for each of the files that compose this program are an externally described file, a CL program,a CL command prompt, a C++ source file, and OPM COBOL program and an OPM RPG program.

Externally Described File T2123DD2

The file T2123DD2 contains the audit trail for the C++ program T2123IC5. The DDS source defines the fields for the audit file:

CL Program T2123CL2

The CL program T2123CL2 passes the CL variables item_name, price, quantity and user_id by reference to an ILE C++ program T2123IC5

The Retrieve Job Attributes (RTVJOBA) command obtains the user ID for the audit trail. Arguments are passed by reference. They can be changed by the receiving ILE C++ program. The variables containing the user and item names are explicitly null-terminated in the CL program.

Note: CL variables and numeric literals are not passed to an ILE C++ program with null-terminated strings. Character literals and logical literals are passed as null-terminated strings but are not widened with blanks. Numeric literals such as packed decimals are passed as 15,5 (8 bytes). Floating point constants are passed as double precision floating point values (1.2E+15).

CL Command Prompt T2123CM2

You use the CL command prompt T2123CM2 to prompt the user to enter item names, prices, and quantities that will be used by the C++ program T2123IC5.

C++ Source File T2123IC5

The C++ source file T2123IC5 contains a main() function which receives the incoming arguments from the CL program T2123CL2. These arguments have been verified by the CL command prompt T2123CM2 and null-terminated within the CL program T2123CL2. All the incoming arguments are pointers.

The main() function calls the function CalcAndFormat() which is mapped to a COBOL name. It passes the price, quantity, taxrate, formatted_cost, and a success_flag to the OPM COBOL program T2123CB1 using the extern "OS nowiden" linkage specification, because the OPM COBOL program is not expecting widened parameters.

The formatted_cost and the success_flag values are updated in the C++ program T2123IC5.If CalcAndFormat() returns successfully a record is written to the audit trail by WriteAuditTrail() in the OPM RPG program.

The main() function in program T2123IC5 calls WriteAuditTrail() which is mapped to an RPG program name, and passes the user_id, item_name, price, quantity, taxrate,and formatted_cost, using the extern "OS" linkage specification.

Note: By default,the compiler converts a short integer to an integer unless the nowiden parameter is specified on the extern linkage specification. The short integer in the C++ program is converted to an integer, and then passed to the OPM RPG program. The RPG program is expecting a 4 byte integer for the quantity variable. See “Understanding Data-Type Compatibility” for information on data-type compatibility.

OPM COBOL Program T2123CB1

The OPM COBOL program T2123CB1 receives pointers to the values of the variables price, quantity and taxrate, and pointers to formatted_cost and success_flag.

The CalcAndFormat() function in program T2123CB1 calculates and formats the total cost. Parameters are passed from the ILE C++ program to the OPM COBOL program to do the tax calculation.

OPM RPG Program T2123RP1

The OPM RPG program T2123RP1 contains the WriteAuditTrail() function which writes the audit trail for the program.Invoking the ILE-OPM Program

To nter data for the program T2123IC5 enter the command T2123CM2 and press F4 (Prompt).

You can enter this data into T2123CM2:

Hammers
1.98
5000
Nails
0.25
2000

The output is:

OPM RPG Program T2123RP1

The physical file T2123DD2 contains this data:

SMITHE HAMMERS 0000000198500015$11,385.0007 2893
SMITHE NAILS 0000000025200015 $575.0007 2893

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM-ILE Topics