You can also run a program from your own CL command. To create a command:
The CRTCMD command definition includes the command name, parameter descriptions, and validity-checking information, and identifies the program that performs the function requested by the command.
The program called by your command is run.
The following example illustrates how to run a program from a user-created command:
A newly created command COST prompts for and accepts user input values. It then calls a C++ program CALCOST and passes it the input values. CALCOST accepts the input values from the command COST, performs calculations on these values, and prints results. Figure 31 illustrates this example.
Figure 31. Calling Program CALCOST from a User-Defined Command COST
![]() |
To create and run the example, follow the steps below:
CRTCMD CMD(MYLIB/COST) PGM(MYLIB/CALCOST) SRCFILE(MYLIB/QCMDSRC)
CRTBNDCPP PGM(MYLIB/CALCOST)
Hammers 1.98 5000
The output of program CALCOST is:
+--------------------------------------------------------------------------------+ | It costs $11385.00 to buy 5000 HAMMERS | | Press ENTER to end terminal session. | | > | +--------------------------------------------------------------------------------+
Figure 32. Source Code for Command Prompt that Runs the CALCOST Program
|
Figure 33. Source Code for Program CALCOST
// calcost.cpp // Source for Program CALCOST #include <iostream.h> #include <string.h> #include <bcd.h> int main(int argc, char *argv[]) { char *item_name; _DecimalT<10,2> *price; short int *quantity; const _DecimalT<2,2> taxrate=__D("0.15"); _DecimalT<17,2> cost; item_name = argv[1]; price = (_DecimalT<10,2> *) argv[2]; quantity = (short *) argv[3]; cost = (*quantity)*(*price)*(__D(1.00+taxrate)); cout << "\nIt costs $" << cost << " to buy " << *quantity << " " << item_name << endl; } |
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.