Difference between revisions of "SAP ABAP ALV CL GUI ALV GRID"

From SapWiki
 
(4 intermediate revisions by the same user not shown)
Line 54: Line 54:
  
 
===Y_TEST_ALV_GRID_TOP===
 
===Y_TEST_ALV_GRID_TOP===
  <nowiki>* Y_TEST_ALV_GRID_TOP
+
<nowiki>* Y_TEST_ALV_GRID_TOP
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
DATA: ok_code            LIKE sy-ucomm,
+
DATA: ok_code            LIKE sy-ucomm,
      save_ok            LIKE sy-ucomm,
+
      save_ok            LIKE sy-ucomm,
      g_container        TYPE scrfname VALUE 'CC_ALV',
+
      g_container        TYPE scrfname VALUE 'CC_ALV',
      g_grid            TYPE REF TO cl_gui_alv_grid,
+
      g_grid            TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
+
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gt_fieldcat        TYPE lvc_t_fcat,
+
      gt_fieldcat        TYPE lvc_t_fcat,
      gs_layout          TYPE lvc_s_layo,
+
      gs_layout          TYPE lvc_s_layo,
      gt_events TYPE slis_t_event.
+
      gt_events TYPE slis_t_event.
 
DATA : g_variant1 TYPE disvariant,
 
        g_variant2 TYPE disvariant.
 
 
INCLUDE <icon>.
 
CLASS lcl_event_receiver DEFINITION DEFERRED.
 
DATA: g_event_receiver TYPE REF TO lcl_event_receiver.
 
 
*----------------------------------------------------------------------*
 
*      CLASS lcl_event_receiver DEFINITION
 
*----------------------------------------------------------------------*
 
*
 
*----------------------------------------------------------------------*
 
CLASS lcl_event_receiver DEFINITION.
 
  PUBLIC SECTION.
 
    METHODS:
 
      handle_toolbar
 
                    FOR EVENT toolbar OF cl_gui_alv_grid
 
        IMPORTING e_object e_interactive,
 
 
      handle_user_command
 
                    FOR EVENT user_command OF cl_gui_alv_grid
 
        IMPORTING e_ucomm.
 
 
    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
 
*----------------------------------------------------------------------*
 
*  agregar botones a CONTAINER
 
*----------------------------------------------------------------------*
 
CLASS lcl_event_receiver IMPLEMENTATION.
 
 
  METHOD handle_toolbar.
 
    DATA: ls_toolbar  TYPE stb_button.
 
* append a separator to normal toolbar
 
    CLEAR ls_toolbar.
 
    MOVE 3 TO ls_toolbar-butn_type.
 
    APPEND ls_toolbar TO e_object->mt_toolbar.
 
* append an icon to show booking table
 
 
*--------------------------------------------------------------------*
 
* se habilita botón Aprobar
 
*--------------------------------------------------------------------*
 
    CLEAR ls_toolbar.
 
    MOVE 'APRO' TO ls_toolbar-function.
 
    MOVE icon_execute_object TO ls_toolbar-icon.
 
    MOVE 'Aprobar' TO ls_toolbar-quickinfo.
 
    MOVE 'Aprobar' TO ls_toolbar-text.
 
    MOVE ' ' TO ls_toolbar-disabled.
 
    APPEND ls_toolbar TO e_object->mt_toolbar.
 
  
  ENDMETHOD.
+
DATA : g_variant1 TYPE disvariant,
*--------------------------------------------------------------------*
+
      g_variant2 TYPE disvariant.
  METHOD handle_user_command.
+
 
*--------------------------------------------------------------------*
+
INCLUDE <icon>.
    PERFORM user_command USING e_ucomm.
+
CLASS lcl_event_receiver DEFINITION DEFERRED.
  ENDMETHOD.
+
DATA: g_event_receiver TYPE REF TO lcl_event_receiver.
+
 
*--------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
  METHOD handle_data_changed.
+
*      CLASS lcl_event_receiver DEFINITION
*--------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
    DATA : ls_mod_cell TYPE lvc_s_modi,
+
*
            lv_value    TYPE lvc_value,
+
*----------------------------------------------------------------------*
            lv_mask1    TYPE string,
+
CLASS lcl_event_receiver DEFINITION.
            lv_mask2    TYPE string.
+
  PUBLIC SECTION.
+
    METHODS:
    DATA: l_nachn TYPE pa0002-nachn,
+
      handle_toolbar
          l_vorna TYPE pa0002-vorna,
+
                    FOR EVENT toolbar OF cl_gui_alv_grid
          l_name2 TYPE p0002-name2.
+
        IMPORTING e_object e_interactive,
    DATA l_subrc TYPE sy-subrc.
+
 
    data l_dummy(200).
+
      handle_user_command
+
                    FOR EVENT user_command OF cl_gui_alv_grid
    DATA: lv_valor TYPE string.
+
        IMPORTING e_ucomm.
    DATA: lv_mod TYPE i.
+
 
+
    METHODS:
    SORT er_data_changed->mt_mod_cells BY row_id .
+
      handle_data_changed
+
                    FOR EVENT data_changed OF cl_gui_alv_grid
    LOOP AT er_data_changed->mt_good_cells INTO ls_mod_cell.
+
        IMPORTING er_data_changed.
      IF ls_mod_cell-fieldname = 'VORNA'.
+
 
+
ENDCLASS.                    "lcl_event_receiver DEFINITION
        CALL METHOD er_data_changed->get_cell_value
+
 
          EXPORTING
+
*----------------------------------------------------------------------*
            i_row_id    = ls_mod_cell-row_id
