26
Fri, Apr
1 New Articles

Indicator-Free Function Keys

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
For years, we have witnessed the ever-so-slow evolution of function key identification in RPG. From the original KG indicator for "Command Key 7" on the System/32 and 34, to *INKG on System/38, to numeric indicators in RPG III, and now indicator-free function keys for RPG III and RPG IV on AS/400 and iSeries. In this issue, I show you how to take advantage of two relatively simple techniques to help you continue on down the path of eliminating the use of indicators from your RPG IV programs.

Then, in "Page II--The Midrange Manager," I include QuickReviews of two very important tools for any AS/400 shop, the highly reliable MochaSoft Telnet-based 5250 emulator and the Work with Database File (WRKDBF) command. Mocha's 5250 emulator is fast becoming the emulator of choice for AS/400 shops and consultants who want to avoid the "issues" that occur from installing Client Access on their PCs. WRKDBF is currently a freeware utility that is downloadable from its own Web site. It is an AS/400 tool that displays any database file and allows editing of that database file. In addition, it supports the surprising ability to undelete previously deleted records!

Indicator-Free Function Keys

Everyone uses DDS for display files. Most display file formats have function keys enabled to cancel an action, back up a process, do a search, or perform some other task. We all know that, in DDS, function keys can be either Command Function keys, identified by the CFxx keywords, or Command Attention keys, identified by the CAxx keywords.

The only difference between CF keys and CA keys is that CF keys return data to the program from the display file and perform any DDS-based error checking. CA keys do not return data to the program and therefore avoid any DDS-based error checking. One common use for CA keys is the F5=Refresh function. F5 is usually enabled by specifying a CA05 keyword in the DDS. This allows the end-user to press F5 and have an undo-style function performed without any significant programming.

As RPG programming has evolved, the use of indicators has fast become taboo. However, using indicators in display files has always been problematic, particularly when specifying function keys.

"Specify a response indicator," as it is called, causes the system to automatically set on an associated indicator when the function key is pressed. This normal practice easily allows the RPG programmer to test which function key was pressed. It is a practice I hope to make extinct.

If you' re a long-time RPG programmer--and I mean pre-OS/400 and pre-CPF (System/38)--you may remember something about the Attention Identification Byte. This byte is a one-position field in the Information Data Structure for WORKSTN device files (WSDS) and is automatically updated when the end-user presses a function key.

The Attention Identification Byte is stored in position 369 of the WSDS and can be accessed by including code in your program that is similar to the code in Figure 1.


.....FFileName++IFEASFRlen+LKeylnKFDevice+.Functions+++++++++++++++
0001 FEditCust CF E WORKSTN INFDS(WSDS)
0002 FCUSTMAST UF A E K DISK

.....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++
0003 DWSDS DS
D** Use one of the following syntax styles
0004 D Fkey 369 369A
0005 D Fkey_Alt 1A Overlay(WSDS : 369)
0006 /COPY FKEYS
Figure 1: Attention Identification Byte in the WSDS

The WSDS data structure on line 3 contains two subfields: Fkey and Fkey_Alt. You need to use only one of these fields, but I wanted to illustrate the alternate syntax for specifying the subfield. Fkey (line 4) uses the traditional From/To column notation. Fkey_Alt (line 5), on the other hand, is the same as Fkey but uses the Overlay keyword to identify the location in the WSDS where the field appears. Either is acceptable in this situation. Regardless of style, I would use the name Fkey as the field name used in your code.

Line 6 illustrates how to include the source member I feature later in this article in Figure 4.

Traditionally, to specify the command keys in your DDS, you would use response indicators, similar to Figure 2.

.....A*n01n02n03............................Keywords+++++++++++++++
0001 A CA03(03 'Exit' )
0002 A CF04(04 'Prompt' )
0003 A CA05(05 'Refresh' )
Figure 2: Traditional DDS with Response Indicators

This traditional DDS style can be used with the Attention Identification Byte, so you don't have to change your existing DDS source code to take advantage of this technique. However, you no longer need to specify response indicators if you intend to use only the Attention Identification Byte technique. So that same code from Figure 2, rewritten to take advantage of the Attention Identification Byte technique, would appear as in Figure 3.

.....A.n01n02n03............................Keywords+++++++++++++++
0001 A CA03
0002 A CF04
0003 A CA05
Figure 3: DDS Without Response Indicators

So, how do you use this technique? Well, you first need to create a separate source member that you subsequently /COPY into your applications. This source member should contain named constants, using symbolic names that represent the scan code for the various function keys. What scan code you use depends on whether your executable is running on an EBCDIC machine, like the AS/400, or an ASCII machine, such as Windows or a flavor of UNIX. Since 99.9999% of all RPG today is EBCDIC, I've included the /COPY for you in Figure 4.

 ********************************************************
** (c) 1995 Robert Cozzi, Jr.
** All rights reserved.
** Permission to use in RPG program
** source is granted.
** -----------------------------------------
** Module . . . . . . . . FKEYS
** Description . . . . . Function key named constants
** Purpose . . . . . . . Use as a /COPY member.
** Compare values to pos 369
** of a WORKSTN device's INFDS.
** Notes: Used on AS/400 EBCDIC systems only.
********************************************************
.....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++
0001 D F1 C CONST(X'31' )
0002 D F2 C CONST(X'32' )
0003 D F3 C CONST(X'33' )
0004 D F4 C CONST(X'34' )
0005 D F5 C CONST(X'35' )
0006 D F6 C CONST(X'36' )
0007 D F7 C CONST(X'37' )
0008 D F8 C CONST(X'38' )
0009 D F9 C CONST(X'39' )
0010 D F10 C CONST(X'3A' )
0011 D F11 C CONST(X'3B' )
0012 D F12 C CONST(X'3C' )
0013 D F13 C CONST(X'B1' )
0014 D F14 C CONST(X'B2' )
0015 D F15 C CONST(X'B3' )
0016 D F16 C CONST(X'B4' )
0017 D F17 C CONST(X'B5' )
0018 D F18 C CONST(X'B6' )
0019 D F19 C CONST(X'B7' )
0020 D F20 C CONST(X'B8' )
0021 D F21 C CONST(X'B9' )
0022 D F22 C CONST(X'BA' )
0023 D F23 C CONST(X'BB' )
0024 D F24 C CONST(X'BC' )
0025 D CLEAR C CONST(X'BD' )
0026 D ENTER C CONST(X'F1' )
0027 D HELP C CONST(X'F3' )
0028 D ROLLDN C CONST(X'F4' )
0029 D ROLLUP C CONST(X'F5' )
0030 D PRINT C CONST(X'F6' )
0031 D RCBKSP C CONST(X'F8' )
0032 D AUTENT C CONST(X'3F' )
Figure 4: Source Member FKEYS; Named Constants for Function Keys

Use /COPY to insert the source member into any RPG IV source code that uses this Attention Identification Byte technique. Figure 5 shows an example of how to use the Fkey subfield and the named constants.

.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++
0001 C Dou Fkey = F3 or Fkey = F12

0002 C EXFMT PROMPT
0003 C Select
0004 C When Fkey = Enter
0005 C Exsr ShowData
0006 C When Fkey = F4
0007 C CallP Search
0008 C endSL

0009 C EndDo
Figure 5: Example Use of Function Key Scan Codes in RPG IV

I call this technique Function Key Scan Codes, and I use it exclusively in my code. I no longer use response indicators and have always thoroughly disliked the use of the RPG II *INKx indicators.

In your own code, I suggest that you try to use this technique as your shop standard for new code and work it into older code as time permits.

What About the Indicator Data Structure (INDDS)?

The INDDS is different technology than the technology that uses the Attention Identification Byte. IBM Canada put INDDS into RPG IV because IBM U.S. (Rochester) had not enhanced DDS to allow the programmer to avoid the use of indicators.

The INDDS allows you to automatically map the indicators from a workstation display file into a data structure that is 99 positions in length. Each position in that data structure corresponds to one of RPG's numeric indicators. For example, position 32 of the INDDS maps to indicator 32 used by the corresponding workstation file. So if indicator 32 is used to condition the DSPATR(HI PC) keyword in your DDS, you would use position 32 of the INDDS to avoid referring to *IN32 in your RPG code. Instead, you would assign a field name, such as whose data type is "N" (Named Indicator), to position 32 of the INDDS data structure.

Take care when you use this technique. Though it's very useful, it does eliminate your ability to manipulate the indicators used in the workstation file through their traditional names. That is, using the INDDS replaces access to the indicators used in your display file DDS. If, for example, you use indicator 32 in a display file and use the INDDS in your program, the state of indicator 32 in the program becomes irrelevant to the display file. You can set it off or on, but the keywords or fields in the DDS conditioned by indicator 32 will not be impacted. Only changes to position 32 of the INDDS will affect indicator 32 as used by the DDS. This means that you don' t have to worry about which indicators are used and for what purpose. And that's a good thing.

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

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