drop down joomla login module

Retrieve the Function Key Used on a Display File

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

(Author's Note: This week's article is an excerpt from my upcoming book RPG TNT: 101 Dynamite Tips and Techniques for RPG IV Programmers.)

For decades, programmers have used response indicators to signal the Command or Function key pressed by a user. The program with this approach is that it uses an indicator and the indicator gives no indication of which key was actually pressed.

For just as long as there have been interactive programs, there has been the File Information Data Structure, or INFDS. The INFDS is assigned to files in RPG and contains information about the status of the file. For display files, the INFDS is often referred to as the Workstation Data Structure, or WSDS.

Whenever a display file record is returned to the RPG program, the WSDS is updated. Within the WSDS, in position 369. . Each function key (as well as the other entry keys, such as Enter, Help, Home, Print, PageUp, PageDown, etc.) returns a unique scan code that identifies the key used to return control to the program.

No response indicators are assigned to the key in the DDS when this technique is used. Only the function key needs to be specified. Of course, if the response indicator is already there, you may certainly ignore it and everything will work fine. Position 369 of the WSDS is always updated, regardless of the use of response indicators in the DDS. Here's an example:

     A                                      INDARA
     A                                      CA03 CF12
     A                                      CF04
     A                                      CF05
     A          R CUSTMAINT                 CLRL(*NO)

This is great news because it not only eliminates the use of an indicator or ten, but also allows you to check for the specific key itself.

INFDS position 369 contains the function key scan code:

     FEDITCUST  CF   E             Workstn INFDS(WSDS)

     D WSDS            DS
     D  FKey                          1A   Overlay(WSDS:369)

The scan codes that are returned to position 369 have been published in my best-selling RPG IV book, The Modern RPG IV Language, for decades. I've reproduced them here in Figure 1.

      **********************************************************
      ** (c) Copyright 1989 - 2003 by Robert Cozzi, Jr.       **
      **********************************************************
      **             From RPG xTools (www.rpgxtools.com)      **
      **      -----------------------------------------       **
      **  Description  . . . . . Function key named constants **
      **  Features . . . . . . . The Scan Code of each        **
      **                         each function key.           **
      **********************************************************
.....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++
     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 PAGEUP          C                   CONST(X'F4')
     D PAGEDOWN        C                   CONST(X'F5')
     D ROLLDOWN        C                   CONST(X'F4')
     D ROLLUP          C                   CONST(X'F5')
     D PRINT           C                   CONST(X'F6')
     D RECBACKSP       C                   CONST(X'F8')
     D AUTENT          C                   CONST(X'3F')

Figure 1: Scan codes are returned to position 369.

In your RPG IV code, the following technique would be used to test for the function key used to return control to the program:

     C                   EXFMT     CustMaint
     C                   SELECT
     C                   When      FKey = F12
     C                   Callp     previous()
     C                   When      FKey = F3
     C                   exsr      Exit
     C                   When      FKey = F5
     C                   Callp     Rollback(1)
     C                   endSL

The use of indicators to condition code has been passé for almost 20 years. Continuing to condition your own code on function key response indicators is just as passé. Now you have the tools to stop using response indicators and write responsible code.

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.

BOB COZZI

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.

RPG TnT RPG TnT
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

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

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

  • 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

  • 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: