Using QSYRUSRI to check whether a user profile exists

Sometimes you have a table that captures user profiles. Obviously, if the user profile is deleted, there is nothing to delete these table entries. And sometimes, auditors can see this as a problem.

There are several ways of handling this, one of which is to make use of the QSYRUSRI API.

The Retrieve User Information (QSYRUSRI) API provides information about a user profile. This API provides information similar to the Retrieve User Profile (RTVUSRPRF) command or the Display User Profile (DSPUSRPRF) command when *BASIC is specified for the type parameter.

The following sample program makes use of the fact that, if a user profile has been deleted, the API returns blanks in all for the user profile name, previous sign-on date and time and all other text fields.

       // --------------------------------------------------------------------
       // Program     : DSPUSRI
       // Description : Display User Profile information
       //             : Experiments with the QSYRUSRI API
       // --------------------------------------------------------------------
        ctl-opt main(Main) dftactgrp(*no) actgrp(*new) bnddir('QC2LE');

       // --------------------------------------------------------------------
       // Prototype declarations
       // --------------------------------------------------------------------
        dcl-pr Main extpgm('DSPUSRI');
            UserID char(10) const;
        end-pr;

        dcl-pr RtvUsrInf extpgm('QSYRUSRI');
            RtnVariable char(2000) options(*varsize);
            RtnVarLen int(10) const;
            APIFMT char(8) const;
            UserID char(10) const;
            Error char(1) const;
        end-pr;

       // --------------------------------------------------------------------
       // Main Procedure
       // --------------------------------------------------------------------
        dcl-proc Main;

            dcl-pi Main;
                UserID char(10) const;
            end-pi;


           // ----------------------------------------------------------------
           // Data structures
           // ----------------------------------------------------------------
            dcl-ds F1 qualified inz;
                BytesRtn int(10);
                BytesAvail int(10) inz(%size(F1));
                UserProfile char(10) inz;
                LastSignon char(13) inz;
                res1 char(1) inz;
                BadSignons int(10) inz;
                Status char(10) inz;
                PwdChange char(8) inz;
                NoPassword char(1) inz;
                res2 char(1) inz;
                PasswordExpInt int(10) inz;
                PasswordExpires char(8) inz;
                DaysToPassExp int(10) inz;
                PasswordExpired char(1) inz;
                DspSignOn char(10) inz;
                LocalPassword char(1) inz;
            end-ds;

           // ----------------------------------------------------------------
           // Standalone fields
           // ----------------------------------------------------------------
            dcl-s OutText char(50);

           // ----------------------------------------------------------------
           // Procedure mainline
           // ----------------------------------------------------------------

            // Retrieve the user profile
            RtvUsrInf(F1: %size(F1): 'USRI0100': UserID: ' ');

            if F1.UserProfile = *blank and F1.LastSignon = *blank;
                OutText = %trim(UserID) + ' has gone';
            else;
                OutText = %trim(UserID) + ' is still here';
            endif;

            dsply OutText;

        end-proc;
       // --------------------------------------------------------------------

You can call this program with the user ID as a parameter and it will display a message indicating whether or not the user profile exists. Extending it to do something useful is a pretty straightforward process.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.