Hi Charles,
On 5/29/2013 10:48 PM, Charles Pascoe wrote:
    The ultimate goal of this process (for us) is to imbed a call to the
    program to swap users to a common user that exists on the Windows Network
    and create an .XLS or .XLSX file from a spool file and write it out to a
    Network Folder.
I haven't heard any further info from you on what you're trying to do 
(swap with password, or swap without?)
But here's a very simple example of using these APIs to swap without 
passwords.  This is intended for a situation where the calling user has 
(at least) *USE authority to the "common" user profile, and so can swap 
to it without needing a password.
PGM
       DCL VAR(&ORIGUSER) TYPE(*CHAR) LEN(12)
       DCL VAR(&SFTPUSER) TYPE(*CHAR) LEN(12)
       MONMSG (CPF0000 MCH0000) EXEC(GOTO DONE)
       CALL PGM(QSYGETPH) PARM(*CURRENT *NOPWD &ORIGUSER)
       CALL PGM(QSYGETPH) PARM(the-common-user *NOPWD &SFTPUSER)
       CALL PGM(QWTSETP) PARM(&SFTPUSER)
       /*  ... RUN THE EXCEL STUFF HERE ...   */
DONE:  CALL PGM(QWTSETP) PARM(&ORIGUSER)
       CALL PGM(QSYRLSPH) PARM(&ORIGUSER)
       CALL PGM(QSYRLSPH) PARM(&SFTPUSER)
ENDPGM
As you can see... it's pretty simple, I didn't need another special 
program to implement this, I just called the APIs directly from the CL.
I start by calling QSYGETPH with *CURRENT to get a handle for the 
current userid -- that way, I don't have to worry about whether the 
common user has authority, because I have the handle before I swap.  The 
current user always has authority to his own user profile :-)
Then, I get the profile handle for the common user with QSYGETPH. 
(You'll need to replace 'the-common-user' with the proper user profile 
name.)  Assuming that you have at least *USE authority to that profile, 
you should be able to get the profile handle without needing a password.
Then, it calls QWTSETP to do the actual swap -- and we're set, we can do 
the special stuff that requires the common user profile.
After doing that, it calls QWTSETP to switch back to the original user 
profile, and releases both profile handles with QSYRLSPH, to prevent the 
possible memory leak.
It's important to note that there's a global MONMSG here so that if 
something should go wrong, it'll still swap back to the original profile 
and release the profile handles.   But, the error message will be sent 
to the job log, too, so you'll be able to view the job log to see what 
went wrong.
 
As an Amazon Associate we earn from qualifying purchases.