admin管理员组

文章数量:1392895

I am having trouble capturing value of function key pressed in RPG screen. Here is essential code...

dcl-f SF_04D  workstn  infds(infds1) sfile(SFL1:RRN) ;     

 dcl-c F1Key       const(x'01');   
 dcl-c F3Key       const(x'03');   
 dcl-c F5Key       const(x'05');   

 D infds1          DS                             
 D KeyPressed            369    369               
 
 .
 .
 .
  dsply KeyPressed;   // displays '1' 
  exfmt CtlRecord ;           
  // Press F3 to exit -> Exits OK
  
  dsply KeyPressed;   // shows long yellow line on screen          
  If Keypressed = F3Key; // not getting here.
  dsply 'F3';                   
  Endif;                        

Note:

in screen we define F03
CA03(03 'F3=Exit')        

I am having trouble capturing value of function key pressed in RPG screen. Here is essential code...

dcl-f SF_04D  workstn  infds(infds1) sfile(SFL1:RRN) ;     

 dcl-c F1Key       const(x'01');   
 dcl-c F3Key       const(x'03');   
 dcl-c F5Key       const(x'05');   

 D infds1          DS                             
 D KeyPressed            369    369               
 
 .
 .
 .
  dsply KeyPressed;   // displays '1' 
  exfmt CtlRecord ;           
  // Press F3 to exit -> Exits OK
  
  dsply KeyPressed;   // shows long yellow line on screen          
  If Keypressed = F3Key; // not getting here.
  dsply 'F3';                   
  Endif;                        

Note:

in screen we define F03
CA03(03 'F3=Exit')        
Share Improve this question asked Mar 14 at 22:53 mortimermortimer 896 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 2

Alas, there are several ways to skin a cat. Here are three ways...

            dcl-f  TESTD  workstn  infds(dspfinfo)
                                   indds(indicators);

            // indds (Indicator Data Structure)
            dcl-ds indicators;
              F1Key ind pos(1);
              F3Key ind pos(3);
              F5Key ind pos(5);
            end-ds;

            // infds (File information data structure)
            dcl-ds dspfinfo;
               Keypressed char(1) pos(369);
            end-ds;

            dcl-c PF1 const(x'31'); // not x'01'  !
            dcl-c PF2 const(x'32'); // not x'02'  !
            dcl-c PF3 const(x'33'); // not x'03'  !

            exfmt CtlRecord ;
            // Press F3 to exit

            If Keypressed = PF3;
              dsply 'F3 was pressed';
            Endif;

            If F3Key;
              dsply 'Indicator F3Key (03) is on';
            Endif;

            If *INKC;
              dsply 'Indicator INKC (03) is on';
            Endif;

            Return;

You are using the wrong keyword. It should be indds, not infds.

Something like this

dcl-f SF_04D  workstn  indds(indicators) sfile(SFL1:RRN) ; 

dcl-ds indicators;
  F1Key ind pos(1);
  F3Key ind pos(3);
  F5Key ind pos(5);
end-ds;

...

If F3Key; 
  dsply 'F3';                   
Endif; 

Or use the standard keyword INDARA + the required CFnn in the display file and then check the state of the *INKx indicators (*INKA for F1, *INKB for F2, etc.)

This is generally how I define display files in my RPG:

dcl-f pgm0001d   Workstn Qualified
                         Ignore(Dummy)
                         Sfile(sfl1: r1)
                         Sfile(msgsfl: m1)
                         Indds(Indicators)
                         Infds(fb);

dcl-ds ctlds      LikeRec(pgm0001d.ctl1: *all) Inz;
dcl-ds fkout      LikeRec(pgm9991d.fkeys: *output) Inz;
dcl-ds msgout     LikeRec(pgm0001d.msgctl: *output) Inz;

Notice that I have both Infds and Indds This way I don't have to expend limited indicators for things that don't need them, like function keys. Also notice that I am using the Qualified keyword. I do that on all my files now so I don't have to worry about fields overlapping unexpectedly. One consequence of the Qualified keyword is that the *INKx indicators don't work. That's not a problem for me, I don't use those anyway.

The associated function key definitions in my display file look like this:

     A                                      INDARA
      ....
     A* F3=Exit
     A                                      CF03
     A* F4=Prompt
     A                                      CF04
     A* F5=Refresh
     A                                      CF05

Notice that I am always using CF so I always get the data on the screen back whether I am going to use it or not. Also there is no indicator listed for the function keys. This enables the key pressed field in the feedback area. You either get to use indicators to tell when a key is pressed, or you get to use the feedback area, not both.

本文标签: ibm midrangeRPG DDS screencapture function key (F1F05) valueStack Overflow