*----------------------------------------------------------------------* * *----------------------------------------------------------------------* TYPE-POOLS: slis. TABLES: mara. DATA: gt_data TYPE TABLE OF mara WITH HEADER LINE, gv_matnr TYPE mara-matnr. CONSTANTS: gc_form_top TYPE slis_formname VALUE 'DO_HTML_TOP_OF_PAGE'. *----------------------------------------------------------------------* * CLASS cl_my_event_handler DEFINITION *----------------------------------------------------------------------* CLASS cl_my_event_handler DEFINITION. PUBLIC SECTION. METHODS: handle_selections FOR EVENT selected OF cl_dd_select_element IMPORTING sender. ENDCLASS. DATA: go_hand1 TYPE REF TO cl_my_event_handler.
*----------------------------------------------------------------------* * *----------------------------------------------------------------------* SELECT-OPTIONS: so_matnr FOR mara-matnr. INITIALIZATION. PERFORM init. START-OF-SELECTION. PERFORM get_data. END-OF-SELECTION. PERFORM reuse_alv. *&---------------------------------------------------------------------* *& Form init *&---------------------------------------------------------------------* FORM init. " -------------------------------------------------- " " " -------------------------------------------------- " CREATE OBJECT go_hand1. ENDFORM. *&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* FORM get_data. " -------------------------------------------------- " " " -------------------------------------------------- " SELECT * FROM mara INTO TABLE gt_data WHERE matnr IN so_matnr. CHECK: sy-subrc IS INITIAL. SORT: gt_data BY matnr. ENDFORM. "get_data *&---------------------------------------------------------------------* *& Form reuse_alv *&---------------------------------------------------------------------* FORM reuse_alv. DATA: lt_fieldcat TYPE TABLE OF lvc_s_fcat. CHECK gt_data[] IS NOT INITIAL. " -------------------------------------------------- " " ALV " -------------------------------------------------- " CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'MARA' CHANGING ct_fieldcat = lt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid i_callback_html_top_of_page = gc_form_top it_fieldcat_lvc = lt_fieldcat[] i_save = 'A' TABLES t_outtab = gt_data[]. ENDFORM. "reuse_alv
*&---------------------------------------------------------------------* *& Form do_html_top_of_page *&---------------------------------------------------------------------* FORM do_html_top_of_page USING p_doc TYPE REF TO cl_dd_document. DATA: lo_form TYPE REF TO cl_dd_form_area, lo_sele TYPE REF TO cl_dd_select_element. " -------------------------------------------------- " " " -------------------------------------------------- " CALL METHOD p_doc->add_form IMPORTING formarea = lo_form. " -------------------------------------------------- " " - " -------------------------------------------------- " PERFORM add_casebox TABLES gt_data CHANGING gv_matnr lo_form lo_sele. ENDFORM. "do_html_top_of_page
*&---------------------------------------------------------------------* *& Form add_casebox *&---------------------------------------------------------------------* FORM add_casebox *&---------------------------------------------------------------------* TABLES it_data STRUCTURE mara CHANGING iv_matnr TYPE mara-matnr lo_form TYPE REF TO cl_dd_form_area lo_selec TYPE REF TO cl_dd_select_element. *&---------------------------------------------------------------------* DATA: lt_opt_tab TYPE sdydo_option_tab, lv_text TYPE sdydo_text_element. *----------------------------------------------------------------------* DO. CASE sy-index. WHEN 1. " -------------------------------------------------- " " " -------------------------------------------------- " CHECK sy-ucomm EQ '&ILD'. CLEAR: iv_matnr. WHEN 2. " -------------------------------------------------- " " " -------------------------------------------------- " CALL METHOD lo_form->line_with_layout EXPORTING start = 'X'. WHEN 3. " -------------------------------------------------- " " - " -------------------------------------------------- " lv_text = ':'. CALL METHOD lo_form->add_text EXPORTING text = lv_text. WHEN 4. " -------------------------------------------------- " " " -------------------------------------------------- " CALL METHOD lo_form->add_gap EXPORTING width = 2. WHEN 5. " -------------------------------------------------- " " " -------------------------------------------------- " PERFORM fill_mat_tab TABLES it_data CHANGING iv_matnr lt_opt_tab. WHEN 6. " -------------------------------------------------- " " - " -------------------------------------------------- " CALL METHOD lo_form->add_select_element EXPORTING OPTIONS = lt_opt_tab value = 'P' IMPORTING select_element = lo_selec. WHEN 7. " -------------------------------------------------- " " " -------------------------------------------------- " SET HANDLER go_hand1->handle_selections FOR lo_selec. WHEN 8. " -------------------------------------------------- " " " -------------------------------------------------- " CALL METHOD lo_form->line_with_layout EXPORTING end = 'X'. WHEN OTHERS. EXIT. ENDCASE. ENDDO. ENDFORM.
*&---------------------------------------------------------------------* *& Form fill_mat_tab *&---------------------------------------------------------------------* FORM fill_mat_tab *&---------------------------------------------------------------------* TABLES it_data STRUCTURE mara CHANGING iv_matnr TYPE matnr it_optab TYPE sdydo_option_tab. *&---------------------------------------------------------------------* DATA: ls_opt TYPE sdydo_option. REFRESH: it_optab. *----------------------------------------------------------------------* DO. CASE sy-index. WHEN 1. " -------------------------------------------------- " " " -------------------------------------------------- " CHECK iv_matnr IS NOT INITIAL. ls_opt-value = iv_matnr. ls_opt-text = iv_matnr. APPEND ls_opt TO it_optab. WHEN 2. " -------------------------------------------------- " " , - " -------------------------------------------------- " READ TABLE it_data INDEX 1. LOOP AT it_data TRANSPORTING NO FIELDS WHERE matnr NE it_data-matnr. ls_opt-value = '*'. ls_opt-text = ''. APPEND ls_opt TO it_optab. EXIT. ENDLOOP. WHEN 3. " -------------------------------------------------- " " " -------------------------------------------------- " LOOP AT it_data WHERE matnr IS NOT INITIAL. ls_opt-value = it_data-matnr. ls_opt-text = it_data-matnr. COLLECT ls_opt INTO it_optab. ENDLOOP. WHEN OTHERS. EXIT. ENDCASE. ENDDO. ENDFORM.
*----------------------------------------------------------------------* * CLASS cl_my_event_handler IMPLEMENTATION *----------------------------------------------------------------------* CLASS cl_my_event_handler IMPLEMENTATION. METHOD handle_selections. DATA text_buff TYPE sdydo_text_element. text_buff = sender->value. gv_matnr = text_buff. " -------------------------------------------------- " " " -------------------------------------------------- " PERFORM set_filter TABLES gt_data USING gv_matnr . ENDMETHOD. "handle_selections ENDCLASS. "cl_my_event_handler IMPLEMENTATION *&---------------------------------------------------------------------* *& Form set_filter *&---------------------------------------------------------------------* FORM set_filter *&---------------------------------------------------------------------* TABLES it_data STRUCTURE mara USING iv_value TYPE mara-matnr. *&---------------------------------------------------------------------* DATA: lo_ref1 TYPE REF TO cl_gui_alv_grid, lt_filtered TYPE lvc_t_filt, lv_field TYPE char10 VALUE 'MATNR', ls_filter LIKE LINE OF lt_filtered. *----------------------------------------------------------------------* DO. CASE sy-index. WHEN 1. " -------------------------------------------------- " " ALV " -------------------------------------------------- " CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = lo_ref1. WHEN 2. " -------------------------------------------------- " " . " -------------------------------------------------- " CALL METHOD lo_ref1->get_filter_criteria IMPORTING et_filter = lt_filtered. DELETE lt_filtered WHERE fieldname = lv_field. WHEN 3. " -------------------------------------------------- " " " -------------------------------------------------- " CHECK iv_value NE '' AND iv_value NE '*'. ls_filter-fieldname = lv_field. ls_filter-sign = 'I'. ls_filter-option = 'EQ'. ls_filter-low = iv_value. APPEND ls_filter TO lt_filtered. WHEN 4. " -------------------------------------------------- " " " -------------------------------------------------- " CALL METHOD lo_ref1->set_filter_criteria EXPORTING it_filter = lt_filtered EXCEPTIONS no_fieldcatalog_available = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. WHEN 5. " -------------------------------------------------- " " ALV " -------------------------------------------------- " lo_ref1->refresh_table_display( ). WHEN OTHERS. EXIT. ENDCASE. ENDDO. ENDFORM.
Source: https://habr.com/ru/post/275677/
All Articles