40 pts.
 Get user id within rpgle
How do I get the user id within /Free and send command to clear a workfile? Thanks!

Software/Hardware used:
ASKED: July 31, 2009  1:09 PM
UPDATED: August 6, 2009  2:26 PM

Answer Wiki:
1. User id and lots of other cool stuff is in the program data structure D ProgramDs SDS D UserID 254 263 Use the UserID anywhere in your program 2. send command to clear a workfile Provided your program isn't locking the file you could issue A CLRPGM through QCMDEXEC Phil
Last Wiki Answer Submitted:  July 31, 2009  2:28 pm  by  philpl1jb   44,180 pts.
All Answer Wiki Contributors:  philpl1jb   44,180 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

To get the user id:

D USERID S 10 INZ(*USER)

To clear a work file:

D CMD S 32702A VARYING

// *************************************************************
// * START FREE FORM CALCS.
// *************************************************************

/FREE

// *************************************************************
// * CLEAR WORK FILE.
// *************************************************************

CMD = ‘CLRPFM file_name’;
CALLP QCMDEXC(CMD : %LEN(CMD));
/END-FREE

 5,830 pts.

 

Another way to clear a work file, that does not require an exclusive lock is to issue the SQL statement
Exec SQL DELETE FROM file_name

 3,115 pts.

 

Better to use the QCAPCMD API for processing commands. I’ve got it prototyped in a /copy member as follows:

 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 * Process commands (QCAPCMD)                                          
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
D ProcCmd         Pr                  extpgm('QCAPCMD')                
D                             1024a   options(*varsize) const          
D                                9b 0 const                            
D                               20a   options(*varsize) const          
D                                9b 0 const                            
D                                8a   const                            
D                             1024a   options(*varsize) const          
D                                9b 0 const                            
D                                9b 0 const                            
D                              512a   options(*varsize) const          
                                                                       
                                                                       
D Cc_loscs        S              9b 0                                  
D Cc_ocbl         S              9b 0                                
D Cc_ocbf         S              8    inz('CPOP0100')                  
D Cc_lafccs       S              9b 0 inz(0)                           
D Cc_loccsatr     S              9b 0                                  
                                                                       
                                                                       
D Cpop0100        Ds                  inz                              
D  cpop_tocp                     9b 0 inz(0)                           
D  cpop_dbcs                     1    inz('0')                         
D  cpop_pa                       1    inz('0')                         
D  cpop_css                      1    inz('0')                         
D  cpop_mk                       4                                     
D                                9    inz(x'000000000000000000')

Here’s an example of a CLRPFM:

Cmdstr = 'CLRPFM  FILE(HSP9999) MBR('
       + %trim(outmbr)               
       + ')';                        
Proccmd(%trim(cmdstr):               
        %len(%trim(cmdstr)):         
        cpop0100:                    
        %len(cpop0100):              
        cc_ocbf:                     
        cmdstr:                      
        %len(cmdstr):                
        cc_loccsatr:                 
        api_error);
 5,670 pts.

 

Thank you so much for all this great information! It will definitely get what I need. Good points about the file being available to clear. It is a one-time conversion file and probably will end its shelf life then. But thinking ahead in case I ever do need to do something similar, it would be a good tool to have. I do like the API idea too. Maybe the QCAPCMD API has error conditioning perhaps?

Thank you all for your help! :)

 40 pts.

 

QCAPCMD will return error message ids (and associated message variables) in the api error parameter. Very handy.

 5,670 pts.