+
*      CLASS lcl_event_receiver IMPLEMENTATION
            i_fieldname = 'VORNA'
+
*----------------------------------------------------------------------*
          IMPORTING
+
*  agregar botones a CONTAINER
            e_value    = l_vorna.
+
*----------------------------------------------------------------------*
+
CLASS lcl_event_receiver IMPLEMENTATION.
        READ TABLE gt_data_ori INTO wa_data INDEX ls_mod_cell-row_id.
+
 
        IF wa_data-vorna <> l_vorna.
+
  METHOD handle_toolbar.
            if l_vorna = 'Homero'.
+
    DATA: ls_toolbar  TYPE stb_button.
              l_subrc = 1.
+
* append a separator to normal toolbar
              MESSAGE e000(0k) with 'No se permiten Homeros' into l_dummy.
+
    CLEAR ls_toolbar.
            endif.
+
    MOVE 3 TO ls_toolbar-butn_type.
        ELSE.
+
    APPEND ls_toolbar TO e_object->mt_toolbar.
          l_subrc = 0.
+
* append an icon to show booking table
        ENDIF.
+
 
+
*--------------------------------------------------------------------*
        IF l_subrc <> 0.
+
* se habilita botón Aprobar
          DATA(error_in_data) = 'X'.
+
*--------------------------------------------------------------------*
          CALL METHOD er_data_changed->add_protocol_entry
+
    CLEAR ls_toolbar.
            EXPORTING
+
    MOVE 'APRO' TO ls_toolbar-function.
              i_msgid    = sy-msgid
+
    MOVE icon_execute_object TO ls_toolbar-icon.
              i_msgno    = sy-msgno
+
    MOVE 'Aprobar' TO ls_toolbar-quickinfo.
              i_msgty    = sy-msgty
+
    MOVE 'Aprobar' TO ls_toolbar-text.
              i_msgv1    = sy-msgv1
+
    MOVE ' ' TO ls_toolbar-disabled.
              i_msgv2    = sy-msgv2
+
    APPEND ls_toolbar TO e_object->mt_toolbar.
              i_msgv3    = sy-msgv3
+
 
              i_msgv4    = sy-msgv4
+
  ENDMETHOD.
              i_fieldname = ls_mod_cell-fieldname
+
*--------------------------------------------------------------------*
              i_row_id    = ls_mod_cell-row_id.
+
  METHOD handle_user_command.
+
*--------------------------------------------------------------------*
          CALL METHOD er_data_changed->modify_cell
+
    PERFORM user_command USING e_ucomm.
            EXPORTING
+
  ENDMETHOD.
              i_row_id    = ls_mod_cell-row_id
+
 
              i_fieldname = 'VORNA'
+
*--------------------------------------------------------------------*
              i_value    = wa_data-vorna.
+
  METHOD handle_data_changed.
          CONTINUE.
+
*--------------------------------------------------------------------*
+
    DATA : ls_mod_cell TYPE lvc_s_modi,
        ENDIF.
+
          lv_value    TYPE lvc_value,
      ENDIF.
+
          lv_mask1    TYPE string,
    ENDLOOP.
+
          lv_mask2    TYPE string.
+
 
    CALL METHOD g_grid->refresh_table_display.
+
    DATA: l_nachn TYPE pa0002-nachn,
+
          l_vorna TYPE pa0002-vorna,
    IF error_in_data EQ 'X'.
+
          l_name2 TYPE p0002-name2.
      CALL METHOD er_data_changed->display_protocol.
+
    DATA l_subrc TYPE sy-subrc.
    ENDIF.
+
    data l_dummy(200).
  ENDMETHOD.
+
 
+
    DATA: lv_valor TYPE string.
ENDCLASS.</nowiki>
+
    DATA: lv_mod TYPE i.
 +
 
 +
    SORT er_data_changed->mt_mod_cells BY row_id .
 +
 
 +
    LOOP AT er_data_changed->mt_good_cells INTO ls_mod_cell.
 +
      IF ls_mod_cell-fieldname = 'VORNA'.
 +
 
 +
        CALL METHOD er_data_changed->get_cell_value
 +
          EXPORTING
 +
            i_row_id    = ls_mod_cell-row_id
 +
            i_fieldname = 'VORNA'
 +
          IMPORTING
 +
            e_value    = l_vorna.
 +
 
 +
        READ TABLE gt_data_ori INTO wa_data INDEX ls_mod_cell-row_id.
 +
        IF wa_data-vorna <> l_vorna.
 +
            if l_vorna = 'Homero'.
 +
              l_subrc = 1.
 +
              MESSAGE e000(0k) with 'No se permiten Homeros' into l_dummy.
 +
            endif.
 +
        ELSE.
 +
          l_subrc = 0.
 +
        ENDIF.
 +
 
 +
        IF l_subrc <> 0.
 +
          DATA(error_in_data) = 'X'.
 +
          CALL METHOD er_data_changed->add_protocol_entry
 +
            EXPORTING
 +
              i_msgid    = sy-msgid
 +
              i_msgno    = sy-msgno
 +
              i_msgty    = sy-msgty
 +
              i_msgv1    = sy-msgv1
 +
              i_msgv2    = sy-msgv2
 +
              i_msgv3    = sy-msgv3
 +
              i_msgv4    = sy-msgv4
 +
              i_fieldname = ls_mod_cell-fieldname
 +
              i_row_id    = ls_mod_cell-row_id.
 +
 
 +
          CALL METHOD er_data_changed->modify_cell
 +
            EXPORTING
 +
              i_row_id    = ls_mod_cell-row_id
 +
              i_fieldname = 'VORNA'
 +
              i_value    = wa_data-vorna.
 +
          CONTINUE.
 +
 
 +
        ENDIF.
 +
      ENDIF.
 +
    ENDLOOP.
 +
 
 +
    CALL METHOD g_grid->refresh_table_display.
 +
 
 +
    IF error_in_data EQ 'X'.
 +
      CALL METHOD er_data_changed->display_protocol.
 +
    ENDIF.
 +
  ENDMETHOD.
 +
 
 +
