Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Trigger PAI

aakash_neelaperumal2
Active Participant
0 Likes
3,477

Normally in module pool programming PAI is triggered when we press a button or do some action in the screen. But my requirement is to trigger PAI automatically after PBO is complete(after the data is shown in the screen). Is there any function module to trigger PAI in the code.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
2,172

Do you want to automatically fire the PAI at some time interval, see this example.



REPORT  zrich_0001.

*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer.

ENDCLASS.                    "lcl_event_handler DEFINITION

DATA: gui_timer TYPE REF TO cl_gui_timer.
DATA: timeout TYPE i VALUE '3'.

PARAMETERS: p_datum TYPE sy-datum,
            p_uzeit TYPE sy-uzeit.

AT SELECTION-SCREEN OUTPUT.

  CREATE OBJECT gui_timer.

  SET HANDLER lcl_event_handler=>on_finished FOR gui_timer.

  gui_timer->interval = timeout.
  CALL METHOD gui_timer->run.

AT SELECTION-SCREEN.

  CASE sy-ucomm.
    WHEN 'REFR'.
* Do What ever
        p_datum = sy-datum.
        p_uzeit = sy-uzeit.

  ENDCASE.



*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_finished.

* Start Timer again
    gui_timer->interval = timeout.
    CALL METHOD gui_timer->run.

* cause PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFR'.

  ENDMETHOD.                    "on_finished

ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

The implementatino is pretty much the same for a dynpro as well.

Regards,

Rich Heilman

8 REPLIES 8
Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
2,172

Hi,

I think you can try use the Method "set_new_ok_code":



  CALL METHOD cl_gui_cfw=>set_new_ok_code
    EXPORTING
      new_code = '<Your New OKCODE>'.
 

Regards.

Marcelo Ramos

Read only

alejandro_bindi
Active Contributor
0 Likes
2,172

You can use this class method:


    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'XXXX'.

Problem is, after PAI, PBO automatically triggers, so you'll probably enter an endless loop (i'm not able to try out now). You should only trigger PAI automatically based on some condition that will change sometime, recheck your requirement.

Regards

Please reward points if helpful.

Message was edited by:

Alejandro Bindi

Read only

0 Likes
2,172

No this is not happening for module pool programming. PAI is not triggered...

Read only

0 Likes
2,172

What I mean is:

Normal module behaviour is:

PBO > [user action] > PAI > PBO > [user action] > PAI > PBO > [user action] > PAI ....

You intend to replace [user action] with an automatic triggering (using the method we suggested). So, taking [user action] out of the way:

PAI > PBO > PAI > PBO > PAI > PBO > PAI > PBO....

You will loose interaction which is the dialog program main purpose. To avoid that, you should call the method based on some condition which is not always true.

Hope you get it.

Regards

Read only

0 Likes
2,172

The automatic trigger of PAI will happen only after some regular time interval. So there wont be a problem in stopping the flow.

Read only

0 Likes
2,172

That's it, no problem then.

Regards

Read only

RichHeilman
Developer Advocate
Developer Advocate
2,173

Do you want to automatically fire the PAI at some time interval, see this example.



REPORT  zrich_0001.

*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer.

ENDCLASS.                    "lcl_event_handler DEFINITION

DATA: gui_timer TYPE REF TO cl_gui_timer.
DATA: timeout TYPE i VALUE '3'.

PARAMETERS: p_datum TYPE sy-datum,
            p_uzeit TYPE sy-uzeit.

AT SELECTION-SCREEN OUTPUT.

  CREATE OBJECT gui_timer.

  SET HANDLER lcl_event_handler=>on_finished FOR gui_timer.

  gui_timer->interval = timeout.
  CALL METHOD gui_timer->run.

AT SELECTION-SCREEN.

  CASE sy-ucomm.
    WHEN 'REFR'.
* Do What ever
        p_datum = sy-datum.
        p_uzeit = sy-uzeit.

  ENDCASE.



*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_finished.

* Start Timer again
    gui_timer->interval = timeout.
    CALL METHOD gui_timer->run.

* cause PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFR'.

  ENDMETHOD.                    "on_finished

ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

The implementatino is pretty much the same for a dynpro as well.

Regards,

Rich Heilman

Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
2,172

Hi,

You can use the program <b>DEMO_CUSTOM_CONTROL</b> as example.

<b>Don't forget to close this Thread and reward points when your question be answered.</b>

Regards.

Marcelo Ramos