MONMSG on QCMDEXC

Hi All,

I am working on an RPG program in which I have a need to use the QCMDEXC command to perform a CL operation (for example ADDPFM). I have been able to run the QCMDEXC command but I dont have a definite answer on how I can track any MONMSG's that come out of running the CL command? For instance, when trying to add a member to a physical file, if there is an error, I want to know what that error message is so that I can chose the next instruction on my RPG.

I do not want to use the option of calling a CL from my RPG to perform the commands. I have to get all this done with a single RPG.

Thanks for your help.

Regards
Ali.
bhagataliAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tliottaCommented:
You can't use MONMSG to monitor for messages from commands that are executed by QCMDEXC.

I do not want to use the option of calling a CL from my RPG to perform the commands.

If you're certain that you want to do it the hard way, then you'll need to learn how to use various Message Handling APIs.

You'll probably need to learn how to use the Send Program Message (QMHSNDPM) API to set a marker message in the job's message queue before calling QCMDEXC. After QCMDEXC returns, use the Receive Program Message (QMHRCVPM) API to receive messages that were sent after your marker message and analyze each one.

It'll be up to your code to determine which ones that you receive are ones that need to be acted upon.

If you know you're going to execute specific commands, it's much cleaner just to write and call into a CL procedure. CL already provides everything that you'll need. Why code a replacement for the CL run-time that already exists in the system? The CL will be a lot simpler than RPG code to do the same things and much easier to maintain. A CL module would also be compiled and far more efficient than having QCMDEXC interpret the command.

Tom
0
bhagataliAuthor Commented:
Thanks Tom, I completely agree with what you say about the CL. I am a big fan of doing it in CL too but in this case I have been asked to stick to RPG. I guess, now would be as good as any time for me to learn those message handling API's :).
0
tliottaCommented:
When you put a 'marker' message onto a program or job message queue, you need to retrieve and save its 'message mark'. Later, when you need to retrieve messages, use the saved 'message mark' as your starting point. Retrieve "next" messages in order by using each message's mark to get the next one.

That usually helps you to get messages even from program message queues after that program is no longer on the call stack. It can get ugly, but that's life.

Tom
0
MurpheyApplication ConsultantCommented:
Use the Monitor message in your RPG Progam to catch the errormessage/code of the QCMDXC
here an example how to do that

h option(*nodebugio)                                 
                                                      
d $cmp            s              2a                  
d $ord            s              6a                  
d $bocd           s              2a                  
d $session        s             24a                  
d $status         s              1a                  
                                                      
d dtaq_name       s             10a                  
d dtaq_lib        s             10a                   
d dtaq_len        s              5p 0                   
d dtaq_data       s            256                      
                                                        
d $web_path       s            101a                     
d $pdf_path       s            101a                     
d $path           s             50a   inz('/directory')   
d $pdf_name       s             50a                     
d $found          s              1a                     
d $count          s              3s 0                   
d @CmdStr         s            512a   inz               
d @Apostr         s              1a   inz(X'7D')        
                                                        
 *  Program Information                                 
d progstatus     sds                                    
d  parms            *parms                              
d  progname         *proc                               
d  errmsgID              40     46                      
d  errmsg                91    169                      
d  jobname              244    253                      
d  userid               254    263                      
d  jobnumber            264    269                      
                                                        
d ExcCmd          PR                  ExtPgm('QCMDEXC') 
d  Cmd_Str                     512a   Options(*VARSIZE)          
d                                     Const                      
d  Cmd_Len                      15p 5 Const                      
                                                                 
c     *entry        plist                                        
c                   parm                    $cmp                 
c                   parm                    $ord                 
c                   parm                    $bocd                
c                   parm                    $session             
c                   parm                    $status              
                                                                 
c                   eval      $status = *blanks                  
                                                                 
c                   eval      $pdf_name = %trim(userid) + '.PDF'  
                                                           
c                   eval      dtaq_data = $cmp +           
c                                         $ord +           
c                                         $bocd +          
c                                         $path +          
c                                         $pdf_name        
 
c*--- Sending request to Data Queue to generate my PDF file                                                           
c                   call      'QSNDDTAQ'                   
c                   parm      '@INVOICE'    dtaq_name      
c                   parm      '*LIBL'       dtaq_lib       
c                   parm      256           dtaq_len       
c                   parm                    dtaq_data      
                                                           
c                   eval      $path = %trim($path) + '/'   
c                   eval      @CmdStr = 'DLYJOB DLY(5)'    
c                   callp     ExcCmd(%Trim(@CmdStr) :      
c                                   %Len(%Trim(@CmdStr)))  
                                                           
c                   dou       $count > 20                  
c                   call      'CHKIFS'                     
c                   parm                    $path          
c                   parm                    $pdf_name      
c                   parm                    $found         
                                                                   
c                   if        $found = 'Y'                         
c                   leave                                          
c                   endif                                          
                                                                   
c                   eval      @CmdStr = 'DLYJOB DLY(3)'            
c                   callp     ExcCmd(%Trim(@CmdStr) :              
c                                   %Len(%Trim(@CmdStr)))          
c                   eval      $count = $count + 1                  
c                   enddo                                          
                                                                   
c                   if        $found = 'Y'                         
                                                                   
c                   eval      $web_path = '/MySite/InvoicePdf/' +  
c                                         %trim($session) + '.pdf' 
c                   eval      $pdf_path = %trim($path) +           
c                                         %trim($pdf_name)         
                                                                   
c                   eval      @CmdStr = 'CPY OBJ(' + @Apostr +     
c                                       %trim($pdf_path) +         
c                                       @Apostr + ') TOOBJ(' +     
c                                       @Apostr +                  
c                                       %trim($web_path) +         
c                                       @Apostr + ') REPLACE(*YES)'
                                                                   
 /free                                                             
    $count = 0;                                                    
    dou $count > 10;                                               
      monitor;                                                     
          callp ExcCmd(%Trim(@CmdStr) :                            
                    %Len(%Trim(@CmdStr)));                         
      on-error;                                                    
        select;                                                    
          when errmsgID = 'CPFA09E';                               
             callp ExcCmd('DLYJOB DLY(3)':13);                     
             $count = $count + 1;                                  
             iter;                                                 
          other;                                                   
             leave;                                                
        endsl;                                                     
      endmon;                                                      
                                                                   
      $status = 'Y';                                               
      leave;                                                       
    enddo;                                                         
 /end-free                                                         
                                          
c                   endif                 
                                          
c                   eval      *inlr = *on 
c                   return  

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tliottaCommented:
MONITOR can be used to catch *ESCAPE messages from QCMDEXC. But depending on whether your program needs to know the cause of the problem or not, you can still need to set a marker message and receive and analyze messages as noted above.

For example, you might find a CPF2817 saying 'Copy command ended because of error.' In order for your program to find the "error", you have to 'See the messages previously listed.' There can be a lot of messages like that.

Tom
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.