ENDCLASS.</nowiki>
  
 
===Y_TEST_ALV_GRID_F01===
 
===Y_TEST_ALV_GRID_F01===
  <nowiki> *----------------------------------------------------------------------*
+
  <nowiki>*----------------------------------------------------------------------*
***Y_TEST_ALV_GRID_F01
+
***Y_TEST_ALV_GRID_F01
*----------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
FORM fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
+
FORM fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
  DATA lt_fcat_save TYPE lvc_t_fcat.
+
  DATA lt_fcat_save TYPE lvc_t_fcat.
+
 
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
+
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
+
    EXPORTING
      i_structure_name      = 'PA0002'
+
      i_structure_name      = 'PA0002'
      i_client_never_display = 'X'
+
      i_client_never_display = 'X'
    CHANGING
+
    CHANGING
      ct_fieldcat            = lt_fcat_save
+
      ct_fieldcat            = lt_fcat_save
    EXCEPTIONS
+
    EXCEPTIONS
      inconsistent_interface = 1
+
      inconsistent_interface = 1
      program_error          = 2
+
      program_error          = 2
      OTHERS                = 3.
+
      OTHERS                = 3.
  IF sy-subrc <> 0.
+
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
+
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
+
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
+
  ENDIF.
 
* colums names
 
*  LOOP AT lt_fcat_save ASSIGNING FIELD-SYMBOL(<wa>).
 
*    CASE <wa>-fieldname.
 
*      WHEN 'ICON'.
 
*        <wa>-scrtext_l = 'Estatus'.
 
*        <wa>-scrtext_m = 'Estatus'.
 
*        <wa>-scrtext_s = <wa>-reptext = 'Estatus'.
 
*  endloop.
 
 
* hide, solo se desplegan columnas PERNR, VORNA, NACHN & NAME2
 
  LOOP AT lt_fcat_save ASSIGNING FIELD-SYMBOL(<wa>) WHERE fieldname <> 'PERNR'
 
                                        AND fieldname <> 'VORNA'
 
                                        AND fieldname <> 'NACHN'
 
                                        AND fieldname <> 'NAME2'.
 
    <wa>-tech = 'X'.
 
  ENDLOOP.
 
  
* enable VORNA para editar
+
* colums names
  READ TABLE lt_fcat_save ASSIGNING <wa> WITH KEY fieldname = 'VORNA'.
+
*  LOOP AT lt_fcat_save ASSIGNING FIELD-SYMBOL(<wa>).
   <wa>-edit = 'X'.
+
*   CASE <wa>-fieldname.
+
*      WHEN 'ICON'.
  pt_fieldcat[] = lt_fcat_save[].
+
*        <wa>-scrtext_l = 'Estatus'.
+
*        <wa>-scrtext_m = 'Estatus'.
ENDFORM.
+
*       <wa>-scrtext_s = <wa>-reptext = 'Estatus'.
*----------------------------------------------------------------------*
+
*  endloop.
*      FORM style
+
 
*----------------------------------------------------------------------*
+
* hide, solo se desplegan columnas PERNR, VORNA, NACHN & NAME2
* Habilita/Des-Habilita edición de columna VORNA
+
  LOOP AT lt_fcat_save ASSIGNING FIELD-SYMBOL(<wa>) WHERE fieldname <> 'PERNR'
*----------------------------------------------------------------------*
+
                                        AND fieldname <> 'VORNA'
-->  p1        text
+
                                        AND fieldname <> 'NACHN'
*  <--  p2        text
+
                                        AND fieldname <> 'NAME2'.
*----------------------------------------------------------------------*
+
    <wa>-tech = 'X'.
FORM style CHANGING p_edit.
+
  ENDLOOP.
  DATA: ls_celltab TYPE lvc_s_styl.
+
 
  DATA: lt_celltab TYPE lvc_t_styl.
+
* enable VORNA para editar
  DATA l_tabix TYPE sy-tabix.
+
  READ TABLE lt_fcat_save ASSIGNING <wa> WITH KEY fieldname = 'VORNA'.
+
  <wa>-edit = 'X'.
  LOOP AT gt_data INTO wa_data.
+
 
    l_tabix = sy-tabix.
+
  pt_fieldcat[] = lt_fcat_save[].
    CLEAR lt_celltab[].
+
 
    CLEAR wa_data-celltab[].
+
ENDFORM.
+
*----------------------------------------------------------------------*
    IF p_edit = 'X'.
+
*      FORM style
    ELSE.
+
*----------------------------------------------------------------------*
      ls_celltab-fieldname = 'VORNA'.
+
* Habilita/Des-Habilita edición de columna VORNA
      ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
+
*----------------------------------------------------------------------*
      INSERT ls_celltab INTO TABLE lt_celltab.
+
*  -->  p1        text
    ENDIF.
+
*  <--  p2        text
+
*----------------------------------------------------------------------*
    INSERT LINES OF lt_celltab INTO TABLE wa_data-celltab.
+
FORM style CHANGING p_edit.
    MODIFY gt_data FROM wa_data INDEX l_tabix.
+
  DATA: ls_celltab TYPE lvc_s_styl.
  ENDLOOP.
+
  DATA: lt_celltab TYPE lvc_t_styl.
