data base_url type string.
base_url = '<base url of an OData service>'.
http_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = cl_http_destination_provider=>create_by_url( i_url = base_url ) ).
http_client->get_http_request( )->set_authorization_basic(
i_username = '<username>'
i_password = '<password>'
).
https://sapes5.sapdevcenter.com/sap/opu/odata/sap/ZE2E100_SOL_2_SRV/$metadata
@EndUserText.label: 'ZSC_SALESORDERDEMO'
@OData.schema.name: 'ZE2E100_SOL_2_SRV'
define service ZSC_SALESORDERDEMO {
expose ZSALESORDERDEMO;
}
/********** GENERATED on 10/19/2019 at 18:25:05 by CB0000000083**************/
@OData.entitySet.name: 'Zsepm_C_Salesorder_SOL'
@OData.entityType.name: 'Zsepm_C_Salesorder_SOLType'
define root abstract entity ZSALESORDERDEMO {
key SalesOrder : abap.char( 10 ) ;
@Semantics.amount.currencyCode: 'TransactionCurrency'
NetAmountInTransactionCurrency : abap.dec( 16, 3 ) ;
@Semantics.amount.currencyCode: 'TransactionCurrency'
TaxAmountInTransactionCurrency : abap.dec( 16, 3 ) ;
SalesOrderLifeCycleStatus : abap.char( 1 ) ;
SalesOrderBillingStatus : abap.char( 1 ) ;
SalesOrderDeliveryStatus : abap.char( 1 ) ;
SalesOrderOverallStatus : abap.char( 1 ) ;
Opportunity : abap.char( 35 ) ;
SalesOrder_Text : abap.char( 255 ) ;
CreationDateTime : tzntstmpl ;
LastChangedDateTime : tzntstmpl ;
IsCreatedByBusinessPartner : abap_boolean ;
IsLastChangedByBusinessPartner : abap_boolean ;
Customer : abap.char( 10 ) ;
@Semantics.currencyCode: true
TransactionCurrency : abap.cuky( 5 ) ;
@Semantics.amount.currencyCode: 'TransactionCurrency'
GrossAmountInTransacCurrency : abap.dec( 16, 3 ) ;
}
CLASS zcl_call_odata_from_trial DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
DATA salesorders TYPE STANDARD TABLE OF zsalesorderdemo.
PRIVATE SECTION.
METHODS get_http_client
IMPORTING base_url TYPE string
RETURNING VALUE(http_client) TYPE REF TO if_web_http_client
RAISING
cx_web_http_client_error
cx_http_dest_provider_error.
METHODS get_odata_response
IMPORTING http_client TYPE REF TO if_web_http_client
EXPORTING entityset LIKE salesorders
RAISING
cx_web_http_client_error
/iwbep/cx_gateway.
ENDCLASS.
CLASS zcl_call_odata_from_trial IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA base_url TYPE string.
base_url = 'https://sapes5.sapdevcenter.com/'.
TRY.
DATA(http_client) = get_http_client( base_url = base_url ).
CATCH cx_web_http_client_error cx_http_dest_provider_error INTO DATA(error_creating_http_client).
out->write( error_creating_http_client->get_longtext( ) ).
EXIT.
ENDTRY.
TRY.
get_odata_response(
EXPORTING http_client = http_client
IMPORTING entityset = DATA(salesorders) ).
CATCH cx_web_http_client_error /iwbep/cx_gateway INTO DATA(error_calling_OData_service).
"handle exception
out->write( error_calling_OData_service->get_longtext( ) ).
EXIT.
ENDTRY.
LOOP AT salesorders INTO DATA(salesorder).
out->write( salesorder ).
ENDLOOP.
ENDMETHOD.
METHOD get_http_client.
http_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = cl_http_destination_provider=>create_by_url( i_url = base_url ) ).
http_client->get_http_request( )->set_authorization_basic(
i_username = '<your ES5 user>'
i_password = '<password of your ES5 user>'
).
ENDMETHOD.
METHOD get_odata_response.
DATA entity LIKE LINE OF entityset.
DATA range_for_salesorders LIKE RANGE OF entity-salesorder.
DATA range_for_salesorders2 LIKE RANGE OF entity-salesorder.
DATA range_for_netamounts LIKE RANGE OF entity-netamountintransactioncurrency.
DATA range_for_netamounts2 LIKE RANGE OF entity-netamountintransactioncurrency.
DATA(client_proxy) = cl_web_odata_client_factory=>create_v2_remote_proxy(
EXPORTING
iv_service_definition_name = 'ZSC_SALESORDERDEMO'
io_http_client = http_client
iv_relative_service_root = '/sap/opu/odata/sap/ZE2E100_SOL_2_SRV/' ).
DATA(odata_request) = client_proxy->create_resource_for_entity_set( 'ZSEPM_C_SALESORDER_SOL' )->create_request_for_read( ).
odata_request->set_top( 5 )->set_skip( 0 ).
* filter
range_for_salesorders = VALUE #(
( sign = 'I' option = 'GE' low = '500000100' ) ).
range_for_netamounts = VALUE #(
( sign = 'I' option = 'LE' low = '8000' ) ).
range_for_netamounts2 = VALUE #(
( sign = 'I' option = 'GE' low = '3000' ) ).
DATA(filter_factory) = odata_request->create_filter_factory( ).
DATA(filter_child_node_1) = filter_factory->create_by_range( iv_property_path = 'SALESORDER'
it_range = range_for_salesorders ).
DATA(filter_child_node_2) = filter_factory->create_by_range( iv_property_path = 'NETAMOUNTINTRANSACTIONCURRENCY'
it_range = range_for_netamounts
iv_currency_code = 'USD' ).
DATA(filter_child_node_3) = filter_factory->create_by_range( iv_property_path = 'NETAMOUNTINTRANSACTIONCURRENCY'
it_range = range_for_netamounts2
iv_currency_code = 'USD' ).
DATA(filter_root_node) = filter_child_node_1->and( filter_child_node_2->and( filter_child_node_3 ) ).
odata_request->set_filter( filter_root_node ).
* retrieve business data
DATA(odata_response) = odata_request->execute( ).
odata_response->get_business_data( IMPORTING et_business_data = entityset ).
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 |
---|---|
17 | |
11 | |
7 | |
7 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |