Fri, Sep
0 New Articles

Abandon Response Indicators

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

For years, OS/400 programmers have used function keys to control interactive applications. All function keys are either Command Function (CF) keys or Command Attention (CA) keys. These two types of keys are effectively the same in their functionality except that CF keys return data from the screen to the application, whereas CA keys do not.

There are 24 standard function keys as well as a variety of other special-purpose keys, such as Help, Home, Rollup (page down), Rolldown (page up), Print, FieldExit, and so forth. The standard function keys can act as either CA or CF keys, but the special-purpose keys can be used only as CA keys.

Declaring a function key in your display file is relatively simple. Indicators are used to pass the function key requests to the RPG program. Traditionally, an indicator is assigned to the key when it is declared in the display file. An indicator is assigned by specifying the indicator within parentheses adjacent to the keyword. Specify a CFxx keyword when CF capability is needed or a CAxx keyword when CA capability is required.

In Figure 1, CA keys 3 and 5 are declared along with Rollup and Rolldown. In addition, CF key 4 is declared. When these keys are used to return control to the program, the corresponding indicator is set on in the RPG program.

By the way, these indicators are referred to as "command key response indicators," although lately the term "command key" has been replaced by the term "function key."

     A                               INDARA
     A                               CA03(73 'Exit')
     A                               CF04(74 'Prompt')
     A                               CA05(75 'Refresh')
     A                               ROLLUP(41 'Page down')
     A                               ROLLDOWN(42 'Page up')
     A          R EDITREC    

Figure 1: This is an example of traditional function key declarations in DDS.

Eliminating Response Indicators

My goal this week is to get you to consider abandoning these response indicators and use an alternative technique, one that avoids the use of indicators all together. One technique for doing this has been around seemingly forever and yet seems to have become a lost technology. It's my goal to resurrect this technique to help eliminate the use of indicators in RPG programs. After all, eliminating the using of indicators has been a long-standing goal of most RPG programmers; this technique simply helps us achieve that end.

To accomplishing this transition, relatively few changes need to be made to the way function keys are declared and processed. The first change is in the way function keys are declared in the DDS itself. The CAxx or CFxx keywords may be specified without a response indicator, as illustrated in Figure 2.

     A                                      INDARA
     A                                      CA03
     A                                      CF04
     A                                      CA05
     A                                      ROLLUP
     A                                      ROLLDOWN
     A          R EDITREC                              

Figure 2: Here's an example of function key declaration without response indicators.

By avoiding the response indicator, the function key is simply specified by itself. Removing the response indicators is not strictly required for this technique. They may be specified if necessary for backward compatibility and then simply ignored in the RPG program.

Which Function Key Is Pressed?

So how does your RPG program know which function key was pressed when response indicators are not used? Answer: the INFDS.

Since the implementation of RPG II on the System/34 (and probably back as far as the System/3), the INFDS for display files, commonly referred to as the "workstation data structure" or simply "WSDS," has included a subfield containing the so-called Attention Identification Byte. Perhaps this subfield's name is ambiguous and is therefore ignored by most developers. But the Attention Identification Byte (sometimes called the "AID Byte") is nothing more than the scan code of the function key used to return control to the RPG program.

To declare the WSDS in RPG, the INFDS keyword is used on the File Continuation specification (in RPG III) and the File keyword area (in RPG IV).

In RPG IV, the WSDS is declared as follows:

FEditCust  CF   E             WORKSTN INFDS(WSDS)

In RPG III, the WSDS is declared as follows:

FEDITCUSTC E                    WORKSTN      KINFDS WSDS  

Once a workstation data structure is identified on the File specification, an actual data structure must be declared to receive the so-called I/O feedback information from the display file. This data structure will have several values stored in it; however, a little research (look on page 18 and 19 of The Modern RPG IV Language) reveals that the Attention Identification Byte or "scan code" is returned in position 369 of the WSDS.

Therefore, in RPG IV, we would code the following:

D WSDS            DS
D  FKey                 369    369A

Whereas in RPG III, we would code this:

IWSDS        DS             
I                                      369 369 FKEY

Let me put these pieces together. The RPG IV and RPG III code is similar, so, depending on which language you use, Figure 3a or Figure 3b contains the necessary code that provides access to the Function key scan codes.

     FEditCust  CF   E             WORKSTN INFDS(WSDS)

     D WSDS            DS
     D  FKey                 369    369A

Figure 3a: This is the RPG IV Workstation Data Structure (WSDS) with FKey subfield.

FEDITCUSTC E                    WORKSTN      KINFDS WSDS  
IWSDS        DS             
I                                      369 369 FKEY

Figure 3b: This is the RPG III Workstation Data Structure (WSDS) with FKEY subfield.

The data structure subfield named FKEY is declared and can be used throughout the program. It can be used to determine which function key (if any) was used to return control to the program from an EXFMT or WRITE/READ combination.

There is no rocket science involved in this technique, and you have probably written code very similar to the WSDS examples from Figures 3a and 3b.

Testing for a Function Key

There are two more pieces to this technique, however, and both are very easy to implement. The first requires you to research which scan codes are returned for each function key. Normally, this could take some time, but rather than make you do it, I've created the following table with the scan codes (taken from chapter 1 of The Modern RPG IV Language) and listed them in Figure 4.

Function Key
Value in Hex
Function Key
Value in Hex
Rec'd Bksp
Auto Enter

Figure 4: This table lists the Attention Identification Byte/function key scan codes.

Comparing the FKEY subfield in the WSDS from Figures 3a and 3b to a hexadecimal value isn't difficult, but how much more intuitive is

    IF FKey = X'33'


     IF *IN73=*ON

Not very intuitive.