+
  DATA l_tabix TYPE sy-tabix.
  IF p_edit = 'X'.
+
 
    p_edit = space.
+
  LOOP AT gt_data INTO wa_data.
  ELSE.
+
    l_tabix = sy-tabix.
    p_edit = 'X'.
+
    CLEAR lt_celltab[].
  ENDIF.
+
    CLEAR wa_data-celltab[].
+
 
ENDFORM.
+
    IF p_edit = 'X'.
+
    ELSE.
*&---------------------------------------------------------------------*
+
      ls_celltab-fieldname = 'VORNA'.
*&      Form  CREATE_AND_INIT_ALV
+
      ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
*&---------------------------------------------------------------------*
+
      INSERT ls_celltab INTO TABLE lt_celltab.
*      text
+
    ENDIF.
*----------------------------------------------------------------------*
+
 
*      <--P_GT_DATA[]  text
+
    INSERT LINES OF lt_celltab INTO TABLE wa_data-celltab.
*      <--P_GT_FIELDCAT  text
+
    MODIFY gt_data FROM wa_data INDEX l_tabix.
*----------------------------------------------------------------------*
+
  ENDLOOP.
+
 
FORM create_and_init_alv CHANGING pt_outtab TYPE STANDARD TABLE
+
  IF p_edit = 'X'.
                                  pt_fieldcat TYPE lvc_t_fcat.
+
    p_edit = space.
+
  ELSE.
  DATA: lt_exclude TYPE ui_functions.
+
    p_edit = 'X'.
  DATA: ps_layout TYPE lvc_s_layo.
+
  ENDIF.
+
 
  CREATE OBJECT g_custom_container
+
ENDFORM.
    EXPORTING
+
 
      container_name = g_container.
+
*&---------------------------------------------------------------------*
  CREATE OBJECT g_grid
+
*&      Form  CREATE_AND_INIT_ALV
    EXPORTING
+
*&---------------------------------------------------------------------*
      i_parent = g_custom_container.
+
*      text
+
*----------------------------------------------------------------------*
  PERFORM fieldcat CHANGING pt_fieldcat.
+
*      <--P_GT_DATA[]  text
+
*      <--P_GT_FIELDCAT  text
  PERFORM exclude_tb_functions CHANGING lt_exclude.
+
*----------------------------------------------------------------------*
+
 
  ps_layout-zebra = 'X'.
+
FORM create_and_init_alv CHANGING pt_outtab TYPE STANDARD TABLE
  ps_layout-cwidth_opt = 'X'.
+
                                  pt_fieldcat TYPE lvc_t_fcat.
  ps_layout-stylefname = 'CELLTAB'.
+
 
+
  DATA: lt_exclude TYPE ui_functions.
  g_variant1-report = sy-repid.
+
  DATA: ps_layout TYPE lvc_s_layo.
  g_variant1-handle = 'X'.
+
 
  g_variant1-username = sy-uname.
+
  CREATE OBJECT g_custom_container
+
    EXPORTING
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
+
      container_name = g_container.
    EXPORTING
+
  CREATE OBJECT g_grid
      i_save        = 'A'
+
    EXPORTING
    CHANGING
+
      i_parent = g_custom_container.
      cs_variant    = g_variant1
+
 
    EXCEPTIONS
+
  PERFORM fieldcat CHANGING pt_fieldcat.
      wrong_input  = 1
+
 
      not_found    = 2
+
  PERFORM exclude_tb_functions CHANGING lt_exclude.
      program_error = 3
+
 
      OTHERS        = 4.
+
  ps_layout-zebra = 'X'.
+
  ps_layout-cwidth_opt = 'X'.
  CALL METHOD g_grid->set_table_for_first_display
+
  ps_layout-stylefname = 'CELLTAB'.
    EXPORTING
+
 
      i_save              = 'A'
+
  g_variant1-report = sy-repid.
      is_variant          = g_variant1
+
  g_variant1-handle = 'X'.
      is_layout            = ps_layout
+
  g_variant1-username = sy-uname.
      it_toolbar_excluding = lt_exclude
+
 
    CHANGING
+
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
      it_fieldcatalog      = pt_fieldcat
+
    EXPORTING
      it_outtab            = pt_outtab[].
+
      i_save        = 'A'
+
    CHANGING
  CALL METHOD g_grid->set_ready_for_input
+
      cs_variant    = g_variant1
    EXPORTING
+
    EXCEPTIONS
      i_ready_for_input = 1.
+
      wrong_input  = 1
+
      not_found    = 2
  CALL METHOD g_grid->register_edit_event
+
      program_error = 3
    EXPORTING
+
      OTHERS        = 4.
      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
+
 
+
  CALL METHOD g_grid->set_table_for_first_display
*  CALL METHOD g_grid->save_variant.
+
    EXPORTING
+
      i_save              = 'A'
  CREATE OBJECT g_event_receiver.
+
      is_variant          = g_variant1
  SET HANDLER g_event_receiver->handle_user_command FOR g_grid.
+
      is_layout            = ps_layout
  SET HANDLER g_event_receiver->handle_toolbar FOR g_grid.
+
      it_toolbar_excluding = lt_exclude
  SET HANDLER g_event_receiver->handle_data_changed FOR g_grid.
+
    CHANGING
  CALL METHOD g_grid->set_toolbar_interactive.
+
      it_fieldcatalog      = pt_fieldcat
+
      it_outtab            = pt_outtab[].
+
 
ENDFORM.                    " CREATE_AND_INIT_ALV
+
  CALL METHOD g_grid->set_ready_for_input
+
    EXPORTING
*&---------------------------------------------------------------------*
+
      i_ready_for_input = 1.
