Application Development 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: 

How to trigger PAI on pressing enter on set_table_for_first_display table ?

Former Member
0 Kudos

I am not able to trigger the PAI event on pressing enter if i click on table cells and area of this table but when i click outside this table it is trigerring the user command of screen 0116. I have used one method egister_edit_event so it will trigger if we click outside the table block.

I have one main screen 0100 and subscreen as 0101, this 0101 is a custom container --

PBO--------.

1> Created Object for container--

CREATE OBJECT o_cont_sob

       EXPORTING

         container_name              = 'SOB_ALV'  

       EXCEPTIONS

         cntl_error                  = 1

         cntl_system_error           = 2

         create_error                = 3

         lifetime_error              = 4

         lifetime_dynpro_dynpro_link = 5

         OTHERS                      = 6.


2> Created object for GRID--


CREATE OBJECT o_grid_sob

         EXPORTING

           i_parent          = o_cont_sob

         EXCEPTIONS

           error_cntl_create = 1

           error_cntl_init   = 2

           error_cntl_link   = 3

           error_dp_create   = 4

           OTHERS            = 5.


CALL METHOD o_grid_sob->set_table_for_first_display

       EXPORTING

         it_toolbar_excluding          = pt_exclude

         is_layout                     = wa_layout

       CHANGING

         it_outtab                     = gt_sob_1

         it_fieldcatalog               = gt_fieldcat_new

       EXCEPTIONS

         invalid_parameter_combination = 1

         program_error                 = 2

         too_many_lines                = 3

         OTHERS                        = 4.


*  Registering the EDIT Event

     CALL METHOD o_grid_sob->register_edit_event

       EXPORTING

         i_event_id = cl_gui_alv_grid=>mc_evt_enter

       EXCEPTIONS

         error      = 1

         OTHERS     = 2.

     IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.                                 " IF SY-SUBRC NE 0


PAI-----


MODULE user_command_0116 INPUT.

   CALL METHOD o_grid_sob->register_edit_event

     EXPORTING

       i_event_id = cl_gui_alv_grid=>mc_evt_enter "trigger event after ENTER is pressed

     EXCEPTIONS

       error      = 1

       OTHERS     = 2.



Please suggest how to trigger it.


2 REPLIES 2

former_member184158
Active Contributor
0 Kudos

Hi,

you can this method handle data change,if the data has been changed in ALV, and you pressed enter,then this method should be called,

SET HANDLER g_event_receiver->handle_data_changed FOR o_grid_sob


try this code.

REPORT zibo_pg_test99.
DATA o_cont_sob TYPE REF TO cl_gui_custom_container.
DATA o_grid_sob TYPE REF TO cl_gui_alv_grid.
DATA gt_sob_1 TYPE TABLE OF sflight.

DATA gt_fieldcat_new TYPE lvc_t_fcat .

CLASS lcl_event_receiver DEFINITION.
 
PUBLIC SECTION.
   
METHODS:
      handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
       
IMPORTING
          er_data_changed
.



ENDCLASS.                    "lcl_event_receiver DEFINITION

CLASS lcl_event_receiver IMPLEMENTATION.
 
METHOD handle_data_changed.

   
MESSAGE 'you have pressed enter-event' TYPE 'I'.
 
ENDMETHOD.                    "handle_data_changed
ENDCLASS.

START-OF-SELECTION.
 
CALL SCREEN 100.

 
" IF SY-SUBRC NE 0






*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

 
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
   
EXPORTING
*     I_BUFFER_ACTIVE  =
      i_structure_name
= 'SFLIGHT'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
   
CHANGING
      ct_fieldcat     
= gt_fieldcat_new
*   EXCEPTIONS
*     INCONSISTENT_INTERFACE       = 1
*     PROGRAM_ERROR    = 2
*     OTHERS           = 3
   
.
 
IF sy-subrc <> 0.
* Implement suitable error handling here
 
ENDIF.
 
FIELD-SYMBOLS <ls_f> like line of gt_fieldcat_new.

READ TABLE gt_fieldcat_new ASSIGNING  <ls_f>
with key fieldname = 'FLDATE'.
 
IF  sy-subrc = 0.
    <ls_f>
-edit = abap_true.
 
ENDIF.
 
SELECT * FROM sflight INTO TABLE gt_sob_1 UP TO 10 ROWS.
 
CREATE OBJECT o_cont_sob
   
EXPORTING
      container_name             
= 'SOB_ALV'
   
EXCEPTIONS
      cntl_error                 
= 1
      cntl_system_error          
= 2
      create_error               
= 3
      lifetime_error             
= 4
      lifetime_dynpro_dynpro_link
= 5
     
OTHERS                      = 6.


 
CREATE OBJECT o_grid_sob
   
EXPORTING
      i_parent         
= o_cont_sob
   
EXCEPTIONS
      error_cntl_create
= 1
      error_cntl_init  
= 2
      error_cntl_link  
= 3
      error_dp_create  
= 4
     
OTHERS            = 5.

 
CALL METHOD o_grid_sob->set_table_for_first_display

*       EXPORTING
*     it_toolbar_excluding          = pt_exclude
*     is_layout                     = wa_layout
   
CHANGING
      it_outtab                    
= gt_sob_1
     it_fieldcatalog              
= gt_fieldcat_new
   
EXCEPTIONS
      invalid_parameter_combination
= 1
      program_error                
= 2
      too_many_lines               
= 3
     
OTHERS                        = 4.

*  Registering the EDIT Event
  o_grid_sob
->register_edit_event( cl_gui_alv_grid=>mc_evt_enter ).

 
DATA g_event_receiver TYPE REF TO lcl_event_receiver.
 
CREATE OBJECT g_event_receiver.
 
SET HANDLER g_event_receiver->handle_data_changed FOR o_grid_sob.

call method cl_gui_cfw=>set_new_ok_code
 
exporting
  new_code
= 'REFR'.


ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
 
CALL METHOD o_grid_sob->register_edit_event
   
EXPORTING
      i_event_id
= cl_gui_alv_grid=>mc_evt_enter "trigger event after ENTER is pressed
   
EXCEPTIONS
      error     
= 1
     
OTHERS     = 2.
ENDMODULE.                 " USER_COMMAND_0100  INPUT


Regards

Ebrahim

former_member184158
Active Contributor
0 Kudos

Hi

I have tried it out, and it works, the important thins is to change the data and then press enter.

Regards

Ebrahim