CHANGING A LIBRARY’S OWNER and ALL of its OBJECTS

Many times libraries have been created and later realized it has the wrong owner, or you decide to use a new authority scheme in your company and want to change the owner and authority. It takes a long time to change all the
Just compile the CL Program, Command, and create the File below all in your favorite Utility library, or personal library and give it a try
CL PROGRAM
PGM PARM(&LIB &NEWOWNER &CURAUT)
DCLF FILE(YOURLIB/OBJOWN)
DCL VAR(&LIB) TYPE(*CHAR) LEN(10)
DCL VAR(&CURAUT) TYPE(*CHAR) LEN(10)
DCL VAR(&NEWOWNER) TYPE(*CHAR) LEN(10)
DSPOBJD OBJ(&LIB/*ALL) OBJTYPE(*ALL) +
OUTPUT(*OUTFILE) OUTFILE(YOURLIB/OBJOWN)
RCVF: RCVF DEV(*FILE)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END))
CHGOBJOWN OBJ(&ODLBNM/&ODOBNM) OBJTYPE(&ODOBTP) +
NEWOWN(&NEWOWNER) CUROWNAUT(&CURAUT)
MONMSG MSGID(CPF0000)
GOTO CMDLBL(RCVF)
END: ENDPGM
COMMAND
CMD
PROMPT(‘Change Library Owner’)
PARM KWD(LIB) TYPE(*CHAR) LEN(10)
MIN(1) +
PROMPT(‘Library’)
PARM KWD(NEWOWN) TYPE(*CHAR)
LEN(10) MIN(1) +
PROMPT(‘New Owner’)
PARM KWD(CURAUT) TYPE(*CHAR)
LEN(10) RSTD(*YES) +
VALUES(‘*SAME’ ‘*REVOKE’)
MIN(1) PROMPT(‘Current Owner Authority’)
FILE
DSPOBJD
OBJ(YOURLIB/*ALL)
OBJTYPE(*ALL) +
OUTPUT(*OUTFILE) OUTFILE(YOURLIB/OBJOWN)
Just run this command manually one time and you will have your file created.
You could also use IFS naming to make these change with a single command.
For example, to change the owner of all *PGM objects under library MYLIB, use command:
CHGOWN OBJ(‘/QSYS.LIB/MYLIB.LIB/*.PGM’) NEWOWN(someuser).
Similarly, to change all files use “/QSYS.LIB/MYLIB.LIB/*.FILE”, and for all objects use “/QSYS.LIB/MYLIB.LIB/*”
This is stupid. Just use the built-in OS/400 command CHGOWN as follows:
CHGOWN ‘/QSYS,LIB/libname.LIB’ NEWOWN(newowner)
to change the owner of the *LIB and then issue:
CHGOWN ‘/QSYS,LIB/libname.LIB/*’ NEWOWN(newowner)
to change the owner of all of the objects in that library.
Done!
You could also use IFS naming to make changes with a single command.
For example, to change all program objects under library MYLIB:
CHGOWN OBJ(‘/QSYS.LIB/MYLIB.LIB/*.PGM’) NEWOWN(someuser)
Similarly, you can use “*.FILE” for all file objects, “*” for all objects, etc.
You could also use IFS naming to make changes with a single command.
For example, to change all program objects under library MYLIB:
CHGOWN OBJ(‘/QSYS.LIB/MYLIB.LIB/*.PGM’) NEWOWN(someuser)
Similarly, you can use “*.FILE” for all file objects, “*” for all objects, etc.
I probably would have just created a user defined option in PDM to do this.
One small but useful tip is to use IBM’s own model files for things like this. DSPOBJD uses QADSPOBJ. This way you can compile your programs without having to manually create outfiles first.
Just add the following line right after your existing line 1 (the one that start with “PGM”):
DCLF FILE(QSYS/QADSPOBJ)
Then add the following line right before the line that begins with “RCVF”:
OVRDBF FILE(QADSPOBJ) TOFILE(YOURLIB/OBJOWN)