CHGOWN – Easily Change Object Ownership

Steven McIver

Object ownership is very important on IBM i, as often group profiles are used to secure objects, and sometimes programs are compiled to run under the authority of the profile that owns the program. There are times when a decision is made to change the owner of a particular library in order to change the scheme of securing objects, or you may go to restore a library to another system, and realize that the profile that owned the objects on the original system, does not exist on the target system to take the ownership. Sometimes in these cases, the library has hundreds or even thousands of objects in them, and changing the owner of these objects one at a time is just not feasible. There are several ways to resolve this, but certainly, the easiest way is to use the CHGOWN command.

Note:  To change object ownership, there must be no jobs locking the objects in the library. You may need to wait till the jobs locking the objects can be ended, or run the command during a planned maintenance.

In this funny example, I will be changing the object ownership of a few objects using CHGOWN. Currently, all the objects in the TOPPINGS library are owned by SUNDAE, when clearly all these objects need to be owned by PIZZA! Let’s step through how to right this wrong.

DSPOBJD showing that the object has the wrong owner!

Start by typing the command CHGOWN and then prompting it with the F4 key. The two required parameters are Object and New owner, and those are the two we’re going to focus on. On the object line, we are going to type the name of the TOPPINGS library as it appears in the /QSYS.lib filesystem. All libraries are nested inside the QSYS library, and all libraries have a .lib file extension, and at the end we include a wildcard (*) to indicate we want this change to apply to every object in the library. What you put on the object line ends up looking like this:  /qsys.lib/toppings.lib/*

Using CHGOWN to change all objects in library TOPPINGS to be owned by user profile PIZZA.

The next thing to do is specify the new owner, PIZZA, on the New owner parameter. Hit Enter. The bottom of the screen should tell you “X objects successfully changed.” Lastly, press F9 to bring the command back so we can change the ownership of the library object. Change the object line to /qsys.lib/toppings.lib and then hit Enter. The bottom of the screen should say “Object changed”.

Changing the ownership of the library object.

You can review your job log to ensure all the changes were made correctly, and you can use DSPOBJD on a few objects just to be sure.

The PEPPERONI object now rightly owned by PIZZA.

Leave a Comment

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