Most of us have used QCMDEXC to execute a CL program from an RPG program, but you can also use QCMDEXC to execute...
a command from a CL program. At first glance that sounds silly, but by using QCMDEXC you can dynamically execute commands that your CL program doesn't have to know about at compile time.
You can also execute commands whose total number of parameters are not known until time of execution. Some possible uses of this technique include, but are not limited to, running OPNQRYF with input provided by a user, running commands from a menu system, and saving a user's library list. The following example program shows a basic use of the QCMDEXC command. This program will save the user's library list, allow for some sort of processing and then change the library list back to its original form when the program is done. This is useful if you have users bouncing between menus of different application systems that require different library lists.
Click here for an additional example of the QCMDEXC command.
PGM DCL VAR(&LIBL) TYPE(*CHAR) LEN(275) DCL VAR(&LEN) TYPE(*DEC) LEN(15 5) VALUE(512) BEGIN: /* RETRIEVE ORIGINAL LIBRARY LIST */ RTVJOBA USRLIBL(&LIBL) CHGLIBL: /* CHANGE LIBRARY LIST */ /* PUT CODE CHANGES HERE */ ENDPGM: /* CHANGE LIBRARY LIST BACK TO ORIGINAL VALUES */ CHGVAR VAR(&CMD) VALUE('CHGLIBL LIBL(' *CAT &LIBL + *TCAT ')') CALL PGM(QCMDEXC) PARM(&CMD &LEN) ENDPGM
About the author: Tim is vice president of Technical Services at Interlink Technologies in Maumee, Ohio, where he serves as chief architect for their warehouse management system. He has worked in the banking, insurance, healthcare and distribution industries in various positions, including programmer/analyst, systems analyst and DP manager. Tim has worked on IBM midrange platforms since 1983.
- The Best AS/400 Web Links for Programmers
- Ask your programmer questions--or help out your peers by answering them--in our live programmer discussion forum.
- Ask the Experts yourself: Our programmer gurus are waiting to answer your technical questions.
- What do you think of this tip? Send us your comments -- good or bad -- at email@example.com
MEMBER-SUBMITTED PROGRAMMER TIPS
Search400 members recently submitted the following programmer tips. You probably have some tips of your own. Why not send them in? You could win some great prizes.
- Recursive call
Submitted by Roldao Silva
- RPG ILE made easier
Submitted by Drew Dekreon
- Right-justifying numerical input in a character
Submitted by Gordon Pu
- Alternate find messages by description
Submitted by Mark Kennedy