The Attention key is perhaps the most powerful key on your keyboard. Here's how you can use it!
Brief: If you've been wondering what use the Attention key is on an AS/400, you've come to the right place. The main article covers OS/400 commands that control the Attention key, suggestions for how to use the Attention key effectively and a discussion of the limitations inherent in Attention key processing. Our sidebar provides you with the complete, downloadable code for a command that overcomes many of these limitations and gives you a standard approach to Attention key programming for all types of users, including programmers, operators and end users.
The first time you pressed the Attention (Attn) key on your AS/400 terminal, you were probably surprised by the response you got from the system-it did nothing. You probably concluded that IBM gave you a dummy key so you could tap your index finger, marking the beat of whatever song you're listening to on the radio.
It turns out, however, that the Attention key is user-definable; if yours doesn't do anything, it is because you haven't told your system what you want it to do. In this article you'll learn how to define the Attention key, how to control it, how it differs from the S/36 Attention key and what you can do (and cannot do) with it. For example, you might want to give your system operator quick and easy access to the main Operational Assistant menu.
Uses of the Attention Key
Many people use the Attention key to call a program that displays a menu where they can select options to run frequently performed tasks. This could be a CL program using a simple display file. This application of the Attention key is great for end users, but programmers and more experienced users may prefer something more flexible. Here are a few alternatives you can plug into your user profile's ATNPGM setting:
QSYS/QCMD: Presents the Command Entry panel. Now you can enter any command and have a running history of all the commands you have entered.
QSYS/QUSCMDLN: Presents a window with a command line. Again, you can enter any commands, but you don't get the running history.
QSYS/QWSSYSRQ: Presents the System Request menu. It lets you use the Attention key instead of the more complicated Shift-SysRq followed by Enter. Great for people who come from the S/36.
QSYS/QEZMAIN: Presents the Operational Assistant main menu. Incidentally, calling QSYS/QEZMAIN (even manually with the CALL command) shows a status message "Processing Attention key...." Obviously IBM thought that this program would always be processed by the Attention key. As you will see later, there is also a special value that can be used to present the Operational Assistant menu instead of using the QEZMAIN program.
Basic Operation
The purpose of the Attention key is to execute a program whenever the Attention key is pressed. This program is usually known as the Attention key handling program, but in the rest of the article I'll drop the word handling for brevity. The program's name is specified globally in a system value (QATN-PGM) or explicitly in your user profile; the security administrator can change it with the Change User Profile (CHGUSRPRF) or Change Profile (CHGPRF) command, as follows:
CHGUSRPRF USRPRF(JOE) + ATNPGM(MYLIB/PGMX)
This changes JOE's Attention key program to PGMX in library MYLIB. From now on, every time user JOE signs on, his Attention key will automatically run this program. It is important to know that the change becomes effective next time user JOE signs on; if JOE is signed on already, the Attention key still works as it did before running the CHGUSRPRF command. Also, if the attention key program is modified and recompiled, the new version of the program does not become effective until the next time the user signs on.
Both the CHGUSRPRF and CHGPRF commands accept special values in the ATNPGM parameter. *NONE deactivates the Attention key (so you can tap on it while listening to the radio), *ASSIST takes you to the Operational Assistant main menu, and *SYSVAL uses system value QATNPGM to determine what program to call when the Attention key is pressed.
The SETATNPGM Command
Changing your user profile and signing on is one way to assign an Attention key program to your interactive job. Another method that allows on-the-fly changes to the Attention key program is the Set Attention Program (SETATNPGM) command, which can be executed manually or included in a CL program. The changes made by the SETATNPGM are effective only at the current (or subsequent) levels in the program stack. This means that if you include SETATNPGM in a CL program named CHGATN and then CALL CHGATN, the effect of the SETATNPGM command will last only as long as CHGATN (or any program called from CHGATN) runs. As soon as CHGATN ends, the Attention key automatically reverts back to its original state.
SETATNPGM has two parameters: PGM and SET.
PGM (Program) identifies the program that is invoked when you press the Attention key. You can enter a qualified name or the special values *CURRENT and *PRVINVLVL. *CURRENT represents whatever program is the Attention key program at the time you run the SETATNPGM command. *PRVINVLVL is the previous invocation level's Attention key program.
SET (Set) indicates whether to activate (*ON) or deactivate (*OFF) the program named in the PGM parameter as the Attention key program.
Here are some examples:
SETATNPGM PGM(QSYS/QUSCMDLN) + SET(*ON)
This command changes your interactive job's Attention key program to
SETATNPGM PGM(*CURRENT) + SET(*OFF)
This deactivates the current Attention key program. The Attention key will do nothing.
SETATNPGM PGM(*CURRENT) + SET(*ON)
Now the current Attention key program is reactivated. Pressing Attention will invoke it.
SETATNPGM PGM(*PRVINVLVL)
The help text says that this sets the previous invocation level's Attention key program as the current Attention key program, and activates it. The SET parameter cannot be specified with *PRVINVLVL; it seems like the system assumes SET(*YES). If you run SETATNPGM PGM(*PRVINVLVL) from CL program X, the Attention key will call the Attention key program that was in effect before program X was called.
Limitations of the Attention Key
Unfortunately, the Attention key cannot be used to execute a command-only a program. What's worse, there is no way to pass parameters to the program you have selected. Therefore, you should not attempt to use the Attention key to run a program that expects parameters. Since no parameters can be passed, the program won't be able to run properly. You'll get the Program Messages panel (nasty) with CPI1301 displayed: An error occurred while processing the Attention key. After you wade through the Help levels and display the job log, you'll discover message MCH0802: Argument list total not equal to number in associated parameter list.
It's no wonder that the system sometimes takes a while to react to the Attention key; the system is busy calling a series of programs before calling your Attention key program.
While doing research for this article, I wondered how the system executed the Attention key program. I therefore created a short CL program, named X, that only ran DSPJOB OUTPUT(*PRINT) OPTION(*PGMSTK) so I could obtain a printout of the program stack (the program stack includes all the active programs for your job) during the execution of the Attention key program. Then I changed my user profile's ATNPGM parameter to X, signed off, and signed on again.
The results were amazing. My job's program stack normally looks like 1a. When I pressed the Attention key, my program stack looked like 1b. The system loaded a bunch of programs before calling my Attention key program.
The results were amazing. My job's program stack normally looks like Figure 1a. When I pressed the Attention key, my program stack looked like Figure 1b. The system loaded a bunch of programs before calling my Attention key program.
Writing Your Own Attention Key Program
You can write your own Attention key programs in any HLL language: CL, RPG, COBOL, C.... There are two limitations you must keep in mind when writing your program:
The program must not expect any parameters. You have already seen the reason for this limitation.
The program cannot send a message that will be seen by the operator when the program ends. This limitation is maddening because sometimes it's important to use a message to inform the user that the Attention key program ended normally or that it found a problem. I have tried several ways to send a message, including SNDPGMMSG with TOPGMQ(*PRVQMHRC-MSS), but no message appears at the Command Entry panel until something else refreshes the panel, such as pressing F11 twice.
Other than these two limitations, you can do practically anything in your Attention key program. You can use a display file to present a menu with options; you can submit jobs to batch; or you can send messages to specific message queues (such as QSYSOPR or *REQUESTER).
A Couple of Notes
If you have a S/36 background, perhaps you'll feel more at home selecting QSYS/QWSSYSRQ as your Attention key program. Granted, the numbered options are not the same as the ubiquitous Inquiry Options menu with its Options 0 to 7, but at least the concept is the same. In the long run, you're better off by getting used to the SysRq key and letting the Attention key perform more useful tasks.
If you run REXX programs interactively, you may notice that the system "forgets" which program was your Attention key program after a REXX program ends. This happens only if the REXX program writes something to the screen, such as when you use the SAY statement without overriding STDOUT. I reported this bug in the operating system to IBM Level 2 and, as of this writing, they were investigating the matter. The bug is alive and kicking in V2R1M0; if it bites you, use the SETATNPGM command to activate your Attention key program again, or run the Reroute Job (RRTJOB) command without parameters. IBM Level 2 assured me that they had stamped out this bug in V2R1M1.
Hup, Two, Three, Four!
You can execute four tasks from a single display station if you combine the use of SysRq Option 1 with the Attention key.
Hup: Your regular display station's session.
Two: Press the Attention key to run another program or command.
Three: Transfer to the secondary session with SysRq Option 1 and sign on.
Four: Press the Attention key from that session.
There. Your Attention key will keep you marching along.
A More Flexible Approach to Attn Key Programming
To get around the limitations imposed by the Attn key program, I created a special Attn key program which I call STDATNPGM.
STDATNPGM (see 2) reads a data area named after the user profile. The data area contains a command (including parameters) that I want to execute when I press the Attn key. This allows me, for example, to start PDM by simply pressing the Attn key; all I have to do is change my data area to the value STRPDM or WRKMBRPDM. If I grow tired of this later, I can always change the data area to something else.
STDATNPGM (see Figure 2) reads a data area named after the user profile. The data area contains a command (including parameters) that I want to execute when I press the Attn key. This allows me, for example, to start PDM by simply pressing the Attn key; all I have to do is change my data area to the value STRPDM or WRKMBRPDM. If I grow tired of this later, I can always change the data area to something else.
This approach has an advantage. I no longer have to deal with the SETATNPGM command to switch between several Attn key programs, or change my user profile and sign off and back on. I simply change the data area and off I go.
The CHGATNPGM Command
To make the entire process more professional-looking, I created the Change Attn Program (CHGATNPGM) command (3a) with its associated programs ATN001CL (3b) and ATN001CLA (3c). CHGATNPGM lets me specify the command I want to run in the CMD parameter (which can be up to 128 characters long and accepts special values). I can also specify whose Attn key program I am changing by entering a user profile name in the USRPRF parameter-or leave the default value of *CURRENT if I want to change mine.
To make the entire process more professional-looking, I created the Change Attn Program (CHGATNPGM) command (Figure 3a) with its associated programs ATN001CL (Figure 3b) and ATN001CLA (Figure 3c). CHGATNPGM lets me specify the command I want to run in the CMD parameter (which can be up to 128 characters long and accepts special values). I can also specify whose Attn key program I am changing by entering a user profile name in the USRPRF parameter-or leave the default value of *CURRENT if I want to change mine.
The special values allowed by the CMD parameter are *NONE (do nothing when Attn is pressed), *CMDLIN (present a window with a command line), *CMDENT (present the Command Entry panel), *SYSRQS (present the System Request menu), *ASSIST (present the Operational Assistant main menu) and *SYSVAL (run the program named in system value QATNPGM). You can engineer your own special values if you want.
The CMD parameter can contain any valid command. If you're not sure about the syntax of the command you want to run, type a question mark (?) followed by a command name and press Enter. The command you named will be prompted. Now you can fill the blanks and press Enter.
To activate this Attn key system, key and compile STDATNPGM, CHGATNPGM, ATN001CL and ATN001CLA according to the instructions at the bottom end of each figure. Change the system value QATNPGM or the desired user's profile ATNPGM to STDATNPGM. If you change a user's profile ATNPGM while he is signed on, you will need to sign that user off before the change will take place.
At Ease With the Attention Key
Figure 1A Normal program stack
Figure 1a: Normal Program Stack Request Level Program Library QCMD QSYS CMDENTRY MGTLIB 1 QCMD QSYS
At Ease With the Attention Key
Figure 1B Program stack with ATTN key program
Figure 1b: Program Stack With Attn Key Program Request Level Program Library QCMD QSYS CMDENTRY MGTLIB 1 QCMD QSYS QMHRCMSS QSYS QMHGSD QSYS QUIMGFLW QSYS QUIEXFMT QSYS QUIINMGR QSYS QWSGET QSYS QT3REQIO QSYS QWTSEATN QSYS X $MALERN
At Ease With the Attention Key
Figure 2 CL program STDATNPGM
STDATNPGM: + PGM DCL VAR(&COMMAND) TYPE(*CHAR) LEN(128) DCL VAR(&SYSVAL) TYPE(*CHAR) LEN(20) DCL VAR(&SYSVALLIB) TYPE(*CHAR) LEN(10) DCL VAR(&SYSVALPGM) TYPE(*CHAR) LEN(10) DCL VAR(&USRPRF) TYPE(*CHAR) LEN(10) /* Get the user profile name. If the user's data area does not + exist, create it and end program . If it exists, retrieve the + command to be executed. */ RTVUSRPRF USRPRF(*CURRENT) RTNUSRPRF(&USRPRF) RTVDTAARA DTAARA(xxx/&USRPRF *ALL) RTNVAR(&COMMAND) MONMSG MSGID(CPF1015) EXEC(DO) CRTDTAARA DTAARA(xxx/&USRPRF) TYPE(*CHAR) LEN(128) + VALUE(*NONE) TEXT('Data area for STDATNPGM') AUT(*EXCLUDE) RETURN ENDDO /* Translate special values into actual command strings */ IF COND(&COMMAND *EQ '*NONE') THEN(RETURN) ELSE CMD(IF COND(&COMMAND *EQ '*CMDENT') THEN(DO)) CALL PGM(QSYS/QCMD) ENDDO ELSE CMD(IF COND(&COMMAND *EQ '*CMDLIN') THEN(DO)) CALL PGM(QSYS/QUSCMDLN) ENDDO ELSE CMD(IF COND(&COMMAND *EQ '*SYSRQS') THEN(DO)) CALL PGM(QSYS/QWSSYSRQ) ENDDO ELSE CMD(IF COND(&COMMAND *EQ '*ASSIST') THEN(DO)) CALL PGM(QSYS/QEZMAIN) ENDDO ELSE CMD(IF COND(&COMMAND *EQ '*SYSVAL') THEN(DO)) RTVSYSVAL SYSVAL(QATNPGM) RTNVAR(&SYSVAL) CHGVAR VAR(&SYSVALPGM) VALUE(%SST(&SYSVAL 1 10)) CHGVAR VAR(&SYSVALLIB) VALUE(%SST(&SYSVAL 11 10)) IF COND(&SYSVALPGM *EQ '*NONE') THEN(RETURN) ELSE CMD(IF COND(&SYSVALPGM *EQ '*ASSIST') THEN(DO)) CALL PGM(QSYS/QEZMAIN) ENDDO ELSE CMD(DO) CALL PGM(&SYSVALLIB/&SYSVALPGM) ENDDO ENDDO ELSE CMD(DO) /* If not a special value, execute directly */ CALL PGM(QCMDEXC) PARM(&COMMAND 128) MONMSG MSGID(CPF0000) EXEC(DO) RMVMSG PGMQ(*EXT) CLEAR(*ALL) SNDUSRMSG MSG('Attention key handling program produced an + error.') MSGTYPE(*INFO) TOMSGQ(*EXT) RMVMSG PGMQ(*EXT) CLEAR(*ALL) RETURN ENDDO ENDDO ENDPGM
At Ease With the Attention Key
Figure 3A Command CHGATNPGM
CHGATNPGM: CMD PROMPT('Change Attention Key Program') PARM KWD(CMD) TYPE(*CHAR) LEN(128) SPCVAL((*NONE) + (*CMDLIN) (*CMDENT) (*SYSRQS) (*ASSIST) + (*SYSVAL)) MIN(1) PROMPT('Command to run') PARM KWD(USRPRF) TYPE(*NAME) LEN(10) + DFT(*CURRENT) SPCVAL((*CURRENT)) + EXPR(*YES) PROMPT('User profile name')
At Ease With the Attention Key
Figure 3B Validity checker program ATN001CL
ATN001CL: + PGM PARM(&CMD &USRPRF) DCL VAR(&CMD) TYPE(*CHAR) LEN(128) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(132) DCL VAR(&USRPRF) TYPE(*CHAR) LEN(10) /* Retrieve name of current user profile if *CURRENT specified */ IF COND(&USRPRF *EQ '*CURRENT') THEN(RTVUSRPRF USRPRF(*CURRENT) + RTNUSRPRF(&USRPRF)) /* Validate user profile name */ CHKOBJ OBJ(&USRPRF) OBJTYPE(*USRPRF) MONMSG MSGID(CPF9801) EXEC(DO) /* The leading 4 characters will be dropped from the string + used for VALUE when it is displayed using CPD0006 in the + SNDPGMMSG command. Zeroes are used as filler in this part + of the expression whenever &MSGDTA is created. */ CHGVAR VAR(&MSGDTA) VALUE('0000User' *BCAT &USRPRF *BCAT 'not + found.') GOTO CMDLBL(ERROR) ENDDO MONMSG MSGID(CPF9802) EXEC(DO) CHGVAR VAR(&MSGDTA) VALUE('0000You are not authorized to + change user profile' *BCAT &USRPRF *TCAT '.') GOTO CMDLBL(ERROR) ENDDO /* If &CMD has special value, end validation */ IF COND(&CMD *EQ '*NONE' *OR &CMD *EQ '*CMDLIN' *OR &CMD *EQ + '*CMDENT' *OR &CMD *EQ '*SYSRQS' *OR &CMD *EQ '*ASSIST' *OR + &CMD *EQ '*SYSVAL') THEN(RETURN) /* Check command string for syntax errors. If '?' entered at the + beginning of the command string, QCMDCHK invokes the command + prompter and &CMD is replaced with the completed command string.+ In this case, command's CPP (ATN001CLA) receives the completed + command string (after prompting). */ CALL PGM(QCMDCHK) PARM(&CMD 128) MONMSG MSGID(CPF0000) EXEC(DO) CHGVAR VAR(&MSGDTA) VALUE('0000Invalid command syntax.') GOTO CMDLBL(ERROR) ENDDO RETURN ERROR: + SNDPGMMSG MSGID(CPD0006) MSGF(QCPFMSG) MSGDTA(&MSGDTA) + MSGTYPE(*DIAG) SNDPGMMSG MSGID(CPF0002) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) ENDPGM
At Ease With the Attention Key
Figure 3C Command Processing Program ATN001CLA
ATN001CLA: + PGM PARM(&CMD &USRPRF) DCL VAR(&CMD) TYPE(*CHAR) LEN(128) DCL VAR(&USRPRF) TYPE(*CHAR) LEN(10) /* Verify existence of user's data area. If nonexistent, create it + and change ownership to the correct user profile. */ CHKOBJ OBJ(xxx/&USRPRF) OBJTYPE(*DTAARA) MONMSG MSGID(CPF9801) EXEC(DO) CRTDTAARA DTAARA(xxx/&USRPRF) TYPE(*CHAR) LEN(128) + VALUE(&CMD) TEXT('Data area for STDATNPGM') AUT(*EXCLUDE) CHGOBJOWN OBJ(xxx/&USRPRF) OBJTYPE(*DTAARA) NEWOWN(&USRPRF) MONMSG MSGID(CPF0000) ENDDO /* Change the contents of the user's data area as requested */ CHGDTAARA DTAARA(xxx/&USRPRF *ALL) VALUE(&CMD) MONMSG MSGID(CPF0000) EXEC(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('You are not + authorized to change' *BCAT &USRPRF *TCAT '''s Attn key + program') MSGTYPE(*ESCAPE) RETURN ENDDO SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Attn key program + program for' *BCAT &USRPRF *BCAT 'changed to' *BCAT &CMD) + MSGTYPE(*COMP) ENDPGM
LATEST COMMENTS
MC Press Online