DSPF function keys in fully free RPGLE

  • Home
  • /
  • Blog
  • /
  • DSPF function keys in fully free RPGLE

February 1, 2016

DSPF function keys in fully free RPGLE

By NickLitten

February 1, 2016

aidz, cmdkey, dspf, pfkey

Picking up user keyboard interactions in RPG is easy

But as usual there are many ways of doing it. Three main techniques are

(1) Assign a numeric value to the function keys

Probably the most common is to assign an indicator value to a function so that CMD01 sets on *IN01, CMD02 sets on *IN02 and so on.

(2) Leave the internal indicators for function keys

I see this a lot and I still sometimes use it if my program has simple function key handling. Basically, if you do not assign a numeric indicator to the function key, good ole’ IBM i will assign a free one for us. Namely CMD01 sets on *INKA, CMD02 sets on *INKB, CMD03 sets on *INKC and so on. But… but… beware of the missing alphabet letters 😉

(3) Indicators smell. Dont use them

Define an information data structre in a /copybook and then you can reuse this simple technique where you like. This is my preferred technique.

dcl-f dspf workstn infds(dspfinfo);

 // Use INFDS to pickup the AID value (hex value for keypresses)
 dcl-ds dspfinfo;
 pressedKey char(1) pos(369);

 // Define Constants with HEX value of keypresses
 dcl-c PF1 const(x'31');
 dcl-c PF2 const(x'32');
 dcl-c PF3 const(x'33');
 dcl-c PF4 const(x'34');
 dcl-c PF5 const(x'35');
 dcl-c PF6 const(x'36');
 dcl-c PF7 const(x'37');
 dcl-c PF8 const(x'38');
 dcl-c PF9 const(x'39');
 dcl-c PF10 const(x'3A');
 dcl-c PF11 const(x'3B');
 dcl-c PF12 const(x'3C');
 dcl-c PF13 const(x'B1');
 dcl-c PF14 const(x'B2');
 dcl-c PF15 const(x'B3');
 dcl-c PF16 const(x'B4');
 dcl-c PF17 const(x'B5');
 dcl-c PF18 const(x'B6');
 dcl-c PF19 const(x'B7');
 dcl-c PF20 const(x'B8');
 dcl-c PF21 const(x'B9');
 dcl-c PF22 const(x'BA');
 dcl-c PF23 const(x'BB');
 dcl-c PF24 const(x'BC');
 dcl-c Clear const(x'BD');
 dcl-c Enter const(x'F1');
 dcl-c Help const(x'F3');
 dcl-c Up const(x'F4');
 dcl-c Down const(x'F5');
 dcl-c Print const(x'F6');
 Exfmt Screen;
 If pressedKey = Enter;
 // do some ENTER stuff
 else pressedKey = Help;
 // do some HELP stuff
 else pressedKey = PF03;
 // Exit or something?
 // ... do other stuff for other keys
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips