Example: Using profile handles

This example shows how to use APIs to generate, change, and release profile handles in a CL program.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

/*******************************************************************/
/*******************************************************************/
/*                                                                 */
/* FUNCTION:  Illustrates how to generate, change, and release     */
/*            profile handles in a CL program.                     */
/*                                                                 */
/* LANGUAGE:  CL                                                   */
/*                                                                 */
/* APIs USED: QSYGETPH    - Get Profile Handle                     */
/*            QWTSETP     - Set Profile                            */
/*            QSYRLSPH    - Release Profile Handle                 */
/*                                                                 */
/*******************************************************************/
/*******************************************************************/

PGM (&USERID &PWD &PWDLEN)

/*----------------------------------------------------------*/
/* Parameters:                                              */
/*----------------------------------------------------------*/

/* 10 Character user ID                                     */
DCL        VAR(&USERID) TYPE(*CHAR) LEN(10)  

/* Password  (up to 50 bytes)                               */
/* This password is case sensitive                          */
DCL        VAR(&PWD) TYPE(*CHAR) LEN(50)     

/* Length of the password in binary(4) form (example-- a    */
/* 5 byte password length would be X'00000005)              */
DCL        VAR(&PWDLEN) TYPE(*CHAR) LEN(4)   


/*----------------------------------------------------------*/
/* Variables needed by this program:                        */
/*----------------------------------------------------------*/

/* Password CCSID value of -1. The current password level   */
/* for the system is used to determine the CCSID of the     */
/* password.                                                */
DCL        VAR(&PWDCCSID) TYPE(*CHAR) LEN(4) +
                                VALUE( X'FFFFFFFF')

/* Exceptions will be signalled                             */
DCL        VAR(&ERRCODE)  TYPE(*CHAR) LEN(8) + 
                                VALUE( X'0000000000000000')

/* Password for *CURRENT user ID. When *CURRENT is          */
/* specified for the user ID, the password field will be    */
/* ignored.                                                 */
DCL        VAR(&CURPWD)   TYPE(*CHAR) LEN(10) + 
                                VALUE('          ')

/* Profile handles returned                                 */
DCL        VAR(&PRFHNDL1) TYPE(*CHAR) LEN(12) 
DCL        VAR(&PRFHNDL2) TYPE(*CHAR) LEN(12) 

/*----------------------------------------------------------*/
/* Generate profile handles for the user ID this program    */
/* is currently running under and for the user ID passed    */
/* to this program:                                         */
/*----------------------------------------------------------*/
CALL       PGM(QSYGETPH) PARM('*CURRENT  ' + 
                              &CURPWD  /* Password ignored  +
                                          when *CURRENT is  +
                                          specified       */+
                              &PRFHNDL1)

CALL       PGM(QSYGETPH) PARM(&USERID +
                              &PWD    +
                              &PRFHNDL2 +
                              &ERRCODE   /* Exceptions will   +
                                            be signalled   */ +
                              &PWDLEN    /* Length of pwd  */ +
                              &PWDCCSID) /* Password CCSID */

/*----------------------------------------------------------*/
/* Change the user for this job to the user ID passed to    */
/* this program:                                            */
/*----------------------------------------------------------*/
CALL       PGM(QWTSETP) PARM(&PRFHNDL2)

/*----------------------------------------------------------*/
/* This program is now running under the user ID passed to  */
/* this program.                                            */
/*----------------------------------------------------------*/

/*----------------------------------------------------------*/
/* Now change the user ID for this job back to the user ID  */
/* it was originally running under                          */
/*----------------------------------------------------------*/
CALL       PGM(QWTSETP) PARM(&PRFHNDL1)

/*----------------------------------------------------------*/
/* The profile handles generated in this program can now    */
/* be released:                                             */
/*----------------------------------------------------------*/
CALL       PGM(QSYRLSPH) PARM(&PRFHNDL1)
CALL       PGM(QSYRLSPH) PARM(&PRFHNDL2)

ENDPGM