Trigger ALV Event


Event Class: CL_SALV_EVENTS_TABLE

Following steps are important for ALV event to trigger.

  1. Create  a method for ALV Event to start for instance method double click is used.
  2. Defind double click method for double click event of class cl_salv_events_table, also we need to mention the method which will be called at time of double click i.e detail method.        CLASS-METHODShandle_double_click        FOR EVENT double_click                   OF cl_salv_events_table        IMPORTING row column,        detail            IMPORTING matnr TYPE matnr. 
     
  3. Register event handler method for the events of alv SET HANDLER handle_double_click FOR events.
  4. also defind and impliment detail method.

 Following sample code demonstrates ALV event.
 
  REPORT yua_alv_event.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    TYPESBEGIN OF ty_data,
             banfn TYPE  banfn,
             matnr TYPE  matnr,
           END OF ty_data.
    CLASS-DATA  t_data TYPE TABLE OF ty_data.
    CLASS-METHODShandle_double_click
      FOR EVENT double_click
                  OF cl_salv_events_table
      IMPORTING row column,
      detail
        IMPORTING matnr TYPE matnr.

ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

    SELECT  banfn matnr
           FROM eban
           INTO TABLE t_data.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table DATA(alv)
          CHANGING  t_table t_data ).

        DATA(eventsalv->get_event).
        SET HANDLER handle_double_click FOR events.

        alv->display).
      CATCH cx_salv_msg.
        MESSAGE 'ALV display not possible' TYPE 'I'
                DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

  METHOD detail.
    TYPESBEGIN OF alv_line,
             matnr   TYPE matnr,
             maktx   TYPE maktx,
           END OF alv_line.
    DATA   alv_tab    TYPE TABLE OF alv_line.
    SELECT matnr maktx
           FROM MAKT
           WHERE  matnr @matnr
           INTO CORRESPONDING FIELDS OF TABLE @alv_tab.
    IF sy-subrc <> 0.
      MESSAGE e007(sabapdemos).
    ENDIF.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table DATA(alv)
          CHANGING  t_table alv_tab ).
        alv->set_screen_popupstart_column 1
                               end_column   60
                               start_line   1
                               end_line     12 ).
        alv->display).
      CATCH cx_salv_msg.
        MESSAGE 'ALV display not possible' TYPE 'I'
                DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

  METHOD handle_double_click.
    READ TABLE t_data INDEX row ASSIGNING FIELD-SYMBOL(<s_data>).
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.
    IF column 'MATNR'.
      demo=>detail<s_data>-matnr ).
    ENDIF.

  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  demo=>main).

 Below is the output of above ABAP code.




    

No comments:

Post a Comment

Code Inspector

The Code Inspector tests single objects or object sets (programs, function groups, classes, interfaces, Dictionary objects) for performanc...