-
Notifications
You must be signed in to change notification settings - Fork 238
/
W5U2_CLAS_zcl_ce_rap_agency_####.txt
137 lines (108 loc) · 4.79 KB
/
W5U2_CLAS_zcl_ce_rap_agency_####.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
CLASS zcl_ce_rap_agency_#### DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
TYPES t_agency_range TYPE RANGE OF zrap_####z_travel_agency_es5-agencyid.
TYPES t_business_data TYPE TABLE OF zrap_####z_travel_agency_es5.
METHODS get_agencies
IMPORTING
filter_cond TYPE if_rap_query_filter=>tt_name_range_pairs OPTIONAL
top TYPE i OPTIONAL
skip TYPE i OPTIONAL
is_data_requested TYPE abap_bool
is_count_requested TYPE abap_bool
EXPORTING
business_data TYPE t_business_data
count TYPE int8
RAISING
/iwbep/cx_cp_remote
/iwbep/cx_gateway
cx_web_http_client_error
cx_http_dest_provider_error
.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_ce_rap_agency_#### IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA business_data TYPE t_business_data.
DATA count TYPE int8.
DATA filter_conditions TYPE if_rap_query_filter=>tt_name_range_pairs .
DATA ranges_table TYPE if_rap_query_filter=>tt_range_option .
ranges_table = VALUE #( ( sign = 'I' option = 'GE' low = '070015' ) ).
filter_conditions = VALUE #( ( name = 'AGENCYID' range = ranges_table ) ).
TRY.
get_agencies(
EXPORTING
filter_cond = filter_conditions
top = 3
skip = 1
is_count_requested = abap_true
is_data_requested = abap_true
IMPORTING
business_data = business_data
count = count
) .
out->write( |Total number of records = { count }| ) .
out->write( business_data ).
CATCH cx_root INTO DATA(exception).
out->write( cl_message_helper=>get_latest_t100_exception( exception )->if_message~get_longtext( ) ).
ENDTRY.
ENDMETHOD.
METHOD get_agencies.
DATA: filter_factory TYPE REF TO /iwbep/if_cp_filter_factory,
filter_node TYPE REF TO /iwbep/if_cp_filter_node,
root_filter_node TYPE REF TO /iwbep/if_cp_filter_node.
DATA: http_client TYPE REF TO if_web_http_client,
odata_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,
read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,
read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.
DATA service_consumption_name TYPE cl_web_odata_client_factory=>ty_service_definition_name.
DATA(http_destination) = cl_http_destination_provider=>create_by_url( i_url = 'https://sapes5.sapdevcenter.com' ).
http_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = http_destination ).
service_consumption_name = to_upper( 'ZSC_RAP_AGENCY_####' ).
odata_client_proxy = cl_web_odata_client_factory=>create_v2_remote_proxy(
EXPORTING
iv_service_definition_name = service_consumption_name
io_http_client = http_client
iv_relative_service_root = '/sap/opu/odata/sap/ZAGENCYCDS_SRV/' ).
" Navigate to the resource and create a request for the read operation
read_list_request = odata_client_proxy->create_resource_for_entity_set( 'Z_TRAVEL_AGENCY_ES5' )->create_request_for_read( ).
" Create the filter tree
filter_factory = read_list_request->create_filter_factory( ).
LOOP AT filter_cond INTO DATA(filter_condition).
filter_node = filter_factory->create_by_range( iv_property_path = filter_condition-name
it_range = filter_condition-range ).
IF root_filter_node IS INITIAL.
root_filter_node = filter_node.
ELSE.
root_filter_node = root_filter_node->and( filter_node ).
ENDIF.
ENDLOOP.
IF root_filter_node IS NOT INITIAL.
read_list_request->set_filter( root_filter_node ).
ENDIF.
IF is_data_requested = abap_true.
read_list_request->set_skip( skip ).
IF top > 0 .
read_list_request->set_top( top ).
ENDIF.
ENDIF.
IF is_count_requested = abap_true.
read_list_request->request_count( ).
ENDIF.
IF is_data_requested = abap_false.
read_list_request->request_no_business_data( ).
ENDIF.
" Execute the request and retrieve the business data and count if requested
read_list_response = read_list_request->execute( ).
IF is_data_requested = abap_true.
read_list_response->get_business_data( IMPORTING et_business_data = business_data ).
ENDIF.
IF is_count_requested = abap_true.
count = read_list_response->get_count( ).
ENDIF.
ENDMETHOD.
ENDCLASS.