Link to home
Start Free TrialLog in
Avatar of dpalme
dpalme

asked on

testing for multiple function key presses

As I have been working through learning RPGLE, I have had to create some of my own programmatic problems because the material I have been provided leaves a bit to be desired, so I have embarked on a program of my own.

below is some of the cdoe I have written that basically performs a loop untiil the user selects F3 in which case they exit the program.  I now find myself needing to test for other function keys and I am not quite sure which is the best way to handle this; I could enter some select statements or case statements that test for each of them each pass through the loop but wanted to get the input from you experts before running off in the wrong direction:

0002.00 Frecruitingcf   e             workstn                                                               041111        
0002.01 Frecmast   if   e           K disk    rename(recmast:recm)                                          041111        
0002.02 D                sds                                                                                041116        
0002.03 Dusrid                  254    263                                                                  041116        
0002.04 C                   DOW       *IN03 = *OFF                                                          041111        
0003.00 C                   exfmt     ssnentry                                                              041111        
0003.01 C     SSN           CHAIN     RECM                                                                  041111        
0003.02 C                   IF        %FOUND                                                                041111        
0003.06 C                   exfmt     recmaster                                                             041111        
0003.07 C                   else                                                                            041112        
0003.08 C                   exsr      newapp                                                                041112        
0003.09 C                   endif                                                                           041111        
0003.10 C                   enddo                                                                           041111        
0003.11 C                   eval      *inlr = *on                                                           041111        
0004.00 C                   return                                                                          041111        

Any help or suggestions would be appreciated.
Avatar of dpalme
dpalme

ASKER

I should note that I need to test for the F10 key within the SECOND display file, not the first.
Avatar of dpalme

ASKER

Here is the code for the newapp sub routine:

0005.00 C     newapp        begsr                                                                           041112          
0005.01 C                   eval      recruiter = usrid                                                     041116          
0006.00 C                   eval      status = 1                                                            041112          
0007.00 C                   eval      DESC = 'NEW APPLICATION'                                              041112          
0007.01 C                   eval      appdate = %date                                                       041115          
0007.02 C                   eval      dob = %date                                                           041116          
0007.04 C                   exfmt     recmaster                                                             041112          
0008.00 C                   ENDSR                                                                           041112          
You have the ability to assign a real word and meaning to the function keys and test for them in a loop in the main section of your code.  In the D specs you can give the function key your using a name that will mean more to you in your program.  Here is an example of how to do this.  

     ?*  Program Data Structure
     D@pgm            sds
     D Proc_Name         *Proc                                                  * Pgm name
     D Pgm_Status        *Status                                                * Pgm status
     D Prv_Status             16     20s 0                                      * Date (*Date fmt)
     D Line_Num               21     28                                         * Date (*Date fmt)
     D Routine           *Routine                                               * Pgm status
     D Parms             *Parms                                                 * Pgm status
     D Excp_Type              40     42                                         * Date (*Date fmt)
     D Excp_Num               43     46                                         * Date (*Date fmt)
     D Pgm_Lib                81     90                                         * Run date (Udate)
     D Excp_Data              91    170                                         * Run date (Udate)
     D Excp_Id               171    174                                         * Run date (Udate)
     D Sys_Date              191    198                                         * Date (*Date fmt)
     D Sys_Centry            199    200s 0                                      * Year (*Year fmt)
     D Last_File             201    208                                         * Year (*Year fmt)
     D File_Info             209    243                                         * Year (*Year fmt)
     D Job_Name              244    253                                         * Year (*Year fmt)
     D User                  254    263                                         * User name
     D Job_Num               264    269s 0                                      * Year (*Year fmt)
     D Job_Date              270    275s 0                                      * Year (*Year fmt)
     D Run_Date              276    281s 0                                      * Run date (Udate)
     D Run_Time              282    287s 0                                      * Run time (Udate)
     ?*
     ?*  Display File Data Structure
     D@dspf            DS
     D Dfile             *File                                                  * File name
     D Dstatus           *Status                                                * Display status
     D Dsp_Flag1             367    368                                         * Display flags
     D Dsp_Aid               369    369                                         * Aid byte
     D Cursor                370    371                                         * Cursor location
     D Data_Len              372    375B 0                                      * Actual data len
     D Sf_RRN                376    377B 0                                      * Subfile rrn
     D Min_RRN               378    379B 0                                      * Subfile min rrn
     D Num_Rcds              380    381B 0                                      * Subfile num rcds
     D Act_Curs              380    381B 0                                      * Active window
     D                                                                          *  cursor location
     D Dsp_Major             401    402                                         * Major ret code
     D Dsp_Minor             403    404                                         * Minor ret code
     ?*
     ?*  Named hexadecimal Constants
     D @f01            C                   Const(X'31')
     D @f02            C                   Const(X'32')
     D @Exit           C                   Const(X'33')
     D @f04            C                   Const(X'34')
     D @f05            C                   Const(X'35')
     D @f06            C                   Const(X'36')
     D @f07            C                   Const(X'37')
     D @f08            C                   Const(X'38')
     D @f09            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 @Pagup          C                   Const(X'F4')
     D @Pagdn          C                   Const(X'F5')
     D @Print          C                   Const(X'F6')
     D @Rcdbk          C                   Const(X'F8')
     D @Atoen          C                   Const(X'3F')
     ?*
     ?**************************************************************************
     ?* Program Mainline                                                       *
     ?**************************************************************************
     ?*
     C                   Dou       Dsp_Aid = @Exit
     ?* Process Key Requests
     C                   Select
     ?* Process Enter Key
     C                   When      Dsp_Aid = @Enter
     C                   Exsr      #Enter
     ?* Process Page Down Key
     C                   When      Dsp_Aid = @Pagdn
     C                   Exsr      #Load
     ?*
     C                   Endsl
     ?*
     C                   Exsr      #Displ
     ?*
     C                   Enddo
     ?*
     C                   Eval      *Inlr = *on              