*&      Form  EXCLUDE_TB_FUNCTIONS
+
 
*&---------------------------------------------------------------------*
+
  CALL METHOD g_grid->register_edit_event
*      text
+
    EXPORTING
*----------------------------------------------------------------------*
+
      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
*      -->PT_EXCLUDE text
+
 
*----------------------------------------------------------------------*
+
*  CALL METHOD g_grid->save_variant.
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
+
 
  DATA ls_exclude TYPE ui_func.
+
  CREATE OBJECT g_event_receiver.
+
  SET HANDLER g_event_receiver->handle_user_command FOR g_grid.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
+
  SET HANDLER g_event_receiver->handle_toolbar FOR g_grid.
  APPEND ls_exclude TO pt_exclude.
+
  SET HANDLER g_event_receiver->handle_data_changed FOR g_grid.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
+
  CALL METHOD g_grid->set_toolbar_interactive.
  APPEND ls_exclude TO pt_exclude.
+
 
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
+
 
  APPEND ls_exclude TO pt_exclude.
+
ENDFORM.                    " CREATE_AND_INIT_ALV
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
+
 
  APPEND ls_exclude TO pt_exclude.
+
*&---------------------------------------------------------------------*
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
+
*&      Form  EXCLUDE_TB_FUNCTIONS
  APPEND ls_exclude TO pt_exclude.
+
*&---------------------------------------------------------------------*
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
+
*      text
  APPEND ls_exclude TO pt_exclude.
+
*----------------------------------------------------------------------*
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
+
*      -->PT_EXCLUDE text
  APPEND ls_exclude TO pt_exclude.
+
*----------------------------------------------------------------------*
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
+
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
  APPEND ls_exclude TO pt_exclude.
+
  DATA ls_exclude TYPE ui_func.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
+
 
  APPEND ls_exclude TO pt_exclude.
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
+
  APPEND ls_exclude TO pt_exclude.
  APPEND ls_exclude TO pt_exclude.
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
+
  APPEND ls_exclude TO pt_exclude.
ENDFORM.                    " EXCLUDE_TB_FUNCTIONS
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
*&---------------------------------------------------------------------*
+
  APPEND ls_exclude TO pt_exclude.
*&      Form  GRABAR
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
*&---------------------------------------------------------------------*
+
  APPEND ls_exclude TO pt_exclude.
*      text
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
*----------------------------------------------------------------------*
+
  APPEND ls_exclude TO pt_exclude.
*  -->  p1        text
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
*  <--  p2        text
+
  APPEND ls_exclude TO pt_exclude.
*----------------------------------------------------------------------*
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
FORM grabar .
+
  APPEND ls_exclude TO pt_exclude.
  CALL METHOD g_grid->refresh_table_display.
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
ENDFORM.                    " GRABAR
+
  APPEND ls_exclude TO pt_exclude.
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
*&---------------------------------------------------------------------*
+
  APPEND ls_exclude TO pt_exclude.
*&      Form  user_command
+
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
*&---------------------------------------------------------------------*
+
  APPEND ls_exclude TO pt_exclude.
*      user command de CONTAINER
+
 
*----------------------------------------------------------------------*
+
ENDFORM.                    " EXCLUDE_TB_FUNCTIONS
*      -->I_FUNCTION text
+
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
+
*&      Form  GRABAR
FORM user_command USING i_function TYPE salv_de_function.
+
*&---------------------------------------------------------------------*
  DATA: gt_rows TYPE lvc_t_row.
+
*      text
+
*----------------------------------------------------------------------*
  CALL METHOD g_grid->get_selected_rows
+
*  -->  p1        text
    IMPORTING
+
*  <--  p2        text
      et_index_rows = gt_rows.
+
*----------------------------------------------------------------------*
+
FORM grabar .
  CASE i_function.
+
  CALL METHOD g_grid->refresh_table_display.
    WHEN 'APRO'. "do something
+
ENDFORM.                    " GRABAR
      LOOP AT gt_rows INTO DATA(l_tabix).
+
 
        READ TABLE gt_data INDEX l_tabix INTO wa_data.
+
*&---------------------------------------------------------------------*
      ENDLOOP.
+
*&      Form  user_command
  ENDCASE.
+
*&---------------------------------------------------------------------*
ENDFORM.</nowiki>
+
*      user command de CONTAINER
 +
*----------------------------------------------------------------------*
 +
*      -->I_FUNCTION text
 +
*----------------------------------------------------------------------*
 +
FORM user_command USING i_function TYPE salv_de_function.
 +
  DATA: gt_rows TYPE lvc_t_row.
 +
 
 +
  CALL METHOD g_grid->get_selected_rows
 +
    IMPORTING
 +
      et_index_rows = gt_rows.
 +
 
 +
  CASE i_function.
 +
    WHEN 'APRO'. "do something
 +
      LOOP AT gt_rows INTO DATA(l_tabix).
 +
        READ TABLE gt_data INDEX l_tabix INTO wa_data.
 +
      ENDLOOP.
 +
  ENDCASE.
 +
ENDFORM.</nowiki>
  
 
===Y_TEST_ALV_GRID_I01===
 
===Y_TEST_ALV_GRID_I01===
  <nowiki> *----------------------------------------------------------------------*
+
  <nowiki>*----------------------------------------------------------------------*
***INCLUDE Y_TEST_ALV_GRID_I01
+
***INCLUDE Y_TEST_ALV_GRID_I01
*----------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
+
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
*      user command de dynpro 0100
+
*      user command de dynpro 0100
*----------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
+
MODULE user_command_0100 INPUT.
  save_ok = ok_code.
