Introduction:
ABAP Restful Application Programming is an efficient and cloud-compatible development model that enables rapid creation of Fiori apps.
As a part of clean core guidelines, it is a best practice to used SAP released APIs to fetch the data within S4HANA system instead of directly querying on unreleased CDS views.
Implementation
DATA(lo_client_proxy) =
/iwbep/cl_cp_client_proxy_fact=>create_v2_local_proxy( VALUE #( service_id = 'API_MATERIAL_STOCK_SRV' service_version = '0001' ) ) .
DATA(lo_entity_list_resource) = lo_client_proxy->create_resource_for_entity_set( 'A_MatlStkInAcctMod' ).
DATA(lo_read_list_request) = lo_entity_list_resource->create_request_for_read( ).
DATA(lt_sort_order) = CORRESPONDING /iwbep/if_cp_runtime_types=>ty_t_sort_order( it_sort_order MAPPING property_path = element_name ).
lo_read_list_request->set_orderby( lt_sort_order ).
DATA(lo_filter_factory) = lo_read_list_request->create_filter_factory( ).
DATA: lo_filter_node_final TYPE REF TO /iwbep/if_cp_filter_node.
LOOP AT it_filter ASSIGNING FIELD-SYMBOL(<lv_filter>).
TRY.
DATA(lo_filter_node) = io_filter_factory->create_by_range( iv_property_path = <lv_filter>-name it_range = <lv_filter>-range ).
IF lo_filter_node_final IS BOUND .
lo_filter_node_final = lo_filter_node_final->and( lo_filter_node ).
ELSE .
lo_filter_node_final = lo_filter_node .
ENDIF. .
CATCH /iwbep/cx_gateway.
"handle exception
ENDTRY.
ENDLOOP.
data(lo_filter) = lo_filter_node_final .
lo_read_list_request->set_filter( lo_filter ) .​
IF lv_top > 0 .
lo_read_list_request->set_skip( lv_skip ) .
lo_read_list_request->set_top( lv_top ) .
ENDIF.
DATA(lo_read_list_response) = lo_read_list_request->execute( ).
lo_read_list_response->get_business_data( IMPORTING et_business_data = et_results ).
In this way all the other CRUD operations can be handled using local instance and HTTP client destination configuration can be avoided.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 13 | |
| 12 | |
| 12 | |
| 11 | |
| 10 | |
| 10 | |
| 9 | |
| 9 |