Skip to end of metadata
Go to start of metadata

This simple program helps in editing DDIC from ALV on pressing putton on toolbar.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
    Perform action on Hot spot Click. 

*&---------------------------------------------------------------------*
*& Report  YKC_ALV_OOPS
*&
*&---------------------------------------------------------------------*
*& This prog will help in understanding ALV OOPS
*& EDIT on SAVE
*& Tool bar button addition
*&---------------------------------------------------------------------*
REPORT  YKC_ALV_OOPS.
tables: MARA.
data: begin of it_tab occurs 0,
      matnr like mara-matnr,
      ersda like mara-ersda,  "creation date
      ernam like mara-ernam,  "person created
      pstat like mara-pstat,  "maint stat
      lvorm like mara-lvorm,  "flg for deletion
      mtart like mara-mtart,  "mat type
      meins like mara-meins,  "uom
      end of it_tab.
data: wa_it_tab like line of it_tab.  "making work area
data: i_modified TYPE STANDARD TABLE OF mara,"For getting modified rows
      w_modified TYPE mara.
CLASS lcl_events_d0100 DEFINITION DEFERRED.
DATA: event_receiver1  TYPE REF TO lcl_events_d0100,
      i_selected_rows TYPE lvc_t_row,                "Selected Rows
      w_selected_rows TYPE lvc_s_row.
*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_events_d0100 DEFINITION.
  PUBLIC SECTION.
    METHODS
        handle_hotspot_click
        FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
             e_row_id
             e_column_id
             es_row_no
             sender.
*---code addition for ALV pushbuttons
*--for placing buttons
    METHODS handle_toolbar_set
        FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING
              e_object
              e_interactive.
*---user command on clicking a button
    METHODS handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING
             e_ucomm.
ENDCLASS.                    "lcl_events_d0100 DEFINITION
TYPE-POOLS cndp.
DATA ok_code TYPE sy-ucomm.
*----------------------------------------------------------------------*
*                       FOR VARIANT
*----------------------------------------------------------------------*
DATA st_var TYPE disvariant .
DATA save TYPE c.
st_var-report = 'YKC_ALV_OOPS'.
save = 'A'.
*----------------------------------------------------------------------*
*         FOR LAYOUT
*----------------------------------------------------------------------*
DATA loyo TYPE lvc_s_layo.
loyo-zebra = 'X'.
loyo-detailinit = 'X'.
loyo-info_fname = 'RED'.
*----------------------------------------------------------------------*
*           FOR FIELD CATALOG
*----------------------------------------------------------------------*
DATA fcat TYPE lvc_t_fcat.
DATA wa_fcat LIKE LINE OF fcat.
*--Declaration for toolbar buttons
DATA : ty_toolbar      TYPE stb_button.
DATA : e_object        TYPE REF TO cl_alv_event_toolbar_set,
       io_alv_toolbar  TYPE REF TO cl_alv_event_toolbar_set.
*---custom container
DATA container TYPE REF TO cl_gui_custom_container.
DATA ref_grid TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT container
  EXPORTING
    container_name = 'CONTAINER'."name of container in module pool
CREATE OBJECT ref_grid
  EXPORTING
    i_parent = container.
*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_events_d0100 IMPLEMENTATION.
*---method for hotspot
  METHOD handle_hotspot_click.
    DATA:ls_col_id   TYPE lvc_s_col.
    READ TABLE it_tab INTO wa_it_tab
                             INDEX e_row_id-index.
    IF sy-subrc = 0.
      CHECK ( wa_it_tab-matnr IS NOT INITIAL ).
      CASE e_column_id-fieldname.
        WHEN 'MATNR'.
          leave program.
*---put your own logic as per requirement on hotspot click
        WHEN OTHERS.
*       do nothing
      ENDCASE.
      CALL METHOD ref_grid->set_current_cell_via_id
        EXPORTING
          is_row_id    = e_row_id
          is_column_id = ls_col_id.
    ENDIF.
  ENDMETHOD.                    "handle_hotspot_click
**---method for handling toolbar
  METHOD handle_toolbar_set.
    CLEAR ty_toolbar.
    ty_toolbar-function = 'EDIT'. "name of btn to  catch click
    ty_toolbar-butn_type = 0.
    ty_toolbar-text = 'EDIT'.
    APPEND ty_toolbar    TO e_object->mt_toolbar.
  ENDMETHOD.                    "handle_toolbar_set
  METHOD handle_user_command.
    DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    DATA: lt_rows TYPE lvc_t_row,
          lt_index TYPE  lvc_s_row-index.
    CASE e_ucomm.
      WHEN 'EDIT'.
      perform save_database.
      CALL METHOD ref_GRID->REFRESH_TABLE_DISPLAY.
    ENDCASE.
  ENDMETHOD.                    "handle_user_command
