METHOD itemset_get_entityset.
FIELD-SYMBOLS: <s_entityset> TYPE cl_far_customer_line_i_mpc=>ts_item.
CONSTANTS: c_top TYPE i VALUE 1000000.
* Get Information about Request Context (IO_TECH_REQUEST_CONTEXT)
DATA(request_context) = CAST /iwbep/cl_mgw_request( io_tech_request_context ).
DATA(model) = request_context->get_model( ).
DATA(wt_headers) = request_context->get_request_headers( ).
DATA(ws_request_details) = request_context->get_request_details( ).
* Delete custom filter proprties that not supported by standard data provider
delete_filter_properties(
EXPORTING
it_field_name = VALUE #( ( CONV string( 'AmountType' ) )
( CONV string( 'AgingGroup' ) ) )
CHANGING
cs_request_details = ws_request_details ).
DATA(wt_filter_select_options) = it_filter_select_options.
DELETE wt_filter_select_options WHERE property = 'AmountType'
OR property = 'AgingGroup'.
* Check if totals are read
DATA(w_total) = is_total( is_request_details = ws_request_details
io_model = model ).
* Check if custom properties totals or filters required
IF ( w_total = abap_true ) AND
( line_exists( ws_request_details-select_params[ table_line = 'AmountInvoice' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountDeduction' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountCredit' ] ) OR
line_exists( it_filter_select_options[ property = 'AmountType' ] ) OR
line_exists( it_filter_select_options[ property = 'AgingGroup' ] ) ).
* Add standard fields that are required to calculate custom fields totals
add_select_properties(
EXPORTING
it_field_name = VALUE #( ( CONV string( 'COMPANYCODE' ) )
( CONV string( 'ACCOUNTINGDOCUMENT' ) )
( CONV string( 'FISCALYEAR' ) )
( CONV string( 'ACCOUNTINGDOCUMENTITEM' ) )
( CONV string( 'VH_COMPANYCODECURRENCY' ) )
( CONV string( 'VH_ACCOUNTINGDOCUMENTTYPE' ) )
( CONV string( 'VH_AMOUNTINCOMPANYCODECURRENCY' ) )
( CONV string( 'NETDUEARREARSDAYS' ) ) )
CHANGING
cs_request_details = ws_request_details ).
* Change paging to read all line information at document item level
DATA(ws_paging) = VALUE /iwbep/s_mgw_paging( skip = 0
top = c_top ).
ws_request_details-paging = VALUE #( skip = 0
top = c_top ).
* Create modified Request Context (IO_TECH_REQUEST_CONTEXT)
DATA(tech_request_context) =
NEW /iwbep/cl_mgw_request(
ir_request_details = ref #( ws_request_details )
it_headers = wt_headers
io_model = model ).
* Get entity set
super->itemset_get_entityset(
EXPORTING
iv_entity_name = iv_entity_name
iv_entity_set_name = iv_entity_set_name
iv_source_name = iv_source_name
it_filter_select_options = wt_filter_select_options
is_paging = ws_paging
it_key_tab = it_key_tab
it_navigation_path = it_navigation_path
it_order = it_order
iv_filter_string = iv_filter_string
iv_search_string = iv_search_string
io_tech_request_context = tech_request_context
IMPORTING
et_entityset = et_entityset
es_response_context = es_response_context ).
LOOP AT et_entityset ASSIGNING <s_entityset>.
* Apply custom properties filter
IF line_exists( it_filter_select_options[ property = 'AmountType' ] ).
IF get_amount_type( <s_entityset> ) NOT IN it_filter_select_options[ property = 'AmountType' ]-select_options.
DELETE et_entityset.
CONTINUE.
ENDIF.
ENDIF.
IF line_exists( it_filter_select_options[ property = 'AgingGroup' ] ).
IF get_aging_group( <s_entityset> ) NOT IN it_filter_select_options[ property = 'AgingGroup' ]-select_options.
DELETE et_entityset.
CONTINUE.
ENDIF.
ENDIF.
* Calculate custom properties
<s_entityset>-amountinvoice = get_amount_invoice( <s_entityset> ).
<s_entityset>-amountdeduction = get_amount_deduction( <s_entityset> ).
<s_entityset>-amountcredit = get_amount_credit( <s_entityset> ).
ENDLOOP.
* Calculate totals
get_total(
EXPORTING
is_request_details = ws_request_details
it_entityset = et_entityset
io_model = model
IMPORTING
et_entityset = DATA(wt_entityset_total) ).
ENDIF.
* Getting information about Request Context (IO_TECH_REQUEST_CONTEXT) again
request_context = cast /iwbep/cl_mgw_request( io_tech_request_context ).
ws_request_details = request_context->get_request_details( ).
* Delete custom properties filtering
delete_filter_properties(
EXPORTING
it_field_name = VALUE #( ( CONV string( 'AmountType' ) )
( CONV string( 'AgingGroup' ) ) )
CHANGING
cs_request_details = ws_request_details ).
* Check if custom fields are requested
IF ( line_exists( ws_request_details-select_params[ table_line = 'AmountInvoice' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountDeduction' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountCredit' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountType' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AgingGroup' ] ) OR
line_exists( it_filter_select_options[ property = 'AmountType' ] ) OR
line_exists( it_filter_select_options[ property = 'AgingGroup' ] ) ) AND
w_total = abap_false.
* Add standard fields that are required for custome fields calculation
add_select_properties(
EXPORTING
it_field_name = VALUE #( ( CONV string( 'COMPANYCODE' ) )
( CONV string( 'ACCOUNTINGDOCUMENT' ) )
( CONV string( 'FISCALYEAR' ) )
( CONV string( 'ACCOUNTINGDOCUMENTITEM' ) )
( CONV string( 'VH_ACCOUNTINGDOCUMENTTYPE' ) )
( CONV string( 'VH_AMOUNTINCOMPANYCODECURRENCY' ) )
( CONV string( 'NETDUEARREARSDAYS' ) ) )
CHANGING
cs_request_details = ws_request_details ).
ENDIF.
ws_paging = is_paging.
* Read all data before applying custom property filters
IF w_total = abap_false AND ( line_exists( it_filter_select_options[ property = 'AmountType' ] ) OR
line_exists( it_filter_select_options[ property = 'AgingGroup' ] ) ).
ws_paging = VALUE #( skip = 0
top = c_top ).
ws_request_details-paging = VALUE #( skip = 0
top = c_top ).
ENDIF.
* Create modified Request Context (IO_TECH_REQUEST_CONTEXT)
tech_request_context =
NEW /iwbep/cl_mgw_request(
ir_request_details = REF #( ws_request_details )
it_headers = wt_headers
io_model = model ).
* Get entity set
super->itemset_get_entityset(
EXPORTING
iv_entity_name = iv_entity_name
iv_entity_set_name = iv_entity_set_name
iv_source_name = iv_source_name
it_filter_select_options = wt_filter_select_options
is_paging = ws_paging
it_key_tab = it_key_tab
it_navigation_path = it_navigation_path
it_order = it_order
iv_filter_string = iv_filter_string
iv_search_string = iv_search_string
io_tech_request_context = tech_request_context
IMPORTING
et_entityset = et_entityset
es_response_context = es_response_context ).
*
LOOP AT et_entityset ASSIGNING <s_entityset>.
* Apply customer properties filter
IF w_total = abap_false AND line_exists( it_filter_select_options[ property = 'AmountType' ] ).
IF get_amount_type( <s_entityset> ) NOT IN it_filter_select_options[ property = 'AmountType' ]-select_options.
DELETE et_entityset.
CONTINUE.
ENDIF.
ENDIF.
IF w_total = abap_false AND line_exists( it_filter_select_options[ property = 'AgingGroup' ] ).
IF get_aging_group( <s_entityset> ) NOT IN it_filter_select_options[ property = 'AgingGroup' ]-select_options.
DELETE et_entityset.
CONTINUE.
ENDIF.
ENDIF.
IF line_exists( ws_request_details-select_params[ table_line = 'AmountType' ] ).
<s_entityset>-amounttype = get_amount_type( <s_entityset> ).
ENDIF.
IF line_exists( ws_request_details-select_params[ table_line = 'AgingGroup' ] ).
<s_entityset>-aginggroup = get_aging_group( <s_entityset> ).
ENDIF.
IF ( w_total = abap_false ) AND
( line_exists( ws_request_details-select_params[ table_line = 'AmountInvoice' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountDeduction' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountCredit' ] ) ).
<s_entityset>-amountinvoice = get_amount_invoice( <s_entityset> ).
<s_entityset>-amountdeduction = get_amount_deduction( <s_entityset> ).
<s_entityset>-amountcredit = get_amount_credit( <s_entityset> ).
ENDIF.
IF ( w_total = abap_true ) AND
( line_exists( ws_request_details-select_params[ table_line = 'AmountInvoice' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountDeduction' ] ) OR
line_exists( ws_request_details-select_params[ table_line = 'AmountCredit' ] ) OR
line_exists( it_filter_select_options[ property = 'AmountType' ] ) OR
line_exists( it_filter_select_options[ property = 'AgingGroup' ] ) ).
map_total(
EXPORTING
is_request_details = ws_request_details
it_entityset = wt_entityset_total
it_filter_select_options = it_filter_select_options
io_model = model
CHANGING
cs_entityset = <s_entityset> ).
ENDIF.
ENDLOOP.
IF w_total = abap_false AND ( line_exists( it_filter_select_options[ property = 'AmountType' ] ) OR
line_exists( it_filter_select_options[ property = 'AgingGroup' ] ) ).
* Change inline count after applying custom properties filter
es_response_context-inlinecount = LINES( et_entityset ).
* Return only portion of data requested by client after applying custom properties filter
DATA(wt_entityset) = et_entityset.
CLEAR: et_entityset.
APPEND LINES OF wt_entityset
FROM ( is_paging-skip + 1 ) TO ( is_paging-skip + is_paging-top )
TO et_entityset.
ENDIF.
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |