REPORT ztest_6
.
**********************************************************************
*Table Declaration
**********************************************************************
TABLES : ekko .
TYPE-POOLS : cntl ,slis .
**********************************************************************
*DATA DECLARATION
**********************************************************************
DATA : BEGIN OF it_ekko OCCURS 0 ,
sel ( 1 ) ,
ebeln LIKE ekpo -ebeln ,
ebelp LIKE ekpo -ebelp ,
statu LIKE ekpo -statu ,
aedat LIKE ekpo -aedat ,
matnr LIKE ekpo -matnr ,
menge LIKE ekpo -menge ,
meins LIKE ekpo -meins ,
peinh LIKE ekpo -peinh ,
btn ( 10 ) ,
drdbox ( 20 ) ,
dd_handle TYPE int4 ,
cellstyle TYPE lvc_t_styl ,
END OF it_ekko .
**********************************************************************
*DATA declaration for ALV
**********************************************************************
DATA : it_fieldcatalog TYPE lvc_t_fcat ,
wa_fieldcatalog TYPE lvc_s_fcat ,
g_tab_group TYPE slis_sp_group_alv ,
g_layout TYPE slis_layout_alv ,
g_repid LIKE sy -repid ,
w_layout TYPE lvc_s_layo ,
g_stylerow TYPE lvc_s_styl ,
g_t_ddval TYPE lvc_t_drop ,
g_ddval TYPE lvc_s_drop ,
g_events TYPE slis_t_event ,
g_event TYPE slis_alv_event ,
g_styletab TYPE TABLE OF lvc_s_styl .
*----------------------------------------------------------------------*
* CLASS lcl_event_handlers DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_event_handlers DEFINITION .
PUBLIC SECTION .
METHODS : handle_button_click FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING es_col_id es_row_no .
ENDCLASS . "lcl_event_handlers DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_handlers IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_event_handlers IMPLEMENTATION .
METHOD handle_button_click .
DATA : l_row ( 10 ) ,
l_str TYPE string .
l_row = es_row_no -row_id .
CONCATENATE 'You have clicked on column :' es_col_id -fieldname ',row:' l_row INTO l_str .
MESSAGE l_str TYPE 'I' .
ENDMETHOD . "handle_button_click
ENDCLASS . "lcl_event_handlers IMPLEMENTATION
**********************************************************************
*START-OF-SELECTION
**********************************************************************
START-OF-SELECTION .
PERFORM data_retrieval .
PERFORM build_fieldcatalog .
PERFORM build_layout .
PERFORM create_dropdown_values .
PERFORM create_event_exits .
PERFORM display_alv_report .
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* retrieve data from table ekpo
*----------------------------------------------------------------------*
FORM data_retrieval .
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko .
LOOP AT it_ekko .
it_ekko -btn = sy -tabix .
it_ekko -dd_handle = 1 .
CLEAR g_styletab . REFRESH g_styletab .
*>IF the item no is equal to 1, this cell will can not be edited.
IF it_ekko -ebelp EQ 1 .
g_stylerow -fieldname = 'SEL' .
g_stylerow -style = cl_gui_alv_grid =>mc_style_disabled .
APPEND g_stylerow TO g_styletab .
ENDIF .
*>let the column display as pushbutton
g_stylerow -fieldname = 'BTN' .
g_stylerow -style = cl_gui_alv_grid =>mc_style_button .
APPEND g_stylerow TO g_styletab .
it_ekko -cellstyle[] = g_styletab[] .
MODIFY it_ekko .
ENDLOOP .
ENDFORM . " DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* populate fieldcatalog
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
*>The column will be displayed as checkbox
wa_fieldcatalog -col_pos = 1 .
wa_fieldcatalog -fieldname = 'SEL' .
wa_fieldcatalog -scrtext_l = 'Check' .
wa_fieldcatalog - checkbox = 'X' .
wa_fieldcatalog - edit = 'X' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 2 .
wa_fieldcatalog -fieldname = 'EBELN' .
wa_fieldcatalog -scrtext_l = 'TST1' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 3 .
wa_fieldcatalog -fieldname = 'EBELP' .
wa_fieldcatalog -scrtext_l = 'TST2' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 4 .
wa_fieldcatalog -fieldname = 'STATU' .
wa_fieldcatalog -scrtext_l = 'TST3' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 5 .
wa_fieldcatalog -fieldname = 'AEDAT' .
wa_fieldcatalog -scrtext_l = 'TST4' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 6 .
wa_fieldcatalog -fieldname = 'MATNR' .
wa_fieldcatalog -scrtext_l = 'TST5' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 7 .
wa_fieldcatalog -fieldname = 'MENGE' .
wa_fieldcatalog -scrtext_l = 'TST6' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 8 .
wa_fieldcatalog -fieldname = 'MEINS' .
wa_fieldcatalog -scrtext_l = 'TST7' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 9 .
wa_fieldcatalog -fieldname = 'PEINH' .
wa_fieldcatalog -scrtext_l = 'TST8' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
*>The column will be displayed as button
wa_fieldcatalog -col_pos = 10 .
wa_fieldcatalog -fieldname = 'BTN' .
wa_fieldcatalog -scrtext_l = 'TST9' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
*>The column will be displayed as dropdownbox
wa_fieldcatalog -col_pos = 11 .
wa_fieldcatalog -fieldname = 'DRDBOX' .
wa_fieldcatalog - edit = 'X' .
wa_fieldcatalog -drdn_field = 'DD_HANDLE' .
wa_fieldcatalog -scrtext_l = 'TST10' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
ENDFORM . " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form CREATE_DROPDOWN_VALUES
*&---------------------------------------------------------------------*
FORM create_dropdown_values .
g_ddval -handle = 1 .
g_ddval - value = 'yes' .
APPEND g_ddval TO g_t_ddval .
g_ddval -handle = 1 .
g_ddval - value = 'no' .
APPEND g_ddval TO g_t_ddval .
ENDFORM . "CREATE_DROPDOWN_VALUES
*&---------------------------------------------------------------------*
*& Form create_event_exits
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM create_event_exits .
g_event -name = 'CALLER_EXIT' .
g_event - form = 'CALLER_EXIT' .
APPEND g_event TO g_events .
ENDFORM . "create_event_exits
*&---------------------------------------------------------------------*
*& Form CALLER_EXIT
*&---------------------------------------------------------------------*
FORM caller_exit USING ls_data TYPE slis_data_caller_exit .
DATA : l_ref_alv TYPE REF TO cl_gui_alv_grid ,
l_ref_handler TYPE REF TO lcl_event_handlers .
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_ref_alv .
CALL METHOD l_ref_alv ->set_drop_down_table
EXPORTING
it_drop_down = g_t_ddval .
CREATE OBJECT l_ref_handler .
SET HANDLER l_ref_handler ->handle_button_click FOR l_ref_alv .
ENDFORM . "CALLER_EXIT
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* populate layout
*----------------------------------------------------------------------*
FORM build_layout .
w_layout -stylefname = 'CELLSTYLE' .
w_layout -zebra = 'X' .
w_layout -box_fname = 'SEL' .
ENDFORM . " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* display alv report
*----------------------------------------------------------------------*
FORM display_alv_report .
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
* EXPORTING
* i_callback_program = sy-repid
* i_callback_user_command = 'USER_COMMAND'
* is_layout = g_layout
* it_fieldcat = it_fieldcatalog
** i_save = 'X'
* TABLES
* t_outtab = it_ekko
* EXCEPTIONS
* program_error = 1
* OTHERS = 2.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy -repid
is_layout_lvc = w_layout
it_events = g_events
i_callback_user_command = 'USER_COMMAND'
it_fieldcat_lvc = it_fieldcatalog
TABLES
t_outtab = it_ekko[] .
ENDFORM . " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* USER-COMMAND
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy -ucomm
rs_selfield TYPE slis_selfield .
*>Check function code
CASE r_ucomm .
WHEN '&IC1' .
*>Check field clicked on within alv grid report
IF rs_selfield -fieldname = 'EBELN' .
READ TABLE it_ekko INDEX rs_selfield -tabindex .
SET PARAMETER ID 'BES' FIELD it_ekko -ebeln .
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN .
ENDIF .
* IF rs_selfield-fieldname = 'SEL'.
* READ TABLE it_ekko INDEX rs_selfield-tabindex.
* it_ekko-sel = 'X'.
* MODIFY it_ekko.
* ENDIF.
WHEN '&DATA_SAVE' .
LOOP AT it_ekko .
IF it_ekko -sel EQ 'X' .
WRITE : / it_ekko -ebeln .
ENDIF .
ENDLOOP .
* LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 1000.
ENDCASE .
rs_selfield - refresh = 'X' .
ENDFORM . "user_command
**********************************************************************
*Table Declaration
**********************************************************************
TABLES : ekko .
TYPE-POOLS : cntl ,slis .
**********************************************************************
*DATA DECLARATION
**********************************************************************
DATA : BEGIN OF it_ekko OCCURS 0 ,
sel ( 1 ) ,
ebeln LIKE ekpo -ebeln ,
ebelp LIKE ekpo -ebelp ,
statu LIKE ekpo -statu ,
aedat LIKE ekpo -aedat ,
matnr LIKE ekpo -matnr ,
menge LIKE ekpo -menge ,
meins LIKE ekpo -meins ,
peinh LIKE ekpo -peinh ,
btn ( 10 ) ,
drdbox ( 20 ) ,
dd_handle TYPE int4 ,
cellstyle TYPE lvc_t_styl ,
END OF it_ekko .
**********************************************************************
*DATA declaration for ALV
**********************************************************************
DATA : it_fieldcatalog TYPE lvc_t_fcat ,
wa_fieldcatalog TYPE lvc_s_fcat ,
g_tab_group TYPE slis_sp_group_alv ,
g_layout TYPE slis_layout_alv ,
g_repid LIKE sy -repid ,
w_layout TYPE lvc_s_layo ,
g_stylerow TYPE lvc_s_styl ,
g_t_ddval TYPE lvc_t_drop ,
g_ddval TYPE lvc_s_drop ,
g_events TYPE slis_t_event ,
g_event TYPE slis_alv_event ,
g_styletab TYPE TABLE OF lvc_s_styl .
*----------------------------------------------------------------------*
* CLASS lcl_event_handlers DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_event_handlers DEFINITION .
PUBLIC SECTION .
METHODS : handle_button_click FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING es_col_id es_row_no .
ENDCLASS . "lcl_event_handlers DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_handlers IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_event_handlers IMPLEMENTATION .
METHOD handle_button_click .
DATA : l_row ( 10 ) ,
l_str TYPE string .
l_row = es_row_no -row_id .
CONCATENATE 'You have clicked on column :' es_col_id -fieldname ',row:' l_row INTO l_str .
MESSAGE l_str TYPE 'I' .
ENDMETHOD . "handle_button_click
ENDCLASS . "lcl_event_handlers IMPLEMENTATION
**********************************************************************
*START-OF-SELECTION
**********************************************************************
START-OF-SELECTION .
PERFORM data_retrieval .
PERFORM build_fieldcatalog .
PERFORM build_layout .
PERFORM create_dropdown_values .
PERFORM create_event_exits .
PERFORM display_alv_report .
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* retrieve data from table ekpo
*----------------------------------------------------------------------*
FORM data_retrieval .
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko .
LOOP AT it_ekko .
it_ekko -btn = sy -tabix .
it_ekko -dd_handle = 1 .
CLEAR g_styletab . REFRESH g_styletab .
*>IF the item no is equal to 1, this cell will can not be edited.
IF it_ekko -ebelp EQ 1 .
g_stylerow -fieldname = 'SEL' .
g_stylerow -style = cl_gui_alv_grid =>mc_style_disabled .
APPEND g_stylerow TO g_styletab .
ENDIF .
*>let the column display as pushbutton
g_stylerow -fieldname = 'BTN' .
g_stylerow -style = cl_gui_alv_grid =>mc_style_button .
APPEND g_stylerow TO g_styletab .
it_ekko -cellstyle[] = g_styletab[] .
MODIFY it_ekko .
ENDLOOP .
ENDFORM . " DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* populate fieldcatalog
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
*>The column will be displayed as checkbox
wa_fieldcatalog -col_pos = 1 .
wa_fieldcatalog -fieldname = 'SEL' .
wa_fieldcatalog -scrtext_l = 'Check' .
wa_fieldcatalog - checkbox = 'X' .
wa_fieldcatalog - edit = 'X' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 2 .
wa_fieldcatalog -fieldname = 'EBELN' .
wa_fieldcatalog -scrtext_l = 'TST1' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 3 .
wa_fieldcatalog -fieldname = 'EBELP' .
wa_fieldcatalog -scrtext_l = 'TST2' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 4 .
wa_fieldcatalog -fieldname = 'STATU' .
wa_fieldcatalog -scrtext_l = 'TST3' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 5 .
wa_fieldcatalog -fieldname = 'AEDAT' .
wa_fieldcatalog -scrtext_l = 'TST4' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 6 .
wa_fieldcatalog -fieldname = 'MATNR' .
wa_fieldcatalog -scrtext_l = 'TST5' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 7 .
wa_fieldcatalog -fieldname = 'MENGE' .
wa_fieldcatalog -scrtext_l = 'TST6' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 8 .
wa_fieldcatalog -fieldname = 'MEINS' .
wa_fieldcatalog -scrtext_l = 'TST7' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
wa_fieldcatalog -col_pos = 9 .
wa_fieldcatalog -fieldname = 'PEINH' .
wa_fieldcatalog -scrtext_l = 'TST8' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
*>The column will be displayed as button
wa_fieldcatalog -col_pos = 10 .
wa_fieldcatalog -fieldname = 'BTN' .
wa_fieldcatalog -scrtext_l = 'TST9' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
*>The column will be displayed as dropdownbox
wa_fieldcatalog -col_pos = 11 .
wa_fieldcatalog -fieldname = 'DRDBOX' .
wa_fieldcatalog - edit = 'X' .
wa_fieldcatalog -drdn_field = 'DD_HANDLE' .
wa_fieldcatalog -scrtext_l = 'TST10' .
APPEND wa_fieldcatalog TO it_fieldcatalog . CLEAR wa_fieldcatalog .
ENDFORM . " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form CREATE_DROPDOWN_VALUES
*&---------------------------------------------------------------------*
FORM create_dropdown_values .
g_ddval -handle = 1 .
g_ddval - value = 'yes' .
APPEND g_ddval TO g_t_ddval .
g_ddval -handle = 1 .
g_ddval - value = 'no' .
APPEND g_ddval TO g_t_ddval .
ENDFORM . "CREATE_DROPDOWN_VALUES
*&---------------------------------------------------------------------*
*& Form create_event_exits
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM create_event_exits .
g_event -name = 'CALLER_EXIT' .
g_event - form = 'CALLER_EXIT' .
APPEND g_event TO g_events .
ENDFORM . "create_event_exits
*&---------------------------------------------------------------------*
*& Form CALLER_EXIT
*&---------------------------------------------------------------------*
FORM caller_exit USING ls_data TYPE slis_data_caller_exit .
DATA : l_ref_alv TYPE REF TO cl_gui_alv_grid ,
l_ref_handler TYPE REF TO lcl_event_handlers .
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_ref_alv .
CALL METHOD l_ref_alv ->set_drop_down_table
EXPORTING
it_drop_down = g_t_ddval .
CREATE OBJECT l_ref_handler .
SET HANDLER l_ref_handler ->handle_button_click FOR l_ref_alv .
ENDFORM . "CALLER_EXIT
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* populate layout
*----------------------------------------------------------------------*
FORM build_layout .
w_layout -stylefname = 'CELLSTYLE' .
w_layout -zebra = 'X' .
w_layout -box_fname = 'SEL' .
ENDFORM . " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* display alv report
*----------------------------------------------------------------------*
FORM display_alv_report .
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
* EXPORTING
* i_callback_program = sy-repid
* i_callback_user_command = 'USER_COMMAND'
* is_layout = g_layout
* it_fieldcat = it_fieldcatalog
** i_save = 'X'
* TABLES
* t_outtab = it_ekko
* EXCEPTIONS
* program_error = 1
* OTHERS = 2.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy -repid
is_layout_lvc = w_layout
it_events = g_events
i_callback_user_command = 'USER_COMMAND'
it_fieldcat_lvc = it_fieldcatalog
TABLES
t_outtab = it_ekko[] .
ENDFORM . " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* USER-COMMAND
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy -ucomm
rs_selfield TYPE slis_selfield .
*>Check function code
CASE r_ucomm .
WHEN '&IC1' .
*>Check field clicked on within alv grid report
IF rs_selfield -fieldname = 'EBELN' .
READ TABLE it_ekko INDEX rs_selfield -tabindex .
SET PARAMETER ID 'BES' FIELD it_ekko -ebeln .
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN .
ENDIF .
* IF rs_selfield-fieldname = 'SEL'.
* READ TABLE it_ekko INDEX rs_selfield-tabindex.
* it_ekko-sel = 'X'.
* MODIFY it_ekko.
* ENDIF.
WHEN '&DATA_SAVE' .
LOOP AT it_ekko .
IF it_ekko -sel EQ 'X' .
WRITE : / it_ekko -ebeln .
ENDIF .
ENDLOOP .
* LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 1000.
ENDCASE .
rs_selfield - refresh = 'X' .
ENDFORM . "user_command