@EndUserText.label: 'ApproverId Value Help Custom Entity'
@ObjectModel.dataCategory: #VALUE_HELP
@Search.searchable: true
@ObjectModel.query.implementedBy: 'ABAP:ZCL_APPROVERID_VHLP_SIMPLE'
define custom entity ZC_APPROVERID_VHLP_CE_SIMPLE {
@Search: { defaultSearchElement: true, ranking: #HIGH, fuzzinessThreshold: 0.8 }
@ObjectModel.text.element: ['Name']
key EMailAddress : zemailaddress;
@Semantics.text: true
@Search.defaultSearchElement: true
Name : zbusiness_partner_full_name;
CompanyCode : zcompany_code;
}
CLASS zcl_approverid_vhlp_simple DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_rap_query_provider .
PROTECTED SECTION.
PRIVATE SECTION.
TYPES ty_gt_value_help_entry TYPE STANDARD TABLE OF zc_approverid_vhlp_ce_simple WITH DEFAULT KEY.
TYPES ty_gt_emailaddress_range TYPE RANGE OF zc_approverid_vhlp_ce_simple-EMailAddress.
TYPES ty_gt_name_range TYPE RANGE OF zc_approverid_vhlp_ce_simple-Name.
TYPES ty_gt_company_code_range TYPE RANGE OF zc_approverid_vhlp_ce_simple-CompanyCode.
TYPES ty_gts_allowed_appr_emails TYPE SORTED TABLE OF zc_approverid_vhlp_ce_simple-EMailAddress WITH UNIQUE KEY table_line.
METHODS determine_allowed_approvers
IMPORTING
it_emailaddress_range TYPE ty_gt_emailaddress_range
it_name_range TYPE ty_gt_name_range
it_company_code_range TYPE ty_gt_company_code_range
io_paging TYPE REF TO if_rap_query_paging
it_sort_elements TYPE if_rap_query_request=>tt_sort_elements
iv_search_expression TYPE string
RETURNING
VALUE(rt_value_help_entries) TYPE ty_gt_value_help_entry.
METHODS get_allowed_apprvs_via_http
IMPORTING
it_emailaddress_range TYPE ty_gt_emailaddress_range
it_company_code_range TYPE ty_gt_company_code_range
io_paging TYPE REF TO if_rap_query_paging
it_sort_elements TYPE if_rap_query_request=>tt_sort_elements
RETURNING
VALUE(rt_allowed_approvers_emails) TYPE ty_gts_allowed_appr_emails.
METHODS get_provided_ranges
IMPORTING io_request TYPE REF TO if_rap_query_request
EXPORTING
et_emailaddress_range TYPE ty_gt_emailaddress_range
et_name_range TYPE ty_gt_name_range
et_company_code_range TYPE ty_gt_company_code_range
RAISING cx_rap_query_prov_not_impl
cx_rap_query_provider.
METHODS process_descr_only_request
IMPORTING
it_emailaddress_range TYPE ty_gt_emailaddress_range
io_response TYPE REF TO if_rap_query_response.
METHODS is_descriptions_only_request
IMPORTING
it_emailaddress_range TYPE ty_gt_emailaddress_range
it_name_range TYPE ty_gt_name_range
it_company_code_range TYPE ty_gt_company_code_range
RETURNING
VALUE(rv_is_descr_only_request) TYPE abap_bool
RAISING cx_rap_query_prov_not_impl
cx_rap_query_provider.
ENDCLASS.
CLASS zcl_approverid_vhlp_simple IMPLEMENTATION.
METHOD if_rap_query_provider~select.
DATA lt_value_help_entries TYPE STANDARD TABLE OF zc_approverid_vhlp_ce_simple .
DATA ls_value_help_entry TYPE zc_approverid_vhlp_ce_simple.
DATA(lo_paging) = io_request->get_paging( ).
DATA(lt_sort_elements) = io_request->get_sort_elements( ) .
"io_request->get_requested_elements( ) --> could be used for optimizations
DATA(lv_search_expression) = io_request->get_search_expression( )."Basic search term
get_provided_ranges(
EXPORTING
io_request = io_request
IMPORTING
et_emailaddress_range = DATA(lt_emailaddress_range)
et_name_range = DATA(lt_name_range)
et_company_code_range = DATA(lt_companycode_range)
).
IF is_descriptions_only_request(
it_emailaddress_range = lt_emailaddress_range
it_name_range = lt_name_range
it_company_code_range = lt_companycode_range ).
process_descr_only_request(
it_emailaddress_range = lt_emailaddress_range
io_response = io_response ).
ELSE.
if lt_companycode_range is not initial.
lt_value_help_entries = determine_allowed_approvers(
it_emailaddress_range = lt_emailaddress_range
it_name_range = lt_name_range
it_company_code_range = lt_companycode_range
io_paging = lo_paging
it_sort_elements = lt_sort_elements
iv_search_expression = lv_search_expression ).
endif.
io_response->set_data( lt_value_help_entries ).
io_response->set_total_number_of_records( lines( lt_value_help_entries ) ).
ENDIF.
**********************************************************************
* How to implement exception handling:
* "! @raising cx_rap_query_prov_not_impl | Should be raised if the provider lacks the ability to fulfill the request at hand
* "! in its current state of implementation.
* "! @raising cx_rap_query_provider | General failure. Must be raised if an error prevents successful query processing.
**********************************************************************
ENDMETHOD.
METHOD determine_allowed_approvers.
TYPES ty_gts_email_address TYPE STANDARD TABLE OF zc_approverid_vhlp_ce_simple-emailaddress.
DATA lt_allowed_approvers_emails TYPE ty_gts_email_address.
DATA ls_value_help_entry TYPE zc_approverid_vhlp_ce_simple.
**********************************************************************
* HTTP call to SAP BTP service for allowed approvers
**********************************************************************
lt_allowed_approvers_emails = get_allowed_apprvs_via_http(
it_emailaddress_range = it_emailaddress_range
it_company_code_range = it_company_code_range
io_paging = io_paging
it_sort_elements = it_sort_elements
)."Note: for simplicity reasons we do not respect name filtering and we do ignore the search expression
**********************************************************************
IF lt_allowed_approvers_emails IS NOT INITIAL."enrich with name
SELECT FROM zemployee_details FIELDS emailaddress, name
FOR ALL ENTRIES IN @lt_allowed_approvers_emails
WHERE
emailaddress = @lt_allowed_approvers_emails-table_line
INTO TABLE @DATA(lt_allowed_vhlp_entries) .
LOOP AT lt_allowed_vhlp_entries REFERENCE INTO DATA(lr_allowed_vhlp_entry).
MOVE-CORRESPONDING lr_allowed_vhlp_entry->* TO ls_value_help_entry.
INSERT ls_value_help_entry INTO TABLE rt_value_help_entries.
ENDLOOP.
ENDIF.
ENDMETHOD.
METHOD get_provided_ranges.
TRY.
DATA(lt_ranges) = io_request->get_filter( )->get_as_ranges( ).
LOOP AT lt_ranges REFERENCE INTO DATA(lr_range).
CASE lr_range->name.
WHEN 'EMAILADDRESS'.
LOOP AT lr_range->range REFERENCE INTO DATA(lr_range_entry).
INSERT VALUE #( sign = lr_range_entry->sign option = lr_range_entry->option
low = CONV #( lr_range_entry->low ) high = CONV #( lr_range_entry->high ) )
INTO TABLE et_emailaddress_range.
ENDLOOP.
WHEN 'NAME'.
LOOP AT lr_range->range REFERENCE INTO lr_range_entry.
INSERT VALUE #( sign = lr_range_entry->sign option = lr_range_entry->option
low = CONV #( lr_range_entry->low ) high = CONV #( lr_range_entry->high ) )
INTO TABLE et_name_range.
ENDLOOP.
WHEN 'COMPANYCODE'.
LOOP AT lr_range->range REFERENCE INTO lr_range_entry.
INSERT VALUE #( sign = lr_range_entry->sign option = lr_range_entry->option
low = CONV #( lr_range_entry->low ) high = CONV #( lr_range_entry->high ) )
INTO TABLE et_company_code_range.
ENDLOOP.
ENDCASE.
ENDLOOP.
CATCH cx_rap_query_filter_no_range INTO DATA(lx_previous).
"Exception handling needed - not implemented yet
ENDTRY.
ENDMETHOD.
METHOD get_allowed_apprvs_via_http.
DATA lt_allowed_approvers TYPE TABLE OF zzzi_allowed_approvers.
TRY.
" Create http client
DATA(lo_destination) = cl_http_destination_provider=>create_by_comm_arrangement(
comm_scenario = ‘add your data here’
service_id = ‘add your data here’ ).
DATA(lo_http_client) = cl_web_http_client_manager=>create_by_http_destination( lo_destination ).
DATA(lo_client_proxy) = cl_web_odata_client_factory=>create_v2_remote_proxy(
iv_service_definition_name = ‘add your data here’
io_http_client = lo_http_client
iv_relative_service_root = ‘add your data here’ ).
" Navigate to the resource and create a request for the read operation
DATA(lo_request) = lo_client_proxy->create_resource_for_entity_set( ‘add your data here’ )->create_request_for_read( ).
" Create the filter
DATA(lo_filter_factory) = lo_request->create_filter_factory( ).
IF it_company_code_range IS NOT INITIAL.
DATA(lo_company_code_filter) = lo_filter_factory->create_by_range(
iv_property_path = 'COMPANYCODE'
it_range = it_company_code_range ).
IF it_emailaddress_range IS NOT INITIAL.
DATA(lo_concatenated_filter) = lo_company_code_filter->and( lo_filter_factory->create_by_range(
iv_property_path = 'EMAIL'
it_range = it_emailaddress_range ) ).
lo_request->set_filter( lo_concatenated_filter ).
ELSE.
lo_request->set_filter( lo_company_code_filter ).
ENDIF.
ENDIF.
lo_request->set_top( io_paging->get_page_size( ) )->set_skip( io_paging->get_offset( ) ).
DATA lt_sort_order TYPE /iwbep/if_cp_runtime_types=>ty_t_sort_order.
LOOP AT it_sort_elements REFERENCE INTO DATA(lr_sort_element).
IF lr_sort_element->element_name IS NOT INITIAL.
IF lr_sort_element->element_name = 'EMAILADDRESS'.
DATA(lv_property_path) = 'EMAIL'.
ELSE.
lv_property_path = lr_sort_element->element_name.
ENDIF.
INSERT VALUE #(
property_path = CONV #( lv_property_path )
descending = lr_sort_element->descending ) INTO TABLE lt_sort_order.
ENDIF.
ENDLOOP.
lo_request->set_orderby( CONV #( lt_sort_order ) ).
" Execute the request and retrieve the business data
DATA(lo_response) = lo_request->execute( ).
lo_response->get_business_data( IMPORTING et_business_data = lt_allowed_approvers ).
LOOP AT lt_allowed_approvers REFERENCE INTO data(lr_allowed_approver).
INSERT lr_allowed_approver->Email INTO TABLE rt_allowed_approvers_emails.
ENDLOOP.
CATCH /iwbep/cx_cp_remote INTO DATA(lx_remote).
" Handle remote Exception
" It contains details about the problems of your http(s) connection
CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).
" Handle Exception
CATCH cx_web_http_client_error INTO DATA(lx_http_client_error).
"handle exception
CATCH cx_http_dest_provider_error INTO DATA(lx_http_dest_provider_error).
"handle exception
ENDTRY.
ENDMETHOD.
METHOD is_descriptions_only_request.
rv_is_descr_only_request = abap_false.
IF it_emailaddress_range IS NOT INITIAL AND
it_name_range IS INITIAL.
rv_is_descr_only_request = abap_true.
ENDIF.
ENDMETHOD.
METHOD process_descr_only_request.
DATA lt_value_help_entries TYPE STANDARD TABLE OF zc_approverid_vhlp_ce_simple .
DATA ls_value_help_entry TYPE zc_approverid_vhlp_ce_simple.
SELECT FROM zemployee_details FIELDS emailaddress, name
WHERE
emailaddress IN @it_emailaddress_range
INTO TABLE @DATA(lt_emails_with_names) .
LOOP AT lt_emails_with_names REFERENCE INTO DATA(lr_email_with_name).
MOVE-CORRESPONDING lr_email_with_name->* TO ls_value_help_entry.
INSERT ls_value_help_entry INTO TABLE lt_value_help_entries.
ENDLOOP.
io_response->set_data( lt_value_help_entries ).
io_response->set_total_number_of_records( lines( lt_value_help_entries ) ).
ENDMETHOD.
ENDCLASS.
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 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 |