Question & Answer
Question
How can you change the owner of multiple objects at a time in a library since the CHGOBJOWN does not allow for generics.
Cause
Answer
By using the OBJECT_OWNERSHIP view we can collect information from objects with a selection criteria and then use the CHGOBJOWN command for each one of the objects that matches the criteria.
Authorization:
- The caller must have *READ authority to the user profile that owns the object.
- The requirements for the CHGOBJOWN:
- To transfer ownership, any user (including the object's present owner) must have:
- Object existence (*OBJEXIST) authority for the object (except authorization list)
- Object operational (*OBJOPR) and *OBJEXIST authorities if the object is a file, library, or subsystem description
- All object (*ALLOBJ) special authority or ownership if the object is an authorization list
- Add (*ADD) authority for the new owner's user profile
- Delete (*DLT) authority for the present owner's user profile
- All object (*ALLOBJ) and security administrator (*SECADM) special authorities to change the object owner of a program or an SQL (Structured Query Language) package that adopts its owner's authority.
- Use (*USE) authority to the auxiliary storage pool device if one is specified.
- For display stations, if this command is not run from the device whose ownership is to be changed or whose message queue's ownership is to be changed, this command should be preceded by the Allocate Object (ALCOBJ) command and followed by the Deallocate Object (DLCOBJ) command.
- Object type *DOC or *FLR cannot be specified; the user must use DLO (document interchange) support.
- Changing the ownership of an object that has an authority holder associated with it also changes the ownership of the authority holder.
- To transfer ownership, any user (including the object's present owner) must have:
Example 1: Change the owner of all objects currently owned by a user in a library to a new owner:
1) Open the ACS Run SQL Scripts tool
2) Run the following SQL:
WITH TMPOWN (AUTHORIZATION_NAME, OBJECT_LIBRARY, OBJECT_NAME, OBJECT_TYPE) AS (
SELECT AUTHORIZATION_NAME,
OBJECT_LIBRARY,
OBJECT_NAME,
OBJECT_TYPE
FROM QSYS2.OBJECT_OWNERSHIP
WHERE AUTHORIZATION_NAME = 'HUGO' ---- Name of the Current owner
and object_library = 'V6CASTIL' ---- Name of Library
)
SELECT AUTHORIZATION_NAME,
OBJECT_LIBRARY,
OBJECT_NAME,
OBJECT_TYPE,
QSYS2.QCMDEXC(
'CHGOBJOWN OBJ(' || OBJECT_LIBRARY || '/' || OBJECT_NAME || ') OBJTYPE(' || OBJECT_TYPE || ') NEWOWN(NEWOWNER)')
AS "Success?" --- replace NEWOWNER with the name of the new owner.
FROM TMPOWN;

NOTE 1: The SQL has no confirmation screen and will change the owner of the objects to the new owner as specified on the command.
NOTE 2: The SQL changes the Owner of All object in the specified library that are owned by a specific user profile.
NOTE 3: A '1' on the Completion column indicates that the CHGOBJOWN completed normally, a '-1' indicates the it failed.
Example 2: Change the owner of a specific object type currently owned by a user in a library to a new owner:
1) Open the ACS Run SQL Scripts tool
2) Run the following SQL:
WITH TMPOWN (AUTHORIZATION_NAME, OBJECT_LIBRARY, OBJECT_NAME, OBJECT_TYPE) AS (
SELECT AUTHORIZATION_NAME,
OBJECT_LIBRARY,
OBJECT_NAME,
OBJECT_TYPE
FROM QSYS2.OBJECT_OWNERSHIP
WHERE AUTHORIZATION_NAME = 'V6CASTIL' ---- Name of the Current owner
and object_library = 'V6CASTIL' ---- Name of Library
AND Object_type = '*QRYDFN' ---- Object type
)
SELECT AUTHORIZATION_NAME,
OBJECT_LIBRARY,
OBJECT_NAME,
OBJECT_TYPE,
QSYS2.QCMDEXC(
'CHGOBJOWN OBJ(' || OBJECT_LIBRARY || '/' || OBJECT_NAME || ') OBJTYPE(' || OBJECT_TYPE || ') NEWOWN(NEWOWNER)')
AS "Success?" --- replace NEWOWNER with the name of the new owner.
FROM TMPOWN;

NOTE 1: The SQL has no confirmation screen and will change the owner of the objects to the new owner as specified on the command.
NOTE 2: The SQL specifies the object type a *QRYDFN and will only change the owner of the object that matches the criteria.
NOTE 3: A '1' on the Completion column indicates that the CHGOBJOWN completed normally, a '-1' indicates the it failed.
Example 3: Change the owner of all objects in a Library.
1) Open the ACS Run SQL Scripts tool
2) Run the following SQL:
WITH TMPOWN (OBJNAME, OBJTYPE, OBJOWNER, OBJLIB) AS (
SELECT OBJNAME,
OBJTYPE,
OBJOWNER,
OBJLIB
FROM TABLE (
QSYS2.OBJECT_STATISTICS('V6CASTIL', '*ALL')
) AS X ---- Name of Library. Replace V6CASTIL with the name of the Library
)
SELECT OBJNAME,
OBJTYPE,
OBJOWNER,
OBJLIB,
QSYS2.QCMDEXC('CHGOBJOWN OBJ(' || OBJLIB || '/' || OBJNAME || ') OBJTYPE(' || OBJTYPE || ') NEWOWN(NEWOWNER)')
AS "Success?" --- replace NEWOWNER with the name of the new owner.
FROM TMPOWN;

NOTE 1: The SQL has no confirmation screen and will change the owner of the objects to the new owner as specified on the command.
NOTE 2: The SQL changes the Owner of All object in the specified library no matter who is the current owner or what is the type of the object.
NOTE 3: A '1' on the Completion column indicates that the CHGOBJOWN completed normally, a '-1' indicates the it failed.
This method works for releases 7.3,7.4 and 7.5 of the Operating System, for older releases refer to link:
[{"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":"TS016431523","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.3.0;7.4.0;7.5.0"}]
Was this topic helpful?
Document Information
Modified date:
19 June 2024
UID
ibm17157848