Skip to Content
author's profile photo Former Member
Former Member

WHAT ARE EVENTS IN AN ALV REPORT ?

WHAT ARE EVENTS IN AN ALV REPORT ? PLEASE EXPLAIN HOW TO MAKE AN ALV REPORT AND WHAT THE EVENTS DO ?

BEST REGARDS,

RYAN

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2007 at 05:10 PM

    Events are driven by user interaction...Like...

    DATA_CHANGED
    DOUBLE_CLICK
    ONF4
    

    Here's a sample code of OO ALV using events...

    *&---------------------------------------------------------------------*
    *& Report  ZDUMMY_ATG_2
    *&
    *&---------------------------------------------------------------------*
    REPORT zdummy_atg_2.
    
    TYPES: BEGIN OF ty_scarr,
           carrid TYPE scarr-carrid,
           carrname TYPE scarr-carrname,
           currcode TYPE scarr-currcode,
           END OF ty_scarr.
    
    DATA: t_spfli TYPE STANDARD TABLE OF spfli,
          w_spfli LIKE LINE OF t_spfli,
          lt_f4 TYPE lvc_t_f4 WITH HEADER LINE,
          return_tab TYPE STANDARD TABLE OF ddshretval WITH HEADER LINE,
          t_custom_scarr TYPE STANDARD TABLE OF ty_scarr WITH HEADER LINE,
          t_stable TYPE STANDARD TABLE OF lvc_s_stbl WITH HEADER LINE.
    
    FIELD-SYMBOLS: <fs_spfli> LIKE LINE OF t_spfli,
                   <fs_scarr> LIKE LINE OF t_custom_scarr.
    
    CLASS cl_gui_object DEFINITION LOAD.
    CLASS lcl_event_receiver DEFINITION DEFERRED.
    INCLUDE <cl_alv_control>.
    
    DATA: ok_code LIKE sy-ucomm,
          gt_fieldcat TYPE lvc_t_fcat,
          gt_sort TYPE lvc_t_sort,
          event_receiver TYPE REF TO lcl_event_receiver,
          gs_layout TYPE lvc_s_layo,
          mycontainer TYPE scrfname VALUE 'CUSTOM_ALV',
          custom_container TYPE REF TO cl_gui_custom_container,
          grid1 TYPE REF TO cl_gui_alv_grid,
          gs_variant TYPE disvariant,
          x_save,
          w_error TYPE c,
          l_valid(1) TYPE c.
    
    *---------------------------------------------------------------------*
    *       CLASS LCL_EVENT_RECEIVER DEFINITION
    *---------------------------------------------------------------------*
    CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
        METHODS: handle_data_changed
          FOR EVENT data_changed OF cl_gui_alv_grid
          IMPORTING er_data_changed,
          handle_f4_help
          FOR EVENT onf4 OF cl_gui_alv_grid
          IMPORTING e_fieldname es_row_no er_event_data.
    ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION
    
    *---------------------------------------------------------------------*
    *       CLASS lcl_event_receiver IMPLEMENTATION
    *---------------------------------------------------------------------*
    CLASS lcl_event_receiver IMPLEMENTATION.
      METHOD handle_data_changed.
        PERFORM data_changed USING er_data_changed.
      ENDMETHOD.                    "HANDLE_DATA_CHANGED
      METHOD handle_f4_help.
        PERFORM handle_onf4 USING e_fieldname es_row_no.
        er_event_data->m_event_handled = 'X'.
      ENDMETHOD.                    "HANDLE_F4_HELP
    ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION
    
    *&---------------------------------------------------------------------*
    *&      START-OF-SELECTION                                             *
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.
    
      PERFORM cargar_customs.
      PERFORM cargar_datos.
      PERFORM fill_layout.
      PERFORM fill_catalog.
      PERFORM llamar_alv.
    
      CALL SCREEN 0100.
    
    *&---------------------------------------------------------------------*
    *&      Form  CARGAR_DATOS                                             *
    *&---------------------------------------------------------------------*
    FORM cargar_datos.
    
      SELECT mandt carrid connid countryfr cityfrom
             airpfrom countryto cityto airpto
             fltime deptime arrtime distance
             distid fltype period
      INTO TABLE t_spfli
      FROM spfli.
    
    ENDFORM.                    " CARGAR_DATOS
    
    *&---------------------------------------------------------------------*
    *&      Form  CARGAR_CUSTOMS                                           *
    *&---------------------------------------------------------------------*
    FORM cargar_customs.
    
      SELECT carrid carrname currcode
      INTO TABLE t_custom_scarr
      FROM scarr.
    
    ENDFORM.                    " CARGAR_DATOS
    
    *&---------------------------------------------------------------------*
    *&      Form  FILL_LAYOUT                                              *
    *&---------------------------------------------------------------------*
    FORM fill_layout.
    
      gs_layout-sel_mode = 'A'.
    
    ENDFORM.                    " FILL_LAYOUT
    
    *&---------------------------------------------------------------------*
    *&      Form  FILL_CATALOG                                             *
    *&---------------------------------------------------------------------*
    FORM fill_catalog.
    
      DATA: gs_fieldcat TYPE lvc_s_fcat.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 1.
      gs_fieldcat-fieldname = 'CARRID'.
      gs_fieldcat-reptext   = 'Compañia'.
      gs_fieldcat-tabname   = 'T_SPFLI'.
      gs_fieldcat-edit      = 'X'.
      gs_fieldcat-f4availabl = 'X'.
      gs_fieldcat-outputlen = '8'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 2.
      gs_fieldcat-fieldname = 'CONNID'.
      gs_fieldcat-reptext   = 'Conexión'.
      gs_fieldcat-tabname   = 'T_SPFLI'.
      gs_fieldcat-edit      = 'X'.
      gs_fieldcat-outputlen = '8'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 3.
      gs_fieldcat-fieldname = 'COUNTRYFR'.
      gs_fieldcat-reptext   = 'País'.
      gs_fieldcat-tabname   = 'T_SPFLI'.
      gs_fieldcat-edit      = 'X'.
      gs_fieldcat-outputlen = '4'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 4.
      gs_fieldcat-fieldname = 'CITYFROM'.
      gs_fieldcat-reptext   = 'Ciudad Salida'.
      gs_fieldcat-tabname   = 'T_SPFLI'.
      gs_fieldcat-edit      = space.
      gs_fieldcat-outputlen = '20'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 5.
      gs_fieldcat-fieldname = 'AIRPFROM'.
      gs_fieldcat-reptext   = 'Arp. Salida'.
      gs_fieldcat-tabname   = 'T_SPFLI'.
      gs_fieldcat-edit      = 'X'.
      gs_fieldcat-outputlen = '10'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 6.
      gs_fieldcat-fieldname = 'COUNTRYTO'.
      gs_fieldcat-reptext   = 'País'.
      gs_fieldcat-tabname   = 'T_SPFLI'.
      gs_fieldcat-edit      = 'X'.
      gs_fieldcat-outputlen = '4'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
      CLEAR gs_fieldcat.
      gs_fieldcat-col_pos   = 7.
      gs_fieldcat-fieldname = 'CITYTO'.
      gs_fieldcat-reptext   = 'Ciudad Llegada'.
      gs_fieldcat-tabname   = 'T_SPFLI'.
      gs_fieldcat-edit      = space.
      gs_fieldcat-outputlen = '20'.
      APPEND gs_fieldcat TO gt_fieldcat.
    
    ENDFORM.                    " FILL_CATALOG
    
    *&---------------------------------------------------------------------*
    *&      Form  LLAMAR_ALV                                               *
    *&---------------------------------------------------------------------*
    FORM llamar_alv.
    
      IF custom_container IS INITIAL.
        CREATE OBJECT custom_container
          EXPORTING
            container_name              = mycontainer
          EXCEPTIONS
            cntl_error                  = 1
            cntl_system_error           = 2
            create_error                = 3
            lifetime_error              = 4
            lifetime_dynpro_dynpro_link = 5.
      ENDIF.
    
      CREATE OBJECT grid1
        EXPORTING
          i_parent = custom_container.
    
      CREATE OBJECT event_receiver.
    
      lt_f4-fieldname = 'CARRID'.
      lt_f4-register = 'X' .
      lt_f4-getbefore = 'X' .
      lt_f4-chngeafter = 'X' .
      APPEND lt_f4.
    
      SET HANDLER event_receiver->handle_data_changed FOR grid1.
      SET HANDLER event_receiver->handle_f4_help FOR grid1.
    
      CALL METHOD grid1->register_f4_for_fields
        EXPORTING
          it_f4 = lt_f4[].
    
      IF sy-batch IS INITIAL.
        CALL METHOD grid1->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_modified.
      ENDIF.
    
      CALL METHOD grid1->set_table_for_first_display
        EXPORTING
          is_variant      = gs_variant
          i_save          = x_save
          i_default       = 'X'
          is_layout       = gs_layout
        CHANGING
          it_fieldcatalog = gt_fieldcat
          it_sort         = gt_sort[]
          it_outtab       = t_spfli[].
    
      CALL METHOD grid1->set_ready_for_input
        EXPORTING
          i_ready_for_input = 1.
    
    ENDFORM.                    " LLAMAR_ALV
    
    *&---------------------------------------------------------------------*
    *&      Form  HANDLE_ONF4                                              *
    *&---------------------------------------------------------------------*
    FORM handle_onf4 USING p_e_fieldname
                           p_es_row_no STRUCTURE lvc_s_roid.
    
      CASE p_e_fieldname.
        WHEN 'CARRID'.
          CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
            EXPORTING
              retfield        = 'CARRID'
              value_org       = 'S'
            TABLES
              value_tab       = t_custom_scarr
              return_tab      = return_tab
            EXCEPTIONS
              parameter_error = 1
              no_values_found = 2
              OTHERS          = 3.
    
          IF NOT return_tab[] IS INITIAL.
            READ TABLE return_tab INDEX 1.
            READ TABLE t_spfli INDEX p_es_row_no-row_id
            ASSIGNING <fs_spfli>.
            <fs_spfli>-carrid = return_tab-fieldval.
            CALL METHOD grid1->refresh_table_display
              EXPORTING
                is_stable = t_stable.
          ENDIF.
    
      ENDCASE.
    
    ENDFORM.                    " HANDLE_ONF4
    
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT                                    *
    *&---------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'MAIN_STATUS'.
    *  SET TITLEBAR 'xxx'.
    
    ENDMODULE.                 " STATUS_0100  OUTPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT                               *
    *&---------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
    
      ok_code = sy-ucomm.
    
      CASE ok_code.
        WHEN 'BACK' OR 'STOP' OR 'CANCEL'.
          SET SCREEN 0.
          LEAVE SCREEN.
        WHEN 'SAVE'.
          CALL METHOD grid1->check_changed_data
            IMPORTING
              e_valid = l_valid.
          IF l_valid EQ 'X'.
            PERFORM grabar_datos.
          ENDIF.
      ENDCASE.
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    
    *&---------------------------------------------------------------------*
    *&      Form  DATA_CHANGED                                             *
    *&---------------------------------------------------------------------*
    FORM data_changed USING rr_data_changed TYPE REF TO
                                            cl_alv_changed_data_protocol.
    
      DATA: w_new,
            ls_mod_cells TYPE lvc_s_modi,
            ls_cells TYPE lvc_s_modi.
    
      DATA: l_carrid TYPE spfli-carrid.
    
      CLEAR l_carrid.
    
      LOOP AT rr_data_changed->mt_good_cells INTO ls_mod_cells.
    
        CASE ls_mod_cells-fieldname.
          WHEN 'CARRID'.
            CALL METHOD rr_data_changed->get_cell_value
              EXPORTING
                i_row_id    = ls_mod_cells-row_id
                i_fieldname = ls_mod_cells-fieldname
              IMPORTING
                e_value     = l_carrid.
            IF l_carrid IS INITIAL.
              CALL METHOD rr_data_changed->add_protocol_entry
                EXPORTING
                  i_msgid     = '0K'
                  i_msgno     = '000'
                  i_msgty     = 'E'
                  i_msgv1     = 'Seleccione algún código'
                  i_fieldname = ls_mod_cells-fieldname
                  i_row_id    = ls_mod_cells-row_id.
              w_error = 'X'.
            ELSE.
              READ TABLE t_custom_scarr WITH KEY carrid = l_carrid
              ASSIGNING <fs_scarr>.
              IF sy-subrc NE 0.
                CALL METHOD rr_data_changed->add_protocol_entry
                  EXPORTING
                    i_msgid     = '0K'
                    i_msgno     = '000'
                    i_msgty     = 'E'
                    i_msgv1     = 'Código ingresado no existe'
                    i_fieldname = ls_mod_cells-fieldname
                    i_row_id    = ls_mod_cells-row_id.
                w_error = 'X'.
              ENDIF.
            ENDIF.
        ENDCASE.
    
      ENDLOOP.
    
    ENDFORM.                    " DATA_CHANGED
    
    *&---------------------------------------------------------------------*
    *&      Form  GRABAR_DATOS                                             *
    *&---------------------------------------------------------------------*
    FORM grabar_datos.
    
      LOOP AT t_spfli ASSIGNING <fs_spfli>.
        w_spfli = <fs_spfli>.
        MODIFY spfli FROM w_spfli.
        IF sy-subrc EQ 0.
          COMMIT WORK.
        ELSE.
          ROLLBACK WORK.
        ENDIF.
      ENDLOOP.
    
    ENDFORM.                    " GRABAR_DATOS
    

    Greetings,

    Blag.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2007 at 06:06 PM

    Hi,

    USER_COMMAND

    TOP_OF_PAGE

    END_OF_PAGE

    TOP_OF_LIST

    END_OF_LIST

    for more details ..check this link..

    http://www.sap-basis-abap.com/abap/events-in-alv-and-their-fm.htm

    Regards

    KK

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.