IBM Support

How to change the Owner of all objects owned by a User without Deleting the User.

Question & Answer


Question

How do you change the owner of all objects owned by a User profile without using the *CHGOWN option on the DLTUSRPRF command.  

Answer

The OBJECT_OWNERSHIP view returns ownership information for all objects owned by a User profile.  The results can be used to programmatically  change the owner of the objects owned by a profile to another User ID on the system. 

The values returned for the columns in the view are closely related to the values returned by the WRKOBJOWN CL command and the List Objects User Is Authorized to, Owns, or Is Primary Group of (QSYLOBJA) API.

Authorization: The caller must have *READ authority to the user profile that owns the object.  The user executing the SQL must have *ALLOBJ special authority at their user profile level to be able to change the ownership of certain types of objects in the system. 

The SQL table function is available with the following PTFs:
  • R750:  Base
  • R740:  SF99704 Level 4
  • R730: SF99703 Level 16
NOTE:  If the system is not update to date with PTFs thus not having the new SQL functions, this document can be used that uses a CL program:  https://www.ibm.com/support/pages/node/642243
For Library Type Objects:
To get a listing of the all Library type objects owned by a user and generate a CL command string using CHGOBJOWN. 
 
1) Open the ACS Run SQL Scripts tool 
2) Run the following SQL:
WITH TEMPOBJ (OBJECT_NAME, OBJECT_LIBRARY, OBJECT_TYPE) AS (
        SELECT OBJECT_NAME,
               OBJECT_LIBRARY,
               OBJECT_TYPE
            FROM QSYS2.OBJECT_OWNERSHIP
            WHERE AUTHORIZATION_NAME = 'V6CASTIL' ---  User ID of current owner
                  AND PATH_NAME IS NULL
    )
    SELECT OBJECT_NAME,
           OBJECT_LIBRARY,
           OBJECT_TYPE,
           QSYS2.QCMDEXC(
               'CHGOBJOWN OBJ(' || OBJECT_LIBRARY || '/' || OBJECT_NAME || ') OBJTYPE(' || OBJECT_TYPE || ') NEWOWN(HUGO)')
               AS "Success?" -- Specify the User ID of the new onwern on the Parameter NEWOWN
        FROM TEMPOBJ; 
image-20250325070801-1
NOTE:  The SQL query executes the CHGOBJOWN command to change the owner of objects owned by user profile V6CASTIL to new owner HUGO.  Change the current owner of the objects and the new owner of the objects on the SQL. 
NOTE 2: The User Profile IDs must be specified using all upper case characters.
NOTE 3: '1' on the Completion column indicates that the CHGOBJOWN completed normally, a '-1' indicates the it failed. 
 
 
For IFS Objects:
To get a listing of the all IFS objects owned by a users and generate a CL command using CHGOWN. 
 
1) Open the ACS Run SQL Scripts tool 
2) Run the following SQL:
WITH TEMPOBJ (PATH_NAME) AS (
        SELECT PATH_NAME
            FROM QSYS2.OBJECT_OWNERSHIP
            WHERE AUTHORIZATION_NAME = 'V6CASTIL' ---  User ID of current owner
                  AND PATH_NAME IS NOT NULL
    )
    SELECT PATH_NAME,
           QSYS2.QCMDEXC('CHGOWN OBJ(''' || PATH_NAME || ''') NEWOWN(HUGO)') AS "Success?"
        FROM TEMPOBJ;   -- Specify the User ID of the new owner on the parameter NEWOWN
image-20250325071428-2
NOTE:  The SQL executes  the CHGOWN command to change the owner of IFS objects owned the current owner user profile V6CASTIL and the new owner is HUGO.  Change the current owner of the objects and the new owner of the objects on the SQL. 
NOTE 2: The User Profile IDs must be specified using all upper case characters.
NOTE 3: '1' on the Completion column indicates that the CHGOBJOWN completed normally, a '-1' indicates the it failed. 
 
Information on how to create a list of objects owned by a user profiles can be found on the link:
Information on how to change certain types of objects in a Library to a new owner refer to the following link:
More information on the OBJECT_OWNERSHIP view can be found on the link:
  • https://www.ibm.com/docs/en/i/7.4?topic=services-object-ownership-view

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CHyAAM","label":"Security"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.3.0;7.4.0;7.5.0"}]

Document Information

Modified date:
01 May 2025

UID

ibm17005525