+
  save_ok = ok_code.
  CLEAR ok_code.
+
  CLEAR ok_code.
+
 
  CASE save_ok.
+
  CASE save_ok.
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
    WHEN '&F03' OR "back
+
    WHEN '&F03' OR "back
          '&F15'  OR"leave
+
        '&F15'  OR"leave
          '&F12'. "canc
+
        '&F12'. "canc
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
      SET SCREEN 0.
+
      SET SCREEN 0.
      LEAVE SCREEN.
+
      LEAVE SCREEN.
+
 
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
    WHEN 'EDIT'.  "Habilitar/Des-Habilitar Editar Columnas
+
    WHEN 'EDIT'.  "Habilitar/Des-Habilitar Editar Columnas
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
      PERFORM style CHANGING g_edit.
+
      PERFORM style CHANGING g_edit.
+
 
      CALL METHOD g_grid->refresh_table_display.
+
      CALL METHOD g_grid->refresh_table_display.
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
    WHEN 'GRABAR'.
+
    WHEN 'GRABAR'.
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
      PERFORM grabar.
+
      PERFORM grabar.
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
    WHEN 'LOG'.
+
    WHEN 'LOG'.
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
+
 
    WHEN OTHERS.
+
    WHEN OTHERS.
*    do nothing
+
*    do nothing
  ENDCASE.
+
  ENDCASE.
+
ENDMODULE.                " USER_COMMAND_0100  INPUT</nowiki>
 
ENDMODULE.                " USER_COMMAND_0100  INPUT</nowiki>
 
  
 
===Y_TEST_ALV_GRID_O01===
 
===Y_TEST_ALV_GRID_O01===
  <nowiki> *----------------------------------------------------------------------*
+
  <nowiki>*----------------------------------------------------------------------*
***INCLUDE Y_TEST_ALV_GRID_O01
+
***INCLUDE Y_TEST_ALV_GRID_O01
*----------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
+
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
*      text
+
*      text
*----------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
+
MODULE status_0100 OUTPUT.
+
 
  SET PF-STATUS 'LIST_ALV'. ""copiar de SALV_DEMO_TABLE_LAYOUT
+
  SET PF-STATUS 'LIST_ALV'. ""copiar de SALV_DEMO_TABLE_LAYOUT
  SET TITLEBAR 'T01'.
+
  SET TITLEBAR 'T01'.
+
 
  IF G_CUSTOM_CONTAINER IS INITIAL.
+
  IF G_CUSTOM_CONTAINER IS INITIAL.
    PERFORM CREATE_AND_INIT_ALV CHANGING GT_DATA[]
+
    PERFORM CREATE_AND_INIT_ALV CHANGING GT_DATA[]
                                          GT_FIELDCAT.
+
                                        GT_FIELDCAT.
+
 
  ELSE.
+
  ELSE.
*    CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY.
+
*    CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY.
    CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = G_GRID.
+
    CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = G_GRID.
  ENDIF.
+
  ENDIF.
ENDMODULE.                " STATUS_0100  OUTPUT</nowiki>
+
ENDMODULE.                " STATUS_0100  OUTPUT</nowiki>
  
 
===Dynpro 0100===
 
===Dynpro 0100===

Latest revision as of 20:29, 4 April 2020

  • Ejemplo de CL_GUI_ALV_GRID con User Command en dynpro & Container y editar columna

YTEST_ALV_GRID

*----------------------------------------------------------------------*
* Report  YTEST_ALV_GRID
* Author: .....
*----------------------------------------------------------------------*
* ejemplo de CL_GUI_ALV_GRID con User Command en dynpro & Container
* y editar columna
*
*----------------------------------------------------------------------*
REPORT ytest_alv_grid.

TYPE-POOLS icon.

TYPES: BEGIN OF ty_data.
        INCLUDE TYPE p0002.
TYPES celltab TYPE lvc_t_styl.
TYPES     END OF ty_data.

DATA gt_data TYPE TABLE OF ty_data.
DATA gt_data_ori TYPE TABLE OF ty_data.
DATA wa_data LIKE LINE OF gt_data.

DATA g_edit TYPE xfeld.

INCLUDE y_test_alv_grid_top.

*--------------------------------------------------------------------*
*
*--------------------------------------------------------------------*

SELECT-OPTIONS: s_pernr FOR wa_data-pernr MATCHCODE OBJECT prem.

*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*

  SELECT pernr vorna nachn name2 INTO CORRESPONDING FIELDS OF TABLE gt_data FROM pa0002 UP TO 100 ROWS
                              WHERE pernr IN s_pernr.

  gt_data_ori[] = gt_data[].

  PERFORM style CHANGING g_edit. "por defecto no se puede editar, ver user_command_0100 code EDIT
*--------------------------------------------------------------------*
END-OF-SELECTION.
*--------------------------------------------------------------------*
* display ALV
  CALL SCREEN 0100.  "en la dynpro crear container CC_ALV

  INCLUDE y_test_alv_grid_f01.
  INCLUDE y_test_alv_grid_o01.
  INCLUDE y_test_alv_grid_i01.

Y_TEST_ALV_GRID_TOP

* Y_TEST_ALV_GRID_TOP
*--------------------------------------------------------------------*
DATA: ok_code            LIKE sy-ucomm,
      save_ok            LIKE sy-ucomm,
      g_container        TYPE scrfname VALUE 'CC_ALV',
      g_grid             TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gt_fieldcat        TYPE lvc_t_fcat,
      gs_layout          TYPE lvc_s_layo,
      gt_events TYPE slis_t_event.

DATA : g_variant1 TYPE disvariant,
       g_variant2 TYPE disvariant.

