Get user id within rpgle

50 pts.
Tags:
RPGLE
How do I get the user id within /Free and send command to clear a workfile? Thanks!

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Teandy
    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,860 pointsBadges:
    report
  • graybeard52
    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 pointsBadges:
    report
  • Splat
    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);
    6,825 pointsBadges:
    report
  • ibBusy4sure
    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! :)
    50 pointsBadges:
    report
  • Splat
    QCAPCMD will return error message ids (and associated message variables) in the api error parameter. Very handy.
    6,825 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following