ENDCLASS.                    "lcl_events_d0100 IMPLEMENTATION
START-OF-SELECTION.
  PERFORM get_data.
  PERFORM field_catalog.
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text : getting data into internal table
*----------------------------------------------------------------------*
form get_data .
  select matnr ersda ernam pstat lvorm mtart meins
         into table it_tab
         from mara
         where matnr GE '000000000000000001'.
endform.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  field_catalog
*&---------------------------------------------------------------------*
*       text  :setting field cat
*----------------------------------------------------------------------*
form field_catalog .
  REFRESH fcat.
  DATA: lv_pos TYPE i.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-coltext = 'Material No'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-hotspot = 'X'.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'ERSDA'.
  wa_fcat-coltext = 'Creation Date'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-edit = 'X'.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'ERNAM'.
  wa_fcat-coltext = 'Person Created'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'PSTAT'.
  wa_fcat-coltext = 'Maint Stat'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'LVORM'.
  wa_fcat-coltext = 'Flag For Deletion'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'MTART'.
  wa_fcat-coltext = 'Material Type'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  lv_pos = lv_pos + 1.
  wa_fcat-fieldname = 'MEINS'.
  wa_fcat-coltext = 'UOM'.
  wa_fcat-col_pos = lv_pos.
  wa_fcat-outputlen = 18.
  APPEND wa_fcat TO fcat.
  CLEAR wa_fcat.
  CREATE OBJECT event_receiver1.
*---setting event handlers
  SET HANDLER event_receiver1->handle_toolbar_set   FOR ref_grid.
  SET HANDLER event_receiver1->handle_user_command  FOR ref_grid.
  SET HANDLER event_receiver1->handle_hotspot_click FOR ref_grid.
*----------------------------------------------------------------------*
*           ALV GRID DISPLAY
*----------------------------------------------------------------------*
  CALL METHOD ref_grid->set_table_for_first_display
    EXPORTING
      is_variant      = st_var
      i_save          = save
      is_layout       = loyo
    CHANGING
      it_outtab       = it_tab[]
      it_fieldcatalog = fcat.
  CALL SCREEN 100.
endform.                    " field_catalog
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module STATUS_0100 output.
*  CREATE OBJECT gr_events_d0100.
*
*  SET HANDLER gr_events_d0100->double_click
*
*                 FOR ref_grid.
CALL METHOD ref_grid->register_edit_event
  EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified.
  SET PF-STATUS 'S100'.
  SET TITLEBAR 'XXX'.
endmodule.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  exit  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module exit input.
  CASE ok_code.
    WHEN 'EXI' .
      CLEAR ok_code.
      LEAVE PROGRAM.
  ENDCASE.
endmodule.                 " exit  INPUT
*&---------------------------------------------------------------------*
*&      Form  SAVE_DATABASE
*&---------------------------------------------------------------------*
*       text : saving into DDIC from internal table
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SAVE_DATABASE .
*--- Getting the selected rows index
    CALL METHOD ref_grid->get_selected_rows
                IMPORTING  et_index_rows = i_selected_rows.
*--- Through the index capturing the values of selected rows
    LOOP AT i_selected_rows INTO w_selected_rows.
    READ TABLE it_tab INTO wa_it_tab INDEX w_selected_rows-index.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING wa_it_tab TO w_modified.
      APPEND w_modified TO i_modified.
    ENDIF.
  ENDLOOP.
  MODIFY mara FROM TABLE i_modified.
ENDFORM.                    " SAVE_DATABASE

2 Comments

  1. Unknown User (101dusycz)

    This code gives materials and creation date in an ALV grid. Creation date can be modified. I want to be able to change the dates for several materials, hit the EDIT button and be able to save to mara. RIght now, after modifying the date, I have to highlight the row and then hit EDIT. Thanks.

  2. Former Member

    Hello,

    I am Debottam and I have a very simple query based on ALV grid display. In my AlV report I have a column named BILL RECEIVED and the next column named BILL RECEIVED DATE. The Bill RECEIVED column contains check box. The requirement is when I click on a checkbox in a row, the cell of BILL RECEIVED DATE of the same row becomes editable and vice-versa. That means only those cells of BILL RECEIVED DATE will be editable, whose BILL RECEIVED have the checkbox clicked. Rest will be in un-editable mode. How we can achieve this through REUSE_ALV_GRID_DISPLAY. If this is not possible to achieve this through REUSE_ALV_GRID_DISPLAY what is the alternative. Please suggest.

    Thanks and Regards,

    Debottam.