Question & Answer
Question
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.
- R750: Base
- R740: SF99704 Level 4
- R730: SF99703 Level 16
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;

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

- https://www.ibm.com/docs/en/i/7.4?topic=services-object-ownership-view
Was this topic helpful?
Document Information
Modified date:
01 May 2025
UID
ibm17005525