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
* <-- nbsp="" p2="" span="" 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-->
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
* <-- nbsp="" p2="" span="" 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-->
No comments:
Post a Comment