Guru: When Attention Turns To You – Writing Your Own ATTN Program
September 22, 2025 Gregory Simmons
Most IBM i users press the Attention key without much thought. They’re used to the familiar system-supplied menu popping up, or maybe a command line depending on how their profile is configured. But buried in the system is a powerful customization point: you can assign your own ATTN program. Doing so gives you the ability to intercept that key and provide functionality tailored exactly to your shop’s needs. There are three main ways to establish an attention program, each with its own strengths and tradeoffs.
The most obvious method is at the user profile level. Within the profile’s attributes is a slot for the ATTNPGM parameter. Set it there, and every time that user presses Attention, the designated program runs. This is often the cleanest approach because it follows the user wherever they sign on. The downside is that many developers and operators don’t have the authority to update their own profiles, which means an administrator has to make the change on their behalf.
The second method is at the job level. Using the CHGJOB command, you can alter the ATTNPGM setting for your current job. That means you don’t need to touch the profile itself, and the change vanishes as soon as the job ends. It’s a good approach for testing or temporary overrides. Developers who don’t have profile-change authority but do have authority to change their job often find this to be the most practical route.
The third method is at the system level. By setting the system values QATNPGM and QATNPGMLIB, you can assign a default Attention program that applies to everyone on the system. If you specify QATNPGM(*MENU), the system calls an Attention menu instead of a program, and you can control its contents just like any other menu object. This method is sweeping in its scope: the moment you change those system values, the new Attention behavior is in place for every user. Because of that, you will need *SECADM authority (or higher, such as *SECOFR) to change them.
A casual developer won’t be able to make this adjustment – and that’s a good thing. Misusing it can confuse or even lock out users if the program is buggy or if the menu doesn’t provide a safe exit path.
Once you understand how to assign an ATTN program, the fun begins in deciding what it should do. For a first experiment, let’s keep it simple. You can write a CL program that just issues a command and then returns the user to where they started. If you have the authority, set it as your ATTN program on your user profile. If not, you can still test it by prompting the CHGJOB command and setting the ATTNPGM parameter to point to your program.
Here’s a minimal example you can try today. Create a source member called MYATTN in QCLSRC with the following code:
PGM DCL VAR(&MSG) TYPE(*CHAR) LEN(50) CHGVAR &MSG '*** Attention Key Pressed ***' SNDPGMMSG MSG(&MSG) RETURN ENDPGM
Compile it with CRTCLPGM, and then either change your profile with CHGUSRPRF USRPRF(YOURUSER) ATTNPGM(MYLIB/MYATTN) or just run CHGJOB ATTNPGM(MYLIB/MYATTN) in your current session. Now, whenever you hit the Attention key, your little program will fire, display its message, and hand you back control.
That’s just the beginning. Once you get comfortable with the mechanics, you can extend this in countless directions: logging where and when the Attention key was pressed, providing a utility menu for quick commands, or even intercepting attention in applications to guide users back to safety. The ATTN program is a small feature that opens up big opportunities for customization.
Until next time, happy coding.
Gregory Simmons is a Project Manager with PC Richard & Son. He started on the IBM i platform in 1994, graduated with a degree in Computer Information Systems in 1997 and has been working on the OS/400 and IBM i platform ever since. He has been a registered instructor with the IBM Academic Initiative since 2007, an IBM Champion and holds a COMMON Application Developer certification. When he’s not trying to figure out how to speed up legacy programs, he enjoys speaking at technical conferences, running, backpacking, hunting, and fishing.
RELATED STORIES
Guru: WCA4i And Granite – Because You’ve Got Bigger Things To Build
Guru: When Procedure Driven RPG Really Works
Guru: Unlocking The Power Of %CONCAT And %CONCATARR In RPG
Guru: AI Pair Programming In RPG With Continue
Guru: AI Pair Programming In RPG With GitHub Copilot
Guru: RPG Receives Enumerator Operator
Guru: RPG Select Operation Gets Some Sweet Upgrades
Guru: Growing A More Productive Team With Procedure Driven RPG
Guru: With Procedure Driven RPG, Be Precise With Options(*Exact)
Guru: Testing URLs With HTTP_GET_VERBOSE
Guru: Fooling Around With SQL And RPG
Guru: Procedure Driven RPG And Adopting The Pillars Of Object-Oriented Programming
Guru: Getting Started With The Code 4 i Extension Within VS Code
Guru: Procedure Driven RPG Means Keeping Your Variables Local
Guru: Procedure Driven RPG With Linear-Main Programs
Guru: Speeding Up RPG By Reducing I/O Operations, Part 2
Guru: Speeding Up RPG By Reducing I/O Operations, Part 1
Guru: Watch Out For This Pitfall When Working With Integer Columns