Archived discussions are read-only. Learn more about SAP Q&A

Event handling in alv oops With buttons

Hi Experts

I have some doubt in ALV OOPS using Events. Could any one please tell me the procedure to how to handle events in oops ( Like interactive reports using events ).

Thank you

Satyendra.

replied

Hello Satyendra

The following sample report shows you how to handle the event HOTSPOT_CLICK and BUTTON_CLICK.

DATA:  gd_okcode TYPE ui_func,
  gt_fcat TYPE lvc_t_fcat,
  go_docking TYPE REF TO cl_gui_docking_container,
  go_grid1 TYPE REF TO cl_gui_alv_grid.

DATA:   gt_knb1 TYPE STANDARD TABLE OF knb1.

PARAMETERS: p_bukrs TYPE bukrs  DEFAULT '2000'  OBLIGATORY.

CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS:
      handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
          e_row_id
          e_column_id
          es_row_no
          sender,  " grid instance that raised the event

      handle_button_click FOR EVENT button_click OF cl_gui_alv_grid
        IMPORTING
          es_col_id
          es_row_no
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION

CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_hotspot_click.
*   define local data
    DATA:
      ls_knb1     TYPE knb1,
      ls_col_id   TYPE lvc_s_col.

    READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row_id-index.
    CHECK ( ls_knb1-kunnr IS NOT INITIAL ).

    CASE e_column_id-fieldname.
      WHEN 'KUNNR'.
        SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
        SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
        CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.

      WHEN 'ERNAM'.*        
         SET PARAMETER ID 'USR' FIELD ls_knb1-ernam.
        CALL TRANSACTION 'SU01' AND SKIP FIRST SCREEN.

      WHEN OTHERS.
    ENDCASE.

*   Set active cell to field BUKRS otherwise the focus is still on
*   field KUNNR which will always raise event HOTSPOT_CLICK
    ls_col_id-fieldname = 'BUKRS'.
    CALL METHOD go_grid1->set_current_cell_via_id
      EXPORTING
        is_row_id    = e_row_id
        is_column_id = ls_col_id.

ENDMETHOD.                    "handle_hotspot_click

 METHOD handle_button_click.
*   define local data
    DATA:
      ls_knb1     TYPE knb1.

    READ TABLE gt_knb1 INTO ls_knb1 INDEX es_row_no-row_id.
    CHECK ( ls_knb1-kunnr IS NOT INITIAL ).

    SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
    SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.

    CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.

  ENDMETHOD.                    "handle_button_click

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

  SELECT        * FROM  knb1 INTO TABLE gt_knb1
         WHERE  bukrs  = p_bukrs
* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=>screen0
      ratio                       = 90
    EXCEPTIONS
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Create ALV grid
  CREATE OBJECT go_grid1
    EXPORTING
      i_parent          = go_docking
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Set event handler
  SET HANDLER:
    lcl_eventhandler=>handle_hotspot_click FOR go_grid1,
    lcl_eventhandler=>handle_button_click  FOR go_grid1.


* Build fieldcatalog and set hotspot for field KUNNR
  PERFORM build_fieldcatalog_knb1.
* Display data
  CALL METHOD go_grid1->set_table_for_first_display
    CHANGING
      it_outtab       = gt_knb1
      it_fieldcatalog = gt_fcat
    EXCEPTIONS
      OTHERS          = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Link the docking container to the target dynpro
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = syst-repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.


END-OF-SELECTION.

MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.


ENDMODULE.                 " STATUS_0100  OUTPUT

MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.
    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

FORM build_fieldcatalog_knb1 .
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'KNB1'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

 LOOP AT gt_fcat INTO ls_fcat
          WHERE ( fieldname = 'KUNNR'  OR
                  fieldname = 'ERNAM'  OR
                  fieldname = 'BUKRS' ).
    IF ( ls_fcat-fieldname = 'BUKRS' ).
      ls_fcat-style = cl_gui_alv_grid=>mc_style_button.  " column appears as button
    ELSE.
      ls_fcat-hotspot = abap_true.
    ENDIF.

    MODIFY gt_fcat FROM ls_fcat.
  ENDLOOP.
ENDFORM.                    " BUILD_FIELDCATALOG_KNB1

Regards

Uwe

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question