IBM Support

How do you create a report of all objects owned by a user profile

Question & Answer


Question

How do you create a report of all objects owned by a user profile on the system.

Answer

With the introduction of the IBM i SQL Service OBJECT_OWNERSHIP, you can create an SQL report containing a list of all the objects a user owns 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: Read authority is required to the user profile that owns the object.

To get a listing of all objects owned by a user profile follow the steps:
 
1) Open the ACS Run SQL Scripts tool 
2) Run the following SQL:
  SELECT *
    FROM QSYS2.OBJECT_OWNERSHIP
    WHERE AUTHORIZATION_NAME = 'V6CASTIL'  -- User ID Name
    ORDER BY OBJECT_LIBRARY,
             OBJECT_NAME,
             PATH_NAME

image 3725

NOTE:  The report lists all objects that are owned by profile V6CASTIL on both libraries and the IFS.  Update the Owner User profile on the SQL.

In addition, if you would like to create a listing of all objects owned by a user profile in an IFS directory path, the IFS_OBJECT_STATISTICS table function can be used to create a report.
Authorization: The user needs either *ALLOBJ authority or the following authorities:
  • For each directory included in the path name used to start the search, *X
  • For each directory processed recursively by the service, *RX and *OBJMGT
  • For each object returned by the service, *OBJMGT
To return values for OBJECT_AUDIT and OBJECT_AUDIT_CREATE, the user must have *AUDIT special authority.
To get a listing of all objects owned by a user profile on an IFS path follow the steps:
 
1) Open the ACS Run SQL Scripts tool 
2) Run the following SQL:
  SELECT OBJECT_OWNER,
       PATH_NAME,
       OBJECT_TYPE
    FROM TABLE (
            QSYS2.IFS_OBJECT_STATISTICS(START_PATH_NAME => '/home/', SUBTREE_DIRECTORIES => 'YES')
        )
    WHERE OBJECT_OWNER = 'V6CASTIL'  -- User ID Name
    ORDER BY PATH_NAME
image 3726
NOTE: The report lists all IFS objects owned by user profile V6CASTIL in the /home directory and sub directories. Update the Object Owner profile and the path.
To create a report of all objects owned by a user profile that include the size of the object, use the following SQL:
1) Open the ACS Run SQL Scripts tool 
2) Run the following SQL:
WITH QSYS_STUFF_I_OWN AS (
         SELECT AUTHORIZATION_NAME,
                OBJECT_TYPE,
                PATH_NAME,
                OBJECT_NAME,
                OBJECT_LIBRARY,
                TEXT_DESCRIPTION
             FROM QSYS2.OBJECT_OWNERSHIP
             WHERE AUTHORIZATION_NAME = 'V6CASTIL' -- User ID Name
                   AND PATH_NAME IS NULL
     ),
     Ifs_Dirs_I_Own AS (
         SELECT Authorization_Name,
                Object_Type,
                Path_Name,
                OBJECT_NAME,
                OBJECT_LIBRARY,
                Text_Description
             FROM Qsys2.Object_Ownership
             WHERE Authorization_Name = 'V6CASTIL' -- User ID Name
                   AND Path_Name IS NOT Null
                   AND object_type = '*DIR'
     ),
     Ifs_Objs_I_Own AS (
         SELECT Authorization_Name,
                Object_Type,
                OBJECT_NAME,
                OBJECT_LIBRARY,
                Path_Name,
                Text_Description
             FROM Qsys2.Object_Ownership
             WHERE Authorization_Name = 'V6CASTIL' -- User ID Name
                   AND Path_Name IS NOT Null
                   AND object_type <> '*DIR'
     )
    SELECT A.AUTHORIZATION_NAME,
           A.PATH_NAME,
           A.OBJECT_TYPE,
           A.OBJECT_NAME,
           A.OBJECT_LIBRARY,
           A.TEXT_DESCRIPTION,
           C.OBJCREATED AS CREATE_TIME,
           C.LAST_USED_TIMESTAMP AS LAST_USED_TIME,
           C.OBJSIZE AS OBJECT_SIZE
        FROM QSYS_STUFF_I_OWN AS A
             JOIN LATERAL (
                     SELECT *
                         FROM TABLE (
                                 QSYS2.OBJECT_STATISTICS(
                                     OBJECT_SCHEMA => A.OBJECT_LIBRARY, OBJTYPELIST => A.OBJECT_TYPE, OBJECT_NAME => A.OBJECT_NAME)
                             )
                 ) AS C
                 ON TRUE
    UNION
    SELECT A.Authorization_Name,
           A.Path_Name,
           A.Object_Type,
           A.OBJECT_NAME,
           A.OBJECT_LIBRARY,
           A.Text_Description,
           B.Create_Timestamp AS Create_Time,
           B.Last_Used_Timestamp AS Last_Used_Time,
           B.Data_Size AS Object_Size
        FROM Ifs_Objs_I_Own AS A
             JOIN LATERAL (
                     SELECT *
                         FROM TABLE (
                                 Qsys2.Ifs_Object_Statistics(
                                     Start_Path_Name => A.Path_Name, IGNORE_ERRORS => 'YES', Subtree_Directories => 'NO')
                             )
                 ) AS B
                 ON TRUE
    UNION ALL
    SELECT A.Authorization_Name,
           A.Path_Name,
           A.Object_Type,
           A.OBJECT_NAME,
           A.OBJECT_LIBRARY,
           A.Text_Description,
           CAST(null AS TIMESTAMP) AS Create_Time,
           CAST(null AS TIMESTAMP) AS Last_Used_Time,
           CAST(null AS INTEGER) AS Object_Size
        FROM Ifs_Dirs_I_Own AS A
        ORDER BY path_name,
                 object_size DESC;
image-20250424072226-1
NOTE: Update the Owner User Profile ID in 3 parts of the SQL labeled with -- User ID Name.  
NOTE 2 :  This SQL is used by the Navigator for i interface. 
NOTE 3: The size of the objects is listed in bytes. 
More information on the IBM i SQL Services can be found on the following links:

[{"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;7.6.0"}]

Document Information

Modified date:
24 April 2025

UID

ibm16213232