To avoid hard-coding hexadecimal constants throughout the source code and to eliminate ambiguity, you will need to declare a set of named constants that identify each of the hexadecimal values from Figure 4. Of course, it would be easier if you, for example, named the constants for the function key scan codes the same as the function key names--that is, the named constant for the F3 key would be named F3 and represent a value of X'33'.

In RPG IV, named constants are declared on the Definition specification; in RPG III, they are declared using Input specifications.

A source member that may be used as a /COPY is listed in Figure 5. It includes a complete set of function keys and their hexadecimal scan codes for RPG IV.

     D* Mbr(FKEYS) - Function key Scan Codes
     D* ----------------------------------------------
     D* (c) Copyright 1998 by Robert Cozzi, Jr.
     D* ----------------------------------------------
     D F1              C                   Const(X'31')
     D F2              C                   Const(X'32')
     D F3              C                   Const(X'33')
     D F4              C                   Const(X'34')
     D F5              C                   Const(X'35')
     D F6              C                   Const(X'36')
     D F7              C                   Const(X'37')
     D F8              C                   Const(X'38')
     D F9              C                   Const(X'39')
     D F10             C                   Const(X'3A')
     D F11             C                   Const(X'3B')
     D F12             C                   Const(X'3C')
     D F13             C                   Const(X'B1')
     D F14             C                   Const(X'B2')
     D F15             C                   Const(X'B3')
     D F16             C                   Const(X'B4')
     D F17             C                   Const(X'B5')
     D F18             C                   Const(X'B6')
     D F19             C                   Const(X'B7')
     D F20             C                   Const(X'B8')
     D F21             C                   Const(X'B9')
     D F22             C                   Const(X'BA')
     D F23             C                   Const(X'BB')
     D F24             C                   Const(X'BC')
     D CLEAR           C                   Const(X'BD')
     D ENTER           C                   Const(X'F1')
     D HELP            C                   Const(X'F3')
     D ROLLDOWN        C                   Const(X'F4')
     D ROLLUP          C                   Const(X'F5')
     D PRINT           C                   Const(X'F6')
     D AUTOENTER       C                   Const(X'3F')

Figure 5: FKey Named Constants--Use this source member as a /COPY.

To use this member, create a source member named something like FKEYS and store the code from Figure 5 in it. Then, use the /COPY or /INCLUDE directive to import the named constants into each interactive program that needs it.

It Just Keeps Getting Easier

And now the easiest part: To take advantage of this capability, all you have to do is insert a check of the FKEY subfield for the valid function key scan code (from Figure 5). Insert this check following an EXFMT or a WRITE opcode to a display file.

I like to use a SELECT/WHEN inline case group to detect which key was pressed, but you can use an IF/ELSEIF condition if you're on V5R1 or later. Figure 6 includes a simple example of the SELECT/WHEN test.

     C                   Dou       FKey = F3
     C                   Exfmt     EditRec
     C                   Select
     C                   When      FKey = Enter
     C                   Exsr      ProcessData
     C                   When      FKey = F4
     C                   CallP     Prompter
     C                   When      FKey = F5
     C     *NOKEY        Clear                   EditRec
     C                   Iter
     C                   When      Fkey = RollUp    
     C                   Exsr      GetNextRec
     C                   When      Fkey = RollDown
     C                   Exsr      GetPrevRec
     C                   endsl
     C                   enddo

Figure 6: Use this example for RPG IV processing with the Attention Identification Byte.

A Do loop is used to keep the processes running until the user presses function key 3. Then, an EXFMT is issued to write the display file format and wait for the user to press Enter or some function key. When the user does this, a SELECT/WHEN inline case group checks to see which key is used to return control to the program.

You simply compare the value of the FKEY subfield of the WSDS data structure to the corresponding named constant. Even the ENTER key can be tested, as illustrated on line 4 of Figure 6.

I've brought everything together in one place in Figure 7. It contains the display file declaration and the INFDS keyword, the /COPY of the named constants, and the WSDS declaration including the FKEY subfield. Of course, it also illustrates the use of the subfield and the named constants in the Calculation specifications.

     FEditCust  CF   E             WORKSTN INFDS(WSDS)


     D WSDS            DS
     D  FKey                 369    369A

     C                   Dou       FKey = F3
     C                   Exfmt     EditRec
     C                   Select
     C                   When      FKey = Enter
     C                   Exsr      ProcessData
     C                   When      FKey = F4
     C                   CallP     Prompter
     C                   When      FKey = F5
     C     *NOKEY        Clear                   EditRec
     C                   Iter
     C                   When      Fkey = RollUp    
     C                   Exsr      GetNextRec
     C                   When      Fkey = RollDown
     C                   Exsr      GetPrevRec
     C                   endsl
     C                   enddo

Figure 7: This sample code shows the completed Attention Identification Byte/scan code processing.

The combination of scan codes and named constants brings a level of clarity to RPG IV not previously available. It allows you to easily add new routines based on function keys without concern for indicators (no more worrying if indicator XX is being used someplace else in the program).

One of the objectives of RPG IV is to eliminate indicator usage entirely. While there is nothing you can do about a display file's requirement to use indicators, you can reduce your dependency on indicators in the RPG program through the use of the function key scan code and the FKEY subfield.

Bob Cozzi has been programming in RPG since 1978. Since then, he has written many articles and several books, including The Modern RPG IV Language --the most widely used RPG reference manual in the world. Bob is also a very popular speaker at industry events such as COMMON and RPG World and is the author of his own Web site, www.rpgiv.com, and of the RPG ToolKit, an add-on library for RPG IV programmers.


Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.

MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale



Support MC Press Online

$0.00 Raised:

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: