From 30ec9ee23cb9fdaaef54a601af96559770bd1398 Mon Sep 17 00:00:00 2001 From: Bernd <135710507+darnoc312@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:47:50 +0200 Subject: [PATCH] Update zcl_excel_converter_alv.clas.abap Method get_filter --- .../zcl_excel_converter_alv.clas.abap | 167 ++++++++++-------- 1 file changed, 97 insertions(+), 70 deletions(-) diff --git a/src/not_cloud/zcl_excel_converter_alv.clas.abap b/src/not_cloud/zcl_excel_converter_alv.clas.abap index c44a423..c9c3af5 100644 --- a/src/not_cloud/zcl_excel_converter_alv.clas.abap +++ b/src/not_cloud/zcl_excel_converter_alv.clas.abap @@ -387,99 +387,126 @@ CLASS zcl_excel_converter_alv IMPLEMENTATION. METHOD get_filter. - DATA: ls_filt TYPE lvc_s_filt, - l_line TYPE i, - ls_filter TYPE zexcel_s_converter_fil. - DATA: lo_addit TYPE REF TO cl_abap_elemdescr, + TYPES: BEGIN OF ts_field_range, + fieldname TYPE fieldname, + range_tab TYPE REF TO data, + END OF ts_field_range. + + DATA: ls_filt LIKE LINE OF wt_filt, + ls_filter TYPE zexcel_s_converter_fil, + lo_addit TYPE REF TO cl_abap_elemdescr, lt_components_tab TYPE cl_abap_structdescr=>component_table, ls_components TYPE abap_componentdescr, lo_table TYPE REF TO cl_abap_tabledescr, lo_struc TYPE REF TO cl_abap_structdescr, - lo_trange TYPE REF TO data, - lo_srange TYPE REF TO data, - lo_ltabdata TYPE REF TO data. + lt_field_range TYPE TABLE OF ts_field_range, + ls_field_range LIKE LINE OF lt_field_range, + lv_fieldname TYPE fieldname. FIELD-SYMBOLS: TYPE STANDARD TABLE, - TYPE STANDARD TABLE, TYPE any, TYPE any, - TYPE any, TYPE any, - TYPE STANDARD TABLE. + TYPE STANDARD TABLE, + LIKE LINE OF lt_field_range. - IF ws_option-filter = abap_false. - CLEAR et_filter. + CLEAR et_filter. + IF wt_filt IS INITIAL OR + ws_option-filter = abap_false. RETURN. ENDIF. ASSIGN xo_table->* TO . + READ TABLE ASSIGNING INDEX 1. + IF sy-subrc <> 0. + RETURN. + ENDIF. - CREATE DATA lo_ltabdata LIKE . - ASSIGN lo_ltabdata->* TO . + SORT wt_filt BY fieldname. +* Range creation and range comparison must be done in two steps: +* This is due to the fact, that range values might be applied +* all together at once not value after value for a specific fieldname +* --> Having multiple excluding values is a problem that would otherwise +* occur... + +* 1. Step: Create the combined ranges for each fieldname... LOOP AT wt_filt INTO ls_filt. - LOOP AT ASSIGNING . - l_line = sy-tabix. + IF ls_filt-fieldname <> lv_fieldname. + lv_fieldname = ls_filt-fieldname. + UNASSIGN . ASSIGN COMPONENT ls_filt-fieldname OF STRUCTURE TO . - IF sy-subrc = 0. - IF l_line = 1. - CLEAR lt_components_tab. - ls_components-name = 'SIGN'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-sign ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - ls_components-name = 'OPTION'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-option ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - ls_components-name = 'LOW'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - ls_components-name = 'HIGH'. - lo_addit ?= cl_abap_typedescr=>describe_by_data( ). - ls_components-type = lo_addit . - INSERT ls_components INTO TABLE lt_components_tab. - "create new line type - TRY. - lo_struc = cl_abap_structdescr=>create( p_components = lt_components_tab - p_strict = abap_false ). - CATCH cx_sy_struct_creation. - CONTINUE. - ENDTRY. - lo_table = cl_abap_tabledescr=>create( lo_struc ). + CHECK sy-subrc = 0. - CREATE DATA lo_trange TYPE HANDLE lo_table. - CREATE DATA lo_srange TYPE HANDLE lo_struc. + IF lt_components_tab IS INITIAL. + ls_components-name = 'SIGN'. + lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-sign ). + ls_components-type = lo_addit. + APPEND ls_components TO lt_components_tab. + ls_components-name = 'OPTION'. + lo_addit ?= cl_abap_typedescr=>describe_by_data( ls_filt-option ). + ls_components-type = lo_addit. + APPEND ls_components TO lt_components_tab. + ELSE. + DELETE lt_components_tab FROM 3. + ENDIF. - ASSIGN lo_trange->* TO . - ASSIGN lo_srange->* TO . - ENDIF. - CLEAR . - ASSIGN COMPONENT 'SIGN' OF STRUCTURE TO . - = ls_filt-sign. - ASSIGN COMPONENT 'OPTION' OF STRUCTURE TO . - = ls_filt-option. - ASSIGN COMPONENT 'LOW' OF STRUCTURE TO . - = ls_filt-low. - ASSIGN COMPONENT 'HIGH' OF STRUCTURE TO . - = ls_filt-high. - INSERT INTO TABLE . - IF IN . - IF ws_option-filter = abap_true. - ls_filter-rownumber = l_line. - ls_filter-columnname = ls_filt-fieldname. - INSERT ls_filter INTO TABLE et_filter. - ELSE. - INSERT INTO TABLE . - ENDIF. + lo_addit ?= cl_abap_typedescr=>describe_by_data( ). + ls_components-type = lo_addit. + + ls_components-name = 'LOW'. + APPEND ls_components TO lt_components_tab. + ls_components-name = 'HIGH'. + APPEND ls_components TO lt_components_tab. + "create new line type + TRY. + lo_struc = cl_abap_structdescr=>create( p_components = lt_components_tab + p_strict = abap_false ). + CATCH cx_sy_struct_creation. + CONTINUE. + ENDTRY. + lo_table = cl_abap_tabledescr=>create( lo_struc ). + + ls_field_range-fieldname = ls_filt-fieldname. + CREATE DATA ls_field_range-range_tab TYPE HANDLE lo_table. + APPEND ls_field_range TO lt_field_range. + + ASSIGN ls_field_range-range_tab->* TO . + ELSE. + CHECK IS ASSIGNED. + ENDIF. + + APPEND INITIAL LINE TO ASSIGNING . + ASSIGN COMPONENT 'SIGN' OF STRUCTURE TO . + = ls_filt-sign. + ASSIGN COMPONENT 'OPTION' OF STRUCTURE TO . + = ls_filt-option. + ASSIGN COMPONENT 'LOW' OF STRUCTURE TO . + = ls_filt-low. + ASSIGN COMPONENT 'HIGH' OF STRUCTURE TO . + = ls_filt-high. + ENDLOOP. + + IF lt_field_range IS INITIAL. + RETURN. + ENDIF. + +* 2. Step: Now apply the fieldname ranges afterwards... + LOOP AT ASSIGNING . + ls_filter-rownumber = sy-tabix. + LOOP AT lt_field_range ASSIGNING . + ASSIGN COMPONENT -fieldname OF STRUCTURE TO . + ASSIGN -range_tab->* TO . + IF IN . + IF ws_option-filter = abap_true. + ls_filter-columnname = -fieldname. + INSERT ls_filter INTO TABLE et_filter. ENDIF. + ELSEIF ws_option-filter = abap_undefined. + DELETE . + EXIT. "--> next xo_table line ENDIF. ENDLOOP. - IF ws_option-filter = abap_undefined. - = . - CLEAR . - ENDIF. ENDLOOP. ENDMETHOD.