After my post about how to create your own commands I received messages from readers giving me examples of how they have created their own shortcut commands, to do the same as the standard IBM i command but shorter. In one example the command SP did the same as WRKSPLF.
I don't think many people know of proxy commands. These allow me to create shortcut commands of the regular IBM i commands without any programming. You can even make proxies of proxy commands, although I cannot think of a reason why I would ever think to do so.
In this example I am going to create a proxy command, SP, for the Work with Spooled Files command, WRKSPLF.
I type the following:
CRTPRXCMD |
Then I press F4 to prompt the command.
Create Proxy Command (CRTPRXCMD) Type choices, press Enter. Command . . . . . . . . CMD SP Library . . . . . . . MYLIB Target command . . . . . TGTCMD WRKSPLF Library . . . . . . . *LIBL Text 'description' . . . TEXT *TGTCMD |
In the command parameters I have entered the name I wish to call my proxy command, SP, and the library it will reside in, MYLIB.
As this is my shortcut for WRKSPLF then the target command is WRKSPLF. I leave the library as *LIBL as the WRKSPLF command is in the library QSYS, which should be in everyone's library list.
I leave the text parameter as *TGTCMD. This gives my proxy command the same description as the target command. There is no reason why I could not use something like: "Simon's WRKSPLF proxy" if I so choose.
There are additional parameters, you can see by pressing F10, but I have never found a use for them.
When I press the Enter key the proxy command is created.
Work with Objects Using PDM Library . . . . . MYLIB Opt Object Type Attribute Text ANOTHER *CMD Another command SP *CMD PRX Work with Spooled Files |
My new proxy command can be identified as one by the object attribute of PRX, which non-proxy commands do not have.
Now whenever I need to do WRKSPLF I can just type SP and the same command is executed.
If I need to change my proxy command I use the Change Proxy Command command, CHGPRXCMD.
Create Proxy Command (CRTPRXCMD) Type choices, press Enter. Command . . . . . . . . CMD Library . . . . . . . Target command . . . . . TGTCMD *SAME Library . . . . . . . Text 'description' . . . TEXT *SAME |
If I choose to delete my proxy command I would just use the Delete Command command, DLTCMD.
DLTCMD MYLIB/SP |
I only use the proxy commands as shortcuts on the IBM i command line. I always create them in my own library, that way they are only mine. I need to be careful when creating them to make sure that there is not another command of the same name "higher" in the library list. I would not use them in programs, as no-one else would know what my proxy commands are.
To make it easier for myself to remember what my proxy commands are I use the same names I use for my PDM options.
I also have is a source member, that can be compiled into a CL program, which lists all of my proxy commands. This way I can create the proxy commands on another system, without having to copy the commands themselves to the other location.
PGM DCL VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE('MYLIB') CRTPRXCMD CMD(&LIB/WM) TGTCMD(WRKMBRPDM) CRTPRXCMD CMD(&LIB/WO) TGTCMD(WRKOBJPDM) CRTPRXCMD CMD(&LIB/SP) TGTCMD(WRKSPLF) |
You can learn more about this from the IBM website:
This article was written for IBM i 7.3, and should work for earlier releases too.
Let me know if you find something like this that allows parms so i can type wb and execute WRKACTJOB SBS(QBATCH).
ReplyDeleteAnother Great BLOG post. Thanks.
I must do the cl with the next client I add.
ReplyDeleteDamery World, create a proxy command and use CHGCMDDFT (Change command defaults) to make SBS(QBATCH) a default parameter
ReplyDeleteYou can't specify any of the parameters you can just simply call the command. Specifying parameters would defeat the original purpose of proxy commands which is to avoid conflict when command options are changed in future versions. Bruce Vining discusses a method of doing it but turns out to be a very complicated way to do something simple.
ReplyDeleteI'm a fan of shortcut commands.
ReplyDeleteDamery World, proxy commands can't be used because, when you change the default parameter of a proxy command, it also changes the defaults on the original command. You should use CRTDUPOBJ to make a copy of the command and use CHGCMDDFT on your copy.
ReplyDeleteFantastic article yet again Simon. I love your blog and clear writing stype. Couple add'l notes on this one:
ReplyDeleteIf you create a command by compiling a QCMDSRC member member and the *CMD object already exists, you will get this: Delete existing object . . . . . . . . N
If you create a command with CRTCMD, however, and you already have a command with that name out there, it will be replaced without any warning whatsoever, which in my opinion is an gross oversight in the OS.
CRTPRXCMD does the same thing; it just replaces your existing object, no questions asked. Make sure you don't already have a command with that name before creating a proxy command.
Also interesting is that it lets you create a proxy command with a target command that doesn't exist, without error. Try it:
DLTCMD Z
DLTCMD ZZZ
CRTPRXCMD CMD(Z) TGTCMD(ZZZ)
Z
Command ZZZ in *LIBL not found.
It even lets you referencing the not-yet-existing command itself as target:
DLTCMD Z
CRTPRXCMD CMD(Z) TGTCMD(Z)
Z
Number of chained proxy commands exceeds 5.
"If you create a command with CRTCMD, however, and you already have a command with that name out there, it will be replaced without any warning whatsoever, which in my opinion is an gross oversight in the OS."
ReplyDeleteThat's because the REPLACE parameter on the CRTCMD and CRTPRXCMD commands defaults to *YES. If you don't want that behavior then change the command default to *NO.
Proxy commands along with the product library on command definitions eliminate the need to have 3rd party utility libraries in the library list.
ReplyDeleteSay you have a 3rd party utility in library UTILITY. Make sure any commands in UTILITY have their product library set to UTILITY, then create proxy commands pointing to the commands in library UTILITY and put the proxy commands in a library in the library list (QGPL for example).
When you run one of the utility commands, it will find the proxy, point to the command in the UTILITY library which has the product library of UTILITY in the definition, add the product library (UTILITY) to the library list, execute the command processing program, and remove the product library from the library list.
Excellent thinking
ReplyDeleteLove proxy commands but watch out if you change command defaults on them!!!
ReplyDeleteWork SMARTER not harder!
ReplyDeleteTo Damery world, I have exactly this; one for each of our common subsystems. I just created a CL and commmand, both named QBATCH. The CL is just
ReplyDeletePgm
WrkActJob Sbs(QBATCH)
EndPgm
Simon, thanks for the great article
If you wanted to eliminate the CL program, make the command source be:
DeleteCMD PROMPT('WrkActJob Sbs(QBATCH)')
PARM KWD(CMD) TYPE(*CHAR) LEN(21) +
CONSTANT('WrkActJob Sbs(QBATCH)')
PARM KWD(LEN) TYPE(*DEC) LEN(15 5) +
CONSTANT(21)
and make the command processing program be QCMDEXC.
Hello all,
ReplyDeleteI have another version of this.
in stead of multiple commands i created only one 'X'
In a file i write the commands i want and allow for multiple commands.
eg. typing 'X DB' will execute:
ENDSRVJOB
ENDDBG
STRSRVJOB MYPCNAME
or 'X CP aMember' will exceute:
CPYSRCPF from/QRPGLESRC to/QRPGLESRC &1 *frommbr *repalce