EntitySet通用技巧
EntitySet通用排序
#SAP/Fiori/Segw/EntitySet通用排序
/iwbep/cl_mgw_data_util=>orderby( EXPORTING it_order = it_order CHANGING ct_data = et_entityset ).
SELECT * INTO TABLE @DATA(lt_etfields) FROM /IWBEP/I_SBO_PR
WHERE PARENT_UUID IN
( SELECT NODE_UUID FROM /IWBEP/I_SBO_ET WHERE PROJECT = 'ZCA90_TR_TRANS_ORDER' AND NAME = @IV_ENTITY_NAME ).
*"排序表动态排序
data:lt_sorted_table type abap_sortorder_tab.
LOOP AT IT_ORDER ASSIGNING FIELD-SYMBOL(<fs_order>).
READ TABLE lt_etfields INTO DATA(ls_etfield) WITH KEY NAME = <fs_order>-property.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
APPEND INITIAL LINE TO lt_sorted_table ASSIGNING FIELD-SYMBOL(<fs_sorted>).
<fs_sorted>-name = ls_etfield-abap_field.
CASE ls_etfield-EDM_CORE_TYPE.
WHEN 'Edm.DateTime' OR 'Edm.Time'.
<fs_sorted>-astext = abap_false.
WHEN OTHERS.
<fs_sorted>-astext = abap_true.
ENDCASE.
IF <fs_order>-order = 'desc'.
<fs_sorted>-descending = abap_true.
ELSE.
<fs_sorted>-descending = abap_false.
ENDIF.
ENDLOOP.
SORT et_entityset BY (lt_sorted_table).
EntitySet通用Filter(动态Where)
#SAP/Fiori/Segw/EntitySet通用Filter过滤
DATA: ls_selection TYPE /bobf/s_frw_query_selparam.
DATA: lr_range TYPE REF TO data.
DATA: lt_result TYPE /rer/t_ps_land_key_info_k,
lt_key TYPE /bobf/t_frw_key,
lt_selection_parameters TYPE /bobf/t_frw_query_selparam,
lt_where TYPE STANDARD TABLE OF string,
lt_range TYPE REF TO data.
FIELD-SYMBOLS:
<fs_selection_parameters> TYPE /bobf/s_frw_query_selparam,
<ls_range> TYPE any,
<fs_result> TYPE /rer/s_ps_land_key_info_k.
DATA(lt_filters) = io_tech_request_context->get_filter( )->get_filter_select_options( ).
LOOP AT lt_filters INTO DATA(ls_filters).
* CASE ls_filters-property.
* WHEN 'DEMAND_FROM'. DATA(lr_demand_from) = ls_filters-select_options.
* ENDCASE.
LOOP AT ls_filters-select_options INTO DATA(ls_sel_options).
MOVE-CORRESPONDING ls_sel_options TO ls_selection.
ls_selection-attribute_name = ls_filters-property.
APPEND ls_selection TO lt_selection_parameters.
ENDLOOP.
ENDLOOP.
CALL METHOD /srmerp/cl_bopf_helper=>create_where_clause_from_param
EXPORTING
it_selection_parameters = lt_selection_parameters
iv_check_user = abap_false
IMPORTING
et_where_clause = lt_where
er_range = lr_range
etr_range = lt_range.
ASSIGN lr_range->* TO <ls_range>.
SELECT * INTO CORRESPONDING FIELDS OF TABLE et_entityset FROM zca90t_004
WHERE (lt_where).
分页
/iwbep/cl_mgw_data_util=>paging( EXPORTING is_paging = is_paging CHANGING ct_data = et_entityset ).
DATA(lv_offset) = is_paging-top * ( is_paging-skip - 1 ).
SELECT COUNT(*) FROM zca90t_004 WHERE (lt_where).
es_response_context-inlinecount = sy-dbcnt.
IF lv_offset > 0.
SELECT * FROM zca90t_004
WHERE (lt_where)
ORDER BY req_id
INTO CORRESPONDING FIELDS OF TABLE @et_entityset
OFFSET @lv_offset UP TO @is_paging-top ROWS
.
ELSE.
SELECT * FROM zca90t_004
WHERE (lt_where)
ORDER BY req_id
INTO CORRESPONDING FIELDS OF TABLE @et_entityset
UP TO @is_paging-top ROWS
.
ENDIF.
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Hblog!