How to execute CL commands from RPGLE program using QCMDEXC API

To execute CL commands from RPGLE you have to use the QCMDEXC API. This program requires two parameters. The first parameter is a character string containing the command you wish to execute. The second parameter is of length 15 with 5 decimal places to specify the length of first parameter string value. Here is sample RPGLE program...

h option(*nodebugio) actgrp(*CALLER) dftactgrp(*no)    
d Exc_Cmd         PR                  extpgm('QCMDEXC')
d  command                     200A   const            
d  length                       15P 5 const            
d $command        s            512a                    
  $command = 'DSPF ''/tmp/mySample.html''';            
  Exc_Cmd(%trim($command): %len(%trim($command)));     
c                   eval      *inlr = *on              
c                   return                             

Tip: Using the %len() command helps us specify the length of command string in first parameter!

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.