Midrange News for the IBM i Community

Change Object Owner/Rename Object Owner Published by: Bob Cozzi on 23 Nov 2011 view comments(1)
© 2011 Robert Cozzi, Jr. All rights reserved.

© Robert Cozzi, Jr. All rights reserved. Reproduction/Redistribution prohibited.
A midrangeNews.com Publication

Many Faces of Change Object Owner

Three of Four Required Change Owner Commands Exist

Dealing with changing the owner of an object is certainly easier than it was a few years ago. Today we have the CHGOWN command, which was introduced with the IFS to allow the IFS object's owner to be changed using the IFS file naming convention. The legacy CHGOBJOWN command could not handle path names, so CHGOWN was introduced.

As it turns out, the CHGOWN command is more capable that CHGOBJOWN in that it supports generic names. To change the owner of all the files in a folder named /home/cozzi on the IFS to a new owner named BOB, the following command:


The OBJ (object) parameter needs to be in the IFS naming convention rather than lib/obj (the system naming convention). The new owner is BOB, and the RVKOLDAUT(*NO) parameter means that who ever currently owns the objects, their authority will NOT be revoked. Unless I am changing the owner of as single object, I always use CHGOWN instead of CHGOBJOWN.

Sponsored by: BCD Software

The CHGOWN command also has a SUBTREE parameter. This parameter tells the command to recurse down into any subdirectories within the one you've specified, and change the owner of those objects (and directory nodes) as well.

Using DLTUSRPRF (Delete User Profile)

 The DLTUSRPRF command is quit a bit more powerful than CHGOBJOWN. Often when an employee leaves a company, it is standard operating procedure to change that employee's owned objects to another owner. Many shops have long since moved on to using Group Profiles as the object owner, so this isn't often necessary. However, users always tend to own a couple of objects and those objects will need a new owner.

An enhancement to DLTUSRPRF is the Owned Object Option (OWNOBJOPT) and Primary Group Option (PGPOPT) parameters. These parameters allow you assign a new object owner and/or change the Group Profile assignment for any objects currently owned by the profile. Then the profile is deleted. Love these features!

Introducing the RNMOBJOWN Command

What is missing though, is the ability to change the owner of objects owned by a user profile. That is, do what DLTUSRPRF OWNOBJOPT parameter does, but without deleting the user profile.

I wrote a RNMOBJOWN Command that does just that. Give it a user profile and a new owner user profile and it will change the owner of the objects owned by the user, and optionally revoke the old owner's authority. Here's the syntax:

  RNMOBJOWN USRPRF( existing-owner-usrprf ) NEWOWN( new-owner-usrprf ) OLDOWNACT( *NONE | *REVOKE | *DLT ) 

The main difference between this command and DLTUSRPRF is that the old user profile is NOT deleted by default. This may be important if you have embedded that user profile name in FTP scripts or other areas and can't really delete it, just yet, or if you have other things that would require the profile to exist, but be disabled (for example).

  •  If OLDOWNACT(*NONE) is specified, no further action beyond the CHGOBJOWN is performed.
  • If OLDOWNACT(*REVOKE) is specified, the old owner's authority to the previously owned object is revoked.
  • If OLDOWNACT(*DLT) is specified, the results are the same as DLTOBJOWN, the old user profile is deleted after all object is currently owns are changed to the new owner.

Here's the source code for the RNMOBJOWN Command Definition Object.

 RNMOBJOWN:  CMD        PROMPT('Rename Owner of Objects')
             PARM       KWD(USRPRF) TYPE(*NAME) MIN(1) EXPR(*YES) +
                          PROMPT('Current Owner User Profile')
             PARM       KWD(NEWOWN) TYPE(*NAME) MIN(1) EXPR(*YES) +
                          PROMPT('New Owner')
             PARM       KWD(OLDOWNACT) TYPE(*CHAR) LEN(7) DFT(*NONE) +
                          SPCVAL((*REVOKE) (*DLT) (*NONE)) +
                          EXPR(*YES) CHOICE('*NONE, *REVOKE, *DLT') +
                          PROMPT('Old Owner User Profile Action') 

The source code for the CL program that performs the RNMOBJOWN command, is specified below.

		       /* (c) 2011 by Bob Cozzi  */
             DCL        VAR(&OLDOWN) TYPE(*CHAR) LEN(10)
             DCL        VAR(&NEWOWN) TYPE(*CHAR) LEN(10)
             DCL        VAR(&OLDOWNACT) TYPE(*CHAR) LEN(7)
             DCL        VAR(&REVOKE) TYPE(*CHAR) LEN(7) VALUE('*SAME')

             DCLF       FILE(QADSPUPO)
             MONMSG     MSGID(CPF0000)
             IF (&OLDOWNACT *EQ '*REVOKE') THEN(DO)
                CHGVAR VAR(&REVOKE) VALUE('*REVOKE')

                          OUTPUT(*OUTFILE) OUTFILE(QTEMP/COZRNMOWN) +
                          OUTMBR(*FIRST *REPLACE)
             MONMSG     MSGID(CPF2200) EXEC(DO)
               SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) +
                          MSGDTA('RNMOBJOWN: >>DSPUSRPRF for' *BCAT +
                          &OLDOWN *BCAT 'failed. See joblog for +
                          details.') MSGTYPE(*DIAG)
             MONMSG     MSGID(CPF0864) EXEC(GOTO EOF)
             IF         COND((&OOUSR *EQ &OLDOWN) *AND (&OOUSR *NE +
                          ' ')) THEN(DO)

                          MSGDTA('Changing owner for' *BCAT &OOOBJ +
                          *BCAT 'in' *BCAT &OOLIB *BCAT 'type' +
                          *BCAT &OOTYPE *BCAT 'to' *BCAT &NEWOWN) +
                          TOPGMQ(*EXT) MSGTYPE(*STATUS)
                          MSGDTA('Changing owner for' *BCAT &OOOBJ +
                          *BCAT 'in' *BCAT &OOLIB *BCAT 'type' +
                          *BCAT &OOTYPE *BCAT 'to' *BCAT &NEWOWN) +
                          TOPGMQ(*SAME) MSGTYPE(*INFO)
                          NEWOWN(&NEWOWN) CUROWNAUT(&REVOKE)
             GOTO       CMDLBL(READNEXT)
             IF (&OLDOWNACT *EQ '*DLT') THEN(DO)



Call Me

Bob Cozzi is the webmaster for MidrangeNews.com and has been providing the solutions to midrange problems, in the form or articles and books since 1983. He is available for consulting/contract development or on-site RPG IV, SQL, and CGI/Web training. To contact Cozzi, send an email to: bob at rpgworld.com

You can subscribe to RPG Report (we call it "follow") by visiting the RPG Report page on midrangeNews.com and then click the FOLLOW link in the table of contents for that page. To unsubscribe, simply click that same link. You must be signed up and signed in to midrangeNews.com to start following RPG Report.

Follow Bob Cozzi on Twitter

Return to midrangenews.com home page.
Sort Ascend | Descend


(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Comment on: RPG Report - 15 Nov 2011
Posted: 8 years 1 months 20 days 19 hours 1 minutes ago

Please note that DSPUSRPRF should have TYPE(*OBJOWN) not *BASIC in order for this procedure to work correctly. *BASIC will simply end without doing anything.