Troubleshooting
Problem
This document describes how to retrieve the user profile an ODBC job (QZDASOINIT) or a file server job (QPWFSERVSO) is running under from an IBM i program.
Resolving The Problem
How do I retrieve the user profile an ODBC job is running under from an IBM i program? How do I retrieve the current user profile which a client job such as QZDASOINIT or QPWFSERVSO is using?
Most of the optimized host server programs used by Access Client Solutions use prestart jobs. The job name of the prestart job always contains the name of the user profile that started the job. The default subsystem configuration sets this user profile to QUSER. For example, 073623/QUSER/QZDASOINIT is a typical TCP/IP connected ODBC job name.
When a client application or API starts a communications job with IBM i host servers, the server calls the Set Profile API (QWTSETP). This API swaps the active user profile to the user profile passed by the client. This user profile becomes the current user. The job log is updated with a CPIAD02, Servicing user profile xxxx, message or a CPIAD12 indicating the user and IP address or host name that it is using. This swap allows the job to run with the authority defined for the user profile the communication job was started with rather than QUSER. Other characteristics of the job, such as job name, owner of spooled files, do not change. For more information about the QWTSETP API, see System API Reference.
Some IBM i users directly or indirectly call a program that needs to retrieve the user profile that a job is running under. They typically use the Retrieve Job Information API (QUSRJOBI) to retrieve the
If the program that needs to retrieve the current user profile is called directly from the target prestart job, then the CL command RTVJOBA can also be used. For example, a user exit program or ODBC stored procedure could simply call the CL command RTVJOBA CURUSER(&CURUSR).
Tip:
To locate a specific user's job interactively, use the command WKROBJLCK xxxxx *USRPRF where xxxxx is the user profile name. The results show a list of all active jobs for the user profile (including prestart jobs). This method is typically quicker than scanning job logs for the servicing user profile message.
Note: Starting at V5R4, the WRKACTJOB command displays the current user of an active job rather than the user profile that the job was started under. This capability might eliminate the need to have a program such as this one. Sample CL Program
Most of the optimized host server programs used by Access Client Solutions use prestart jobs. The job name of the prestart job always contains the name of the user profile that started the job. The default subsystem configuration sets this user profile to QUSER. For example, 073623/QUSER/QZDASOINIT is a typical TCP/IP connected ODBC job name.
When a client application or API starts a communications job with IBM i host servers, the server calls the Set Profile API (QWTSETP). This API swaps the active user profile to the user profile passed by the client. This user profile becomes the current user. The job log is updated with a CPIAD02, Servicing user profile xxxx, message or a CPIAD12 indicating the user and IP address or host name that it is using. This swap allows the job to run with the authority defined for the user profile the communication job was started with rather than QUSER. Other characteristics of the job, such as job name, owner of spooled files, do not change. For more information about the QWTSETP API, see System API Reference.
Some IBM i users directly or indirectly call a program that needs to retrieve the user profile that a job is running under. They typically use the Retrieve Job Information API (QUSRJOBI) to retrieve the
User name field. This field contains the user profile of the fully qualified job name, not the current user profile. To retrieve the active user profile, the program must use the JOBI0600 format and retrieve the Current user profile field. This field returns the user profile that the host server communications job is running with.If the program that needs to retrieve the current user profile is called directly from the target prestart job, then the CL command RTVJOBA can also be used. For example, a user exit program or ODBC stored procedure could simply call the CL command RTVJOBA CURUSER(&CURUSR).
Tip:
To locate a specific user's job interactively, use the command WKROBJLCK xxxxx *USRPRF where xxxxx is the user profile name. The results show a list of all active jobs for the user profile (including prestart jobs). This method is typically quicker than scanning job logs for the servicing user profile message.
Note: Starting at V5R4, the WRKACTJOB command displays the current user of an active job rather than the user profile that the job was started under. This capability might eliminate the need to have a program such as this one. Sample CL Program
/* ***************************************************************** */
/* PROGRAM: LSTCURUSR */
/* */
/* LANGUAGE: CL */
/* */
/* INPUT: CHAR(10) - USER PROFILE NAME OR BLANK */
/* */
/* DESCRIPTION: THIS PROGRAM IS AN EXAMPLE OF HOW TO RETRIEVE */
/* THE CURRENT USER AN ODBC JOB IS RUNNING UNDER. */
/* */
/* THIS PROGRAM WILL LIST THE FULLY QUALIFIED ODBC */
/* JOB NAME AND THE USER PROFILE THAT THE JOB IS */
/* CURRENTLY RUNNING UNDER (CURRENT USER) FOR EITHER */
/* ALL ACTIVE ODBC JOBS (INPUT PARAM IS BLANK) OR */
/* A SPECIFIC USER PROFILE (PASSED AS INPUT PARAM). */
/* THE LISTING IS IN THE JOBLOG. */
/* THE SAMPLE PROGRAM ONLY RETRIEVES TCP/IP CONNECTED */
/* ODBC JOBS (QZDASOINIT). CHANGE THE JOB NAME TO */
/* QZDAINIT TO RETRIEVE SNA ATTACHED JOBS. */
/* */
/* THIS PROGRAM RETRIEVES A LIST OF ALL QZDASOINIT */
/* JOBS. IT THEN PULLS THE JOB INFO FOR EACH OF */
/* OF THESE JOBS. IT USES FORMAT 0600 TO FIND THE */
/* CURRENT USER. IT USES FORMAT 0200 TO */
/* RETRIEVE THE JOB ACTIVE STATUS. */
/* */
/* APIS USED: QUSCRTUS, QUSDLTUS, QUSLJOB, QUSRTVUS, QUSRJOBI */
/* */
/* DXD V1.0 */
/* ***************************************************************** */
PGM PARM(&TARGETUSER)
/* */
/* LOCAL VARIABLES */
/* */
DCL VAR(&TARGETUSER) TYPE(*CHAR) LEN(10) +
VALUE(' ') /* BLANK - ALL USERS, +
otherwise list only jobs for that +
specific user */
DCL VAR(&TEMP) TYPE(*CHAR) LEN(5)
DCL VAR(&ERR) TYPE(*CHAR) LEN(8) +
VALUE(X'0000000000000000')
DCL VAR(&USRSPC) TYPE(*CHAR) LEN(20) +
VALUE('CHGA QTEMP ') /* USER +
SPACE NAME FOR APIS */
DCL VAR(&BIN4) TYPE(*CHAR) LEN(4) /* NUMBER OF +
JOBS FOR LIST JOB AND USER SPACE OFFSET +
IN BINARY 4 FORM */
DCL VAR(&LOOP) TYPE(*DEC) LEN(8 0) /* NUMBER OF +
JOBS FROM LIST JOB */
DCL VAR(&DEC8) TYPE(*DEC) LEN(8 0) /* USER SPACE +
OFFSET IN DECIMAL 8,0 FORM */
DCL VAR(&ELEN) TYPE(*DEC) LEN(8 0) /* LIST JOB +
ENTRY LENGTH IN DECIMAL 8,0 FORM */
DCL VAR(&ELENB) TYPE(*CHAR) LEN(4) /* LIST JOB +
ENTRY LENGTH IN BINARY 4 FORM */
/* DATA IN THE LIST JOB INFORMATION */
DCL VAR(&LJOBE) TYPE(*CHAR) LEN(56) /* RETRIEVE +
AREA FOR LIST JOB ENTRY */
DCL VAR(&FQJOBNAME) TYPE(*CHAR) LEN(26) +
VALUE(' *ALL ')
DCL VAR(&JOBNAME) TYPE(*CHAR) LEN(10)
DCL VAR(&USER) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBNUMBER) TYPE(*CHAR) LEN(10)
DCL VAR(&INTJOB) TYPE(*CHAR) LEN(16) /* RETRIEVE +
AREA FOR INTERNAL JOB ID */
/* DATA IN THE JOBI API INFORMATION */
DCL VAR(&JOBI) TYPE(*CHAR) LEN(104) /* RETRIEVE +
AREA FOR JOB INFORMATION */
DCL VAR(&JOBI200) TYPE(*CHAR) LEN(111) /* +
RETRIEVE AREA FOR JOB INFORMATION */
DCL VAR(&JOBTYPE) TYPE(*CHAR) LEN(1) /* JOB TYPE */
DCL VAR(&STATUS) TYPE(*CHAR) LEN(10) /* JOB TYPE */
DCL VAR(&ACTSTATUS) TYPE(*CHAR) LEN(4)
DCL VAR(&CURUSER) TYPE(*CHAR) LEN(10) /* +
RETRIEVE JOB NAME */
DCL VAR(&RJOB) TYPE(*CHAR) LEN(10) /* RETRIEVE +
JOB NAME */
DCL VAR(&RUSER) TYPE(*CHAR) LEN(10) /* RETRIEVE +
USER NAME */
DCL VAR(&RNBR) TYPE(*CHAR) LEN(6) /* RETRIEVE +
JOB NUMBER */
/* */
/* START OF EXECUTABLE CODE */
/* */
/* */
/* DELETE USER SPACE IF IT ALREADY EXISTS */
/* */
/* CHGVAR VAR(&EUSRSPC) VALUE(%SST(&USRSPC 1 10)) */
CALL PGM(QUSDLTUS) PARM(&USRSPC &ERR)
MONMSG CPF0000
/* */
/* CREATE USER SPACE */
/* */
CALL PGM(QUSCRTUS) PARM(&USRSPC 'CHGACTJOB ' +
X'00011000' ' ' '*ALL ' 'QSERVER JOB +
LIST TEMP USER SPACE ')
/* */
/* LIST ACTIVE JOBS WITH JOB NAME SPECIFIED */
/* */
CALL PGM(QUSLJOB) PARM(&USRSPC 'JOBL0100' +
'QZDASOINITQUSER *ALL ' '*ACTIVE ')
/* */
/* RETRIEVE NUMBER OF ENTRIES RETURNED. CONVERT TO DECIMAL AND */
/* */
CALL PGM(QUSRTVUS) PARM(&USRSPC X'00000085' +
X'00000004' &BIN4)
CHGVAR VAR(&LOOP) VALUE(%BINARY(&BIN4))
CHGVAR VAR(&TEMP) VALUE(&LOOP)
SNDPGMMSG MSG(&TEMP *BCAT ' QZDASOINIT JOBS TO BE +
PROCESSED')
IF COND(&LOOP = 0) THEN(GOTO CMDLBL(ALLDONE))
/* */
/* RETRIEVE LIST ENTRY LENGTH, CONVERT TO DECIMAL. */
/* RETRIEVE LIST ENTRY OFFSET, CONVERT TO DECIMAL, AND ADD ONE */
/* TO SET THE POSITION. */
/* */
CALL QUSRTVUS (&USRSPC X'00000089' X'00000004' +
&ELENB)
CHGVAR &ELEN %BINARY(&ELENB)
CALL QUSRTVUS (&USRSPC X'0000007D' X'00000004' +
&BIN4)
CHGVAR VAR(&DEC8) VALUE(%BINARY(&BIN4))
CHGVAR VAR(&DEC8) VALUE(&DEC8 + 1)
/* */
/* LOOP FOR THE NUMBER OF JOBS UNTIL NO MORE JOBS THEN GO TO */
/* ALLDONE LABEL */
/* */
STARTLOOP: IF (&LOOP = 0) THEN(GOTO ALLDONE)
/* */
/* CONVERT DECIMAL POSITION TO BINARY 4 AND RETRIEVE LIST JOB ENTRY */
/* */
CHGVAR VAR(%BINARY(&BIN4)) VALUE(&DEC8)
CALL QUSRTVUS (&USRSPC &BIN4 &ELENB +
&LJOBE)
/* */
/* COPY INTERNAL JOB IDENTIFIER AND RETRIEVE JOB INFORMATION FOR */
/* BASIC INFORMATION. */
/* */
CHGVAR VAR(&INTJOB) VALUE(%SST(&LJOBE 27 16))
CALL PGM(QUSRJOBI) PARM(&JOBI X'00000068' +
'JOBI0600' '*INT ' +
&INTJOB)
CALL PGM(QUSRJOBI) PARM(&JOBI200 X'0000006F' +
'JOBI0200' '*INT ' +
&INTJOB)
/* */
/* COPY JOB TYPE, ACTIVE JOB STATUS, CURRENT USER AND ANY OTHER */
/* JOB INFORMATION NEEDED. */
/* */
CHGVAR VAR(&JOBTYPE) VALUE(%SST(&JOBI 61 1))
CHGVAR VAR(&CURUSER) VALUE(%SST(&JOBI 92 10))
CHGVAR VAR(&STATUS) VALUE(%SST(&JOBI 51 10))
CHGVAR VAR(&RJOB) VALUE(%SST(&JOBI 9 10))
CHGVAR VAR(&RUSER) VALUE(%SST(&JOBI 19 10))
CHGVAR VAR(&RNBR) VALUE(%SST(&JOBI 29 6))
CHGVAR VAR(&ACTSTATUS) VALUE(%SST(&JOBI200 108 4))
IF COND((&TARGETUSER *EQ ' ') *OR +
(&TARGETUSER *EQ &CURUSER)) +
THEN(SNDPGMMSG MSG('JOB' *BCAT &RNBR +
*TCAT '/' *TCAT &RUSER *TCAT '/' *TCAT +
&RJOB *TCAT ' CURRENT USER:' *TCAT +
&CURUSER *TCAT ' ACTIVE STATUS:' *TCAT +
&ACTSTATUS *TCAT ' STATUS:' *TCAT &STATUS +
*BCAT ' JOBTYPE: ' *TCAT &JOBTYPE))
/* */
/* PERFORM ANY SPECIAL JOB PROCESSING HERE */
/* */
/* */
/* AT END OF LOOP SET NEW DECIMAL POSITION TO NEXT ENTRY AND */
/* DECREMENT LOOP COUNTER BY ONE. */
/* */
ENDLOOP: CHGVAR VAR(&DEC8) VALUE(&DEC8 + &ELEN)
CHGVAR VAR(&LOOP) VALUE(&LOOP - 1)
GOTO CMDLBL(STARTLOOP)
/* */
/* ALL DONE. NOW DELETE TEMPORARY USER SPACE THAT WE CREATED. */
/* */
ALLDONE:
CALL PGM(QUSDLTUS) PARM(&USRSPC &ERR)
MONMSG MSGID(CPF0000)
ENDPGM
[{"Product":{"code":"SWG60","label":"IBM i"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Host Servers","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"Version Independent","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]
Historical Number
8021834
Was this topic helpful?
Document Information
Modified date:
29 June 2021
UID
nas8N1010230