RPGIV @ Work

A unique site for RPG and System i Lovers

Welcome!

Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Who's the Current User? Print E-mail
User Rating: / 1
PoorBest 
Written by Chamara Withanachchi   

When a new job is started on i5/OS, three fields are combined to create a job identifier. These fields are the job name, user ID, and job number. After this identifier has been created, you can use it to refer to the job on various CL commands and APIs. The user ID in this job identifier never changes.


Sometimes it's necessary to change the user ID of a job while it's running. This is particularly common in network services, because the job needs to start and wait for a network connection, and then after a user signs in, it needs to switch its user profile to that of the signed-in user. When this happens, the job's current user ID doesn't match the one listed in the job identifier.


The PSDS lists the three fields that make up the job identifier in positions 244-269 as follows:

     D PSDS           SDS
   D   JobName             244    253A  
   D   JobUser             254    263A  
   D   JobNbr              264    269S 0

If the user ID that you're using in your program is the one from positions 254-263, the problem that you described occurs. You see, the VB program is calling your RPG program through a network server program. That program starts out as QUSER and changes to the right user profile as soon as the user signs in. Because you're retrieving the user ID from the job identifier, it remains QUSER.


However, the current user is listed in positions 358-367 of the same data structure. For example, you could code your program as follows:

     D PSDS           SDS                 
   D   CurUser             358    367A 

When you need to know the current user ID, use this field instead of the one that's part of the job identifier. This field contains the current user ID of the job at the time that your program was started.


Using this field instead of the one that's part of the job identifier solves the problem of getting the current user profile when a program is called from VB. It also works properly in Web applications and other places where a program might be run over a network.

 

However, there's one relatively obscure situation in which it won't work. If your program uses the Profile Handle APIs or the Profile Token APIs to switch user profiles while the program is running, the user profile in positions 358-367 is not changed, because it's updated only when the program starts. If you do use these APIs, you have to put the code to retrieve the current user profile in a separate program and call it when you need it.

 

<Previous   Next>