INCLUDE <icon>.
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: g_event_receiver TYPE REF TO lcl_event_receiver.

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
      handle_toolbar
                    FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING e_object e_interactive,

      handle_user_command
                    FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING e_ucomm.

    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
*----------------------------------------------------------------------*
*   agregar botones a CONTAINER
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.

  METHOD handle_toolbar.
    DATA: ls_toolbar  TYPE stb_button.
* append a separator to normal toolbar
    CLEAR ls_toolbar.
    MOVE 3 TO ls_toolbar-butn_type.
    APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon to show booking table

*--------------------------------------------------------------------*
* se habilita botón Aprobar
*--------------------------------------------------------------------*
    CLEAR ls_toolbar.
    MOVE 'APRO' TO ls_toolbar-function.
    MOVE icon_execute_object TO ls_toolbar-icon.
    MOVE 'Aprobar' TO ls_toolbar-quickinfo.
    MOVE 'Aprobar' TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.

  ENDMETHOD.
*--------------------------------------------------------------------*
  METHOD handle_user_command.
*--------------------------------------------------------------------*
    PERFORM user_command USING e_ucomm.
  ENDMETHOD.

*--------------------------------------------------------------------*
  METHOD handle_data_changed.
*--------------------------------------------------------------------*
    DATA : ls_mod_cell TYPE lvc_s_modi,
           lv_value    TYPE lvc_value,
           lv_mask1    TYPE string,
           lv_mask2    TYPE string.

    DATA: l_nachn TYPE pa0002-nachn,
          l_vorna TYPE pa0002-vorna,
          l_name2 TYPE p0002-name2.
    DATA l_subrc TYPE sy-subrc.
    data l_dummy(200).

    DATA: lv_valor TYPE string.
    DATA: lv_mod TYPE i.

    SORT er_data_changed->mt_mod_cells BY row_id .

    LOOP AT er_data_changed->mt_good_cells INTO ls_mod_cell.
      IF ls_mod_cell-fieldname = 'VORNA'.

        CALL METHOD er_data_changed->get_cell_value
          EXPORTING
            i_row_id    = ls_mod_cell-row_id
            i_fieldname = 'VORNA'
          IMPORTING
            e_value     = l_vorna.

        READ TABLE gt_data_ori INTO wa_data INDEX ls_mod_cell-row_id.
        IF wa_data-vorna <> l_vorna.
            if l_vorna = 'Homero'.
              l_subrc = 1.
              MESSAGE e000(0k) with 'No se permiten Homeros' into l_dummy.
            endif.
        ELSE.
          l_subrc = 0.
        ENDIF.

        IF l_subrc <> 0.
          DATA(error_in_data) = 'X'.
          CALL METHOD er_data_changed->add_protocol_entry
            EXPORTING
              i_msgid     = sy-msgid
              i_msgno     = sy-msgno
              i_msgty     = sy-msgty
              i_msgv1     = sy-msgv1
              i_msgv2     = sy-msgv2
              i_msgv3     = sy-msgv3
              i_msgv4     = sy-msgv4
              i_fieldname = ls_mod_cell-fieldname
              i_row_id    = ls_mod_cell-row_id.

          CALL METHOD er_data_changed->modify_cell
            EXPORTING
              i_row_id    = ls_mod_cell-row_id
              i_fieldname = 'VORNA'
              i_value     = wa_data-vorna.
          CONTINUE.

        ENDIF.
      ENDIF.
    ENDLOOP.

    CALL METHOD g_grid->refresh_table_display.

    IF error_in_data EQ 'X'.
      CALL METHOD er_data_changed->display_protocol.
    ENDIF.
  ENDMETHOD.

ENDCLASS.

Y_TEST_ALV_GRID_F01

*----------------------------------------------------------------------*
***Y_TEST_ALV_GRID_F01
*----------------------------------------------------------------------*
FORM fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
  DATA lt_fcat_save TYPE lvc_t_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'PA0002'
      i_client_never_display = 'X'
    CHANGING
      ct_fieldcat            = lt_fcat_save
    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.

* colums names
*  LOOP AT lt_fcat_save ASSIGNING FIELD-SYMBOL(<wa>).
*    CASE <wa>-fieldname.
*      WHEN 'ICON'.
*        <wa>-scrtext_l = 'Estatus'.
*        <wa>-scrtext_m = 'Estatus'.
*        <wa>-scrtext_s = <wa>-reptext = 'Estatus'.
*  endloop.

* hide, solo se desplegan columnas PERNR, VORNA, NACHN & NAME2
  LOOP AT lt_fcat_save ASSIGNING FIELD-SYMBOL(<wa>) WHERE fieldname <> 'PERNR'
                                        AND fieldname <> 'VORNA'
                                        AND fieldname <> 'NACHN'
                                        AND fieldname <> 'NAME2'.
    <wa>-tech = 'X'.
  ENDLOOP.

* enable VORNA para editar
  READ TABLE lt_fcat_save ASSIGNING <wa> WITH KEY fieldname = 'VORNA'.
  <wa>-edit = 'X'.

  pt_fieldcat[] = lt_fcat_save[].

