I have made a CL program to simplify changing owner, USRPRF and permissions for an object. It utilizes GRTOBJAUT among others to do the changes. Here's the parameter definitions:
pgm parm(&libobj &type &owner &usrprfown &user1 &auth1 +
&user2 &auth2 &user3 &auth3)
...
dcl var(&libobj) type(*char) len(21)
dcl var(&type) type(*char) len(10)
dcl var(&user1) type(*char) len(10)
dcl var(&auth1) type(*char) len(10)
...
This is how I call GRTOBJAUT:
grtobjaut obj(&libobj) objtype(*all) user(&user1) +
aut(&auth1)
However, only the first 10 characters of &libobj
are actually passed to GRTOBJAUT. I have verified in the debugger that passing for instance MYLIB/TEST1234 results in grtobjaut obj('MYLIB/TEST')
, despite &libobj
containing the full string. According to the documentation this should be proper syntax for the GRTOBJAUT command, thus allowing for more than 10 characters long paths. Is this actually not the case? Is there a difference between the interactive GRTOBJAUT and the CL GRTOBJAUT? How do I make this work?
The program is compiled for v6.1 and run in a v7.1 capable environment.
EDIT: The same problem applies to CHGOBJOWN.
You can't pass both library and object name together in a single parameter. The GRTOBJAUT OBJ() parameter has two parts, not just one. You define only one part, and declare that it's 21 characters long. But it isn't. It's two parts, and each part is ten characters long.
In general, you should change your CL in this way:
pgm parm(&lib &obj &type &owner &usrprfown &user1 &auth1 +
&user2 &auth2 &user3 &auth3)
...
dcl var(&lib) type(*char) len(10)
dcl var(&obj) type(*char) len(10)
The library and object names are passed in as separate 10-character names. Then the GRTOBJAUT command would be like this:
grtobjaut obj(&lib/&obj) objtype(*all) user(&user1) +
aut(&auth1)
Note that the OBJ() parameter specifies the two parts separately.
You can leave your 21-character CL parm in place if you wish. However, if you do, you will have to add code to your CL to parse that parm value and extract the library and object names before passing them into GRTOBJAUT. It is simpler just to pass them into your CL separately.
Once you have them separated, you'll need to be sure that &lib isn't blank when GRTOBJAUT receives it. If it comes into your CL as a blank value, you'll need to assign a special value such as '*LIBL', '*CURLIB' or whatever is appropriate so that GRTOBJAUT can process it.
There are alternatives, but you should learn this requirement before trying trying things that are essentially 'tricks'.