*=====================================================================                        
      * Example: how to dynamically build an EMLMSG cmd                                             
      *                                                                                             
      * - ADDLIBLE MMAIL                                                                            
      * - CRTBNDRPG MMAIL/EMLMSG123 SRCFILE(MMAIL/SAMPLERPG) DBGVIEW(*SOURCE)                       
      *         DFTACTGRP(*NO) ACTGRP(MMAIL123)                                                     
      *                                                                                             
      *=====================================================================                        
      /copy *LIBL/qrpglesrc,hspecs                                                                  
      /copy *LIBL/qrpglesrc,hspecsbnd                                                               
      /copy *LIBL/qrpglesrc,mailproto                                                               
      /copy *LIBL/qrpglesrc,prototypeb                                                              
      /copy *LIBL/qrpglesrc,variables3                                                              
      /copy *LIBL/qrpglesrc,usec                                                                    
                                                                                                    
     D subject         s             70                                                             
     D txtmbrlib       s             10                                                             
     D txtmbrfile      s             10                                                             
     D txtmbr          s             10                                                             
     D fromname        s             50                                                             
     D fromaddr        s             50                                                             
     D totype          s              4    dim(50)                                                  
     D toname          s             50    dim(50)                                                  
     D toaddr          s             50    dim(50)                                                  
                                                                                                    
     D Cmd             s          10000    varying                                                  
     D i               s             10i 0                                                          
      /free                                                                                         
          //Initialize some variables (simulates receiving input parameters)                        
          exsr Init;                                                                                
          //Build command MMAIL/EMLMSG in variable CMD                                              
          exsr BldCmd;                                                                              
          //Execute command MMAIL/EMLMSG (in variable CMD)                                          
          rc=docmd(CMD);                                                                            
          //Back to caller                                                                          
          return;                                                                                   
      /end-free                                                                                     
      *=========================================================================                    
      * Initialize some variables (simulates receiving input parameters)                            
      *=========================================================================                    
      /free                                                                                         
          Begsr Init;                                                                               
                                                                                                    
          subject='Source of pgm EMLMSG123';                                                        
          txtmbrlib='MMAIL';                                                                        
          txtmbrfile='QRPGLESRC';                                                                   
          txtmbr='EMLMSG123';                                                                       
          fromname='Giovanni B. Perotti';                                                           
          fromaddr='gb_perotti@easy400.net';                                                        
          totype(1)='*TO';                                                                          
          toname(1)='Riccardo Cinelli';                                                             
          toaddr(1)='r.cinelli@vargroup.it';                                                        
          totype(2)='*CC';                                                                          
          toname(2)='G. Fiorenzuoli';                                                               
          toaddr(2)='g.fiorenzuoli@vargroup.it';                                                    
          totype(3)='*BC';                                                                          
          toname(3)='G.B. Perotti';                                                                 
          toaddr(3)='gb_perotti@easy400.net';                                                       
                                                                                                    
          Endsr;                                                                                    
      /end-free                                                                                     
      *=========================================================================                    
      * Build command MMAIL/EMLMSG in variable CMD                                                  
      *=========================================================================                    
      /free                                                                                         
          Begsr BldCmd;                                                                             
                                                                                                    
          Cmd='MMAIL/EMLMSG SUBJECT(''' + %trim(subject) + ''')';                                   
          Cmd=Cmd + ' FROMNAME(''' + %trim(fromname) + ''')';                                       
          Cmd=Cmd + ' FROMADDR(''' + %trim(fromaddr) + ''')';                                       
          Cmd=Cmd + ' TO(';                                                                         
                                                                                                    
          for i=1 to 50;                                                                            
              if totype(i)=' ' or                                                                   
                 toname(i)=' ' or                                                                   
                 toaddr(i)=' ';                                                                     
                 leave;                                                                             
              endif;                                                                                
              Cmd=Cmd +                                                                             
                  '''' + %trim(toaddr(i)) + '''/' +                                                 
                  '''' + %trim(toname(i)) + '''/' +                                                 
                  %trim(totype(i)) + ' ';                                                           
          endfor;                                                                                   
                                                                                                    
          Cmd=Cmd + ') TXTF(' + %trim(txtmbrlib) + '/' + %trim(txtmbrfile) +                        
             ') TXTMBR(' + %trim(txtmbr) + ') EDTMBR(*NO)';                                         
                                                                                                    
          Endsr;                                                                                    
      /end-free