Avatar of dpalme

ASKER

Ok,
That makes a lot more sense, but if I may ask this, since the function key I am testing for is happening within the second display file and that is only called from one of two different sub-routines, I believe I should create a DOU iwthin those specific subroutines and that is where I should test for the function key correct?

ASKER CERTIFIED SOLUTION
Avatar of odumbruce
odumbruce

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpalme

ASKER

I think I am confusing myself here and if this should be addressed as a separate question let me know and I'll be happy to do so.

the prgoram first displays DSP file 1 which prompts the user for a social, the user enters it and then the program searches the table to see if a record already exists, if not, it displays DSP file 2 and prompts the user for the entries.

this second DSP file is handled via a sub-routine, which has several function keys available, F3 to return to the previous menu and F10 which will update and write the record to the table.

However, when the user presses F3 from within the second display file it is exiting the entire program.

here is the sub-routine code for that select statement :

0005.00 C     newapp        begsr                                                                           041112    
0005.01 C                   DOU       *IN03 = *ON                                                           041117    
0005.02 C                   select                                                                          041117    
0005.03 C                   when      *IN03 = *ON                                                           041117    
0005.04 C                   eval      *IN03 = *OFF                                                          041117    
0005.05 C                   eval      *INLR = *ON                                                           041117    
0005.06 C                   return                                                                          041117    
0005.07 C                   endsl                                                                           041117    
0005.08 C                   eval      recruiter = usrid                                                     041116    
0006.00 C                   eval      status = 1                                                            041112    
0007.00 C                   eval      DESC = 'NEW APPLICATION'                                              041112    
0007.01 C                   eval      appdate = %date                                                       041115    
0007.02 C                   eval      dob = %date                                                           041116    
0007.04 C                   exfmt     recmaster                                                             041112    

What I'm telling it to do, I THINK, is that keep displaying the screen until F3 is pressed at which time turn the indicator off and then return to the calling program but that isn't happening.

Suggestions?
well first you need to have your logic changed a bit.  Only use F3 to exit use F12 to step back.  You need to disable F3 on your second display and that would be done using your dds code and how you test within your subroutine.  Once a user hits F12 you would exit the subroutine and return control back to your main processing.
Avatar of dpalme

ASKER

ok I thought I had this down, I changed the statemets so that if F12 is selected, turn IN12 off and then LEAVE the DOU loop which would then execute the return statement at the bottom of the subroutine which I thought would return control back to the main processing but it doesn't.

Here is the code as it stands now:
0005.00 C     newapp        begsr                                                                    
0005.01 C                   DOU       *IN12 = *ON                                                  
0005.02 C                   select                                                                            
0005.03 C                   when      *IN12 = *ON                                                      
0005.04 C                   eval      *IN12 = *OFF                                                    
0005.06 C                   LEAVE                                                                        
0005.07 C                   endsl                                                                        
0005.08 C                   eval      recruiter = usrid                                                  
0006.00 C                   eval      status = 1                                                        
0007.00 C                   eval      DESC = 'NEW APPLICATION'                                      
0007.01 C                   eval      appdate = %date                                                    
0007.02 C                   eval      dob = %date                                                          
0007.04 C                   exfmt     recmaster                                                            
0007.05 C                   enddo                                                                          
0007.07 C                   return                                                                          
0008.00 C                   ENDSR  

so when control is sent to the subroutine it put itself into a loop of DOU IN12 is turned on, at which time the select statement is executed which turns the indicator off and LEAVES the loop which I believe should then execute RETURN ?  
Well I dont think you need to have return in your subroutine.  Once f12 is hit you should leave your subroutine and return to the point in which you left in your mailine processing.  I for one do not like to code that way I like one program for one set of functional screens.  Keeps it cleaner.  I would make all those options a program call but that is me.  You also have to have your dds coded correctly. You can define CF keys global at the top or you can define them at the record level in your display.  
Avatar of dpalme

ASKER

Actually while you were answering I finally figured it out....I had to make several changes, one in the main body of the program I needed to add a select statement to test for the IN03 and what to do in that case....in addition I had to add something similar to the subroutine for the F12 key press.

As you said I do not know if I need to have the "RETURN" statement in there with maybe the exception of the main body program.

In any event it seems to be working now....so we move onto something else LOL

When I finish this I am thinking of pasting the code and giving up some major points for corrections, suggestions, or help in writing cleaner code.

Thanks again though for your paitence and assistance.  I am going to bump the points to 40 since you took so much extra time in helping me out.

Douglas
Avatar of Theo Kouwenhoven
Hi Douglas,

I'm very happy with your end remark ".....writing cleaner code".
But a really clean code I didn't see in the examples. Not my idea about a clean code. I think a clean code must be at the first place very readable and
flexible so that the future changes are not limited by the way the program is developed.
I work here by a customer with some other RPG programmers, and all of us have a diferent Job-history, and develope our own way of handeling
(interactive) programs, and we all came after some years with almost the same way of handling screen programs. So I think you will find the same
way as we did within some years, or if you like I can post the structure of a program here. for free no points ;-).

I'm always happy when someone tries to enter the beautifull world of the AS/400.
Just let me know and I give you a sample.

Regards,
Murph

PS. Fill in your EE Member Profile, so that we know who you are and what your experience / background  is (should be nice to know)