CHANGING A LIBRARY’S OWNER and ALL of its OBJECTS

Bill Hoagland

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 effected objects and the library owner. I created a simple utility command to do the work for you. It only requires 1 CL PGM, 1 CMD and 1 file. In short the CL command will build a file of all the objects in a library and then change the owner of all the objects to the new owner you want them to be. You even have an option to save or revoke the authority of the old owner too.

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.

6 comments on “CHANGING A LIBRARY’S OWNER and ALL of its OBJECTS
  1. Rohit Sharma says:

    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/*”

  2. Mark S. Waterbury says:

    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!

  3. Rohit Sharma says:

    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.

  4. Rohit Sharma says:

    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.

  5. John R. Bromm says:

    I probably would have just created a user defined option in PDM to do this.

  6. DB says:

    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)

Leave a Reply

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

*