ENDFORM.
*----------------------------------------------------------------------*
*       FORM style
*----------------------------------------------------------------------*
* Habilita/Des-Habilita edición de columna VORNA
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM style CHANGING p_edit.
  DATA: ls_celltab TYPE lvc_s_styl.
  DATA: lt_celltab TYPE lvc_t_styl.
  DATA l_tabix TYPE sy-tabix.

  LOOP AT gt_data INTO wa_data.
    l_tabix = sy-tabix.
    CLEAR lt_celltab[].
    CLEAR wa_data-celltab[].

    IF p_edit = 'X'.
    ELSE.
      ls_celltab-fieldname = 'VORNA'.
      ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
      INSERT ls_celltab INTO TABLE lt_celltab.
    ENDIF.

    INSERT LINES OF lt_celltab INTO TABLE wa_data-celltab.
    MODIFY gt_data FROM wa_data INDEX l_tabix.
  ENDLOOP.

  IF p_edit = 'X'.
    p_edit = space.
  ELSE.
    p_edit = 'X'.
  ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_DATA[]  text
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*

FORM create_and_init_alv CHANGING pt_outtab TYPE STANDARD TABLE
                                  pt_fieldcat TYPE lvc_t_fcat.

  DATA: lt_exclude TYPE ui_functions.
  DATA: ps_layout TYPE lvc_s_layo.

  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = g_container.
  CREATE OBJECT g_grid
    EXPORTING
      i_parent = g_custom_container.

  PERFORM fieldcat CHANGING pt_fieldcat.

  PERFORM exclude_tb_functions CHANGING lt_exclude.

  ps_layout-zebra = 'X'.
  ps_layout-cwidth_opt = 'X'.
  ps_layout-stylefname = 'CELLTAB'.

  g_variant1-report = sy-repid.
  g_variant1-handle = 'X'.
  g_variant1-username = sy-uname.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = g_variant1
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.

  CALL METHOD g_grid->set_table_for_first_display
    EXPORTING
      i_save               = 'A'
      is_variant           = g_variant1
      is_layout            = ps_layout
      it_toolbar_excluding = lt_exclude
    CHANGING
      it_fieldcatalog      = pt_fieldcat
      it_outtab            = pt_outtab[].

  CALL METHOD g_grid->set_ready_for_input
    EXPORTING
      i_ready_for_input = 1.

  CALL METHOD g_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter.

*  CALL METHOD g_grid->save_variant.

  CREATE OBJECT g_event_receiver.
  SET HANDLER g_event_receiver->handle_user_command FOR g_grid.
  SET HANDLER g_event_receiver->handle_toolbar FOR g_grid.
  SET HANDLER g_event_receiver->handle_data_changed FOR g_grid.
  CALL METHOD g_grid->set_toolbar_interactive.


ENDFORM.                    " CREATE_AND_INIT_ALV

*&---------------------------------------------------------------------*
*&      Form  EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PT_EXCLUDE text
*----------------------------------------------------------------------*
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
  DATA ls_exclude TYPE ui_func.

  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
  APPEND ls_exclude TO pt_exclude.

ENDFORM.                    " EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
*&      Form  GRABAR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM grabar .
  CALL METHOD g_grid->refresh_table_display.
ENDFORM.                    " GRABAR

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       user command de CONTAINER
*----------------------------------------------------------------------*
*      -->I_FUNCTION text
*----------------------------------------------------------------------*
FORM user_command USING i_function TYPE salv_de_function.
  DATA: gt_rows TYPE lvc_t_row.

  CALL METHOD g_grid->get_selected_rows
    IMPORTING
      et_index_rows = gt_rows.

  CASE i_function.
    WHEN 'APRO'. "do something
      LOOP AT gt_rows INTO DATA(l_tabix).
        READ TABLE gt_data INDEX l_tabix INTO wa_data.
      ENDLOOP.
  ENDCASE.
ENDFORM.

Y_TEST_ALV_GRID_I01

*----------------------------------------------------------------------*
***INCLUDE Y_TEST_ALV_GRID_I01
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       user command de dynpro 0100
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.

  CASE save_ok.
*--------------------------------------------------------------------*
    WHEN '&F03' OR "back
         '&F15'  OR"leave
         '&F12'. "canc
*--------------------------------------------------------------------*
      SET SCREEN 0.
      LEAVE SCREEN.

*--------------------------------------------------------------------*
    WHEN 'EDIT'.  "Habilitar/Des-Habilitar Editar Columnas
*--------------------------------------------------------------------*
      PERFORM style CHANGING g_edit.

      CALL METHOD g_grid->refresh_table_display.
*--------------------------------------------------------------------*
    WHEN 'GRABAR'.
*--------------------------------------------------------------------*
      PERFORM grabar.
*--------------------------------------------------------------------*
    WHEN 'LOG'.
*--------------------------------------------------------------------*

    WHEN OTHERS.
*     do nothing
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

Y_TEST_ALV_GRID_O01

*----------------------------------------------------------------------*
***INCLUDE Y_TEST_ALV_GRID_O01
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

  SET PF-STATUS 'LIST_ALV'. ""copiar de SALV_DEMO_TABLE_LAYOUT
  SET TITLEBAR 'T01'.

  IF G_CUSTOM_CONTAINER IS INITIAL.
    PERFORM CREATE_AND_INIT_ALV CHANGING GT_DATA[]
                                         GT_FIELDCAT.

  ELSE.
*    CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY.
    CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = G_GRID.
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT

Dynpro 0100

  • Crear Custom Container con nombre CC_ALV
  • Agregar elemento OK_CODE de tipo OK
  • Crear Status GUI LIST_ALV copia de programa SALV_DEMO_TABLE_LAYOUT Status SALV_STANDARD
  • Agregar Código de función EDIT - Editar - ICON_TOGGLE_DISPLAY_CHANGE
  • Agregar Código de función GRABAR - Grabar - ICON_SYSTEM_SAVE
  • Crear Título T01 "Test CL_GUI_ALV_GRID"
PROCESS BEFORE OUTPUT.
  MODULE status_0100.
*
PROCESS AFTER INPUT.
  MODULE user_command_0100.