PDA

View Full Version : percolate F3 up to exit all interactive programs



David Abramowitz
03-05-2002, 03:27 PM
I do it the same way. This is a great question. Dave

Guest.Visitor
03-06-2002, 05:49 AM
I set up a Based common indicator data structure in all programs/procedures. The first program in the stack will create the data structure and pass the pointer for it to the called programs. Each program/procedure has a common subroutine to check for which command key was pressed. In the example below F3 (i_EndProc) will percolate to the main program/procedure from the called programs/procedures. <font courier> FEXAMPLED CF E Workstn F INDDS(I_ScrnInd) F INFDS(Ds_WorkStn) D *--------------------------------- * Entry Parameters *--------------------------------- D EXAMPLE1 PR D p_PtrCommon * const D EXAMPLE1 PI D p_PtrCommon * const *--------------------------------- * Data Structure for Display File indicators *--------------------------------- D I_ScrnInd DS D i_EndProc 03 03n D i_GoPrevious 12 12n D i_HaveError 90 90n D i_Return 99 99n *--------------------------------- * Interface between programs *--------------------------------- D Ds_CommonIndicators... D DS based(Ptr_toCommon) D px_EndProc 03 03n D px_GoPrevious 12 12n D px_HaveError 99 99n D Ds_DefineCommon... D DS 99 *--------------------------------- * Pointers used within procedure *--------------------------------- D Ptr_toCommon S * *--------------------------------- * Procedure Prototype Definition *--------------------------------- D Maintain_Account... D PR D p_PtrCommon * const D Maintain_Customer... D PR D p_PtrCommon * const C *---------- * Main - *---------- C w_WhichScreen CasEq *BLANK Sr_First C w_WhichScreen CasEq 'SCRN01' Sr_Scrn01 C endcs *--------------------------------------------------------------------- * Sr_Scrn01 - Base Parameters Selection *--------------------------------------------------------------------- C Sr_Scrn01 BegSr C exfmt SCREEN01 * Check for function key pressed by the user C select C When i_EndProc C eval px_EndProc = *ON C When i_GoPrevious C eval px_GoPrevious = *ON * Process user changes C Other C exsr Sr_Edit C If not i_HaveError C exsr Sr_Process C endIf C endsl C exsr Sr_Return C endSr *--------------------------------------------------------------------- * Sr_Return - Check for a user/process "End Procedure" or * "Return" request *--------------------------------------------------------------------- C Sr_Return BegSr C If not i_HaveError C and ( i_Return C or px_EndProc C or i_GoPrevious) C eval *INLR = px_EndProc C eval w_WhichScreen = *BLANK C return C endIf C endSr *--------------------------------------------------------------------- * Sr_Edit - Edit the Input *--------------------------------------------------------------------- C Sr_Edit BegSr C If SC_INPUT <> '1' C or SC_INPUT <> '2' C eval i_HaveError = *ON C endIf C endSr *--------------------------------------------------------------------- * Sr_Process - Process the Input *--------------------------------------------------------------------- C Sr_Process BegSr C If SC_INPUT = '1' C callp Maintain_Account C (Ptr_ToCommon) C else C callp Maintain_Customer C (Ptr_ToCommon) C endIf C endSr *--------------------------------------------------------------------- * Sr_First - Process the Set-Up for the Program *--------------------------------------------------------------------- C Sr_First BegSr C eval w_WhichScreen = 'SCRN01' C If %parms > *ZERO C eval Ptr_toCommon = p_PtrCommon C else C eval Ptr_toCommon = %addr(Ds_DefineCommon) C endIf C endSr </font> Hope this helps. Jerry Hensley

Absolutely_Nobody
03-06-2002, 07:53 AM
This looks like something i'd like to try. It provides for a standard way of checking for F3. What if one of the programs in the call stack is a CL ? Can a pointer be used in a CL ?

gcostagliola@tin.it
03-06-2002, 11:14 AM
Try using QWCRTVCA and QWCCCJOB api's

B.Morris
03-06-2002, 11:24 AM
If you just want to get directly back to the top level without doing any more in the intermediate programs, you could send an escape message back to the top level program. This would cancel all the intermediate invocations. If the invocations were RPG main procedures (i.e. not subprocedures), RPG's cancel handler would close any open files. Here's an example. Create these four programs (activation group etc doesn't matter). To see it working, first call CANCELMAIN and answer 'n' to the question. It will continue to the end of each program (this is the no-F3 case). Call it again and answer 'y' (the F3-case). It will jump immediately to the statement after the call in CANCELMAIN. * Create this program as CANCELMAIN D psds sds D status *status D msgid 40 47 C call(e) 'CANCEL2' C status dsply msgid C return /* Create this program as CANCELMSG pgm SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Pretend + F3 was pressed') TOPGMQ(*SAME (CANCELMAIN)) + MSGTYPE(*ESCAPE) endpgm * Create this program as CANCEL2 C 'cancel2' dsply C call 'CANCEL3' C 'c2: after' dsply C return * Create this program as CANCEL3 C 'cancel3' dsply C 'exit now?y/n'dsply exit 1 C if exit = 'y' C call 'CANCELMSG' C endif C 'c3: after' dsply C return

David Abramowitz
03-07-2002, 02:38 AM
An eloquent solution. Thank you. Dave

Absolutely_Nobody
03-08-2002, 05:11 AM
Barbara, This is the solution that I was looking for. However, it appears as if it requires knowing which program's message queue to send the message to. If this is the case, how do you determine that ?

B.Morris
03-08-2002, 09:01 AM
I assumed that your application would know what the top level program was. If that isn't a constant, then I think you'd have to pass around a parameter with the name.

J.Pluta
03-08-2002, 12:59 PM
Another option would be to write your own API. Call it once to set the value of the top program (this is done by the top program!). Call it a second time to cancel the program. One way is to code the API with two parameters, the first being the opcode ('S'tore or 'C'ancel), and the second being the program name. The other is to code only the program name parameter, with a special value (such as *CANCEL) used to terminate the job. By putting it in an API, you encapsulate all the inner workings and only have to code it once.

Absolutely_Nobody
03-08-2002, 12:59 PM
I know how to detect when a particular function key is pressed in an interactive program. My question is how can F3 be percolated up the call stack to exit all of the calling programs. I've always passed a field back to each called program to determine if F3 was pressed and then code the logic appropriately. Is there a better way to do this ?