Pages

Wednesday, April 25, 2018

Easy to create shortcut commands

creating your own shortcut commands

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.

15 comments:

  1. Let me know if you find something like this that allows parms so i can type wb and execute WRKACTJOB SBS(QBATCH).
    Another Great BLOG post. Thanks.

    ReplyDelete
  2. I must do the cl with the next client I add.

    ReplyDelete
  3. Damery World, create a proxy command and use CHGCMDDFT (Change command defaults) to make SBS(QBATCH) a default parameter

    ReplyDelete
  4. You 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.

    ReplyDelete
  5. I'm a fan of shortcut commands.

    ReplyDelete
  6. Damery 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.

    ReplyDelete
  7. Fantastic article yet again Simon. I love your blog and clear writing stype. Couple add'l notes on this one:

    If 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.

    ReplyDelete
  8. "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."

    That'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.


    ReplyDelete
  9. Proxy commands along with the product library on command definitions eliminate the need to have 3rd party utility libraries in the library list.

    Say 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.

    ReplyDelete
  10. Excellent thinking

    ReplyDelete
  11. Love proxy commands but watch out if you change command defaults on them!!!

    ReplyDelete
  12. Work SMARTER not harder!

    ReplyDelete
  13. To 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

    Pgm
    WrkActJob Sbs(QBATCH)
    EndPgm

    Simon, thanks for the great article


    ReplyDelete
    Replies
    1. If you wanted to eliminate the CL program, make the command source be:

      CMD 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.

      Delete
  14. Hello all,
    I 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

    ReplyDelete

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.