Problem solve Get help with specific problems with your technologies, process and projects.

Create dynamic commands in a CL program using QCMDEXC

Read how to use QCMDEXC to execute a command from a CL program.

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.

CODE:

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.

==================================
MORE INFORMATION
==================================

=========================================
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.


Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close