forked from nzamani/gatewaycodepatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuery
81 lines (72 loc) · 2.92 KB
/
Query
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
*Get Filters
DATA: lt_filter_select_options TYPE /iwbep/t_mgw_select_option,
ls_filter TYPE /iwbep/s_mgw_select_option,
ls_select_option TYPE /iwbep/s_cod_select_option.
lt_filter_select_options = io_tech_request_context->get_filter( )->get_filter_select_options( ).
"Replace 'PLANT' with suitable property name (all capitals)
READ TABLE lt_filter_select_options INTO ls_filter WITH KEY property = 'PLANT'.
IF sy-subrc EQ 0.
READ TABLE ls_filter-select_options INTO ls_select_option INDEX 1.
lv_plant = ls_select_option-low.
ENDIF.
*Get Open SQL WHERE Clause from $filter
DATA: lv_osql_where_clause TYPE string.
lv_osql_where_clause = io_tech_request_context->get_osql_where_clause( ).
*Get Source Keys. If query is through Navigation
DATA: lt_parent_keys TYPE /iwbep/t_mgw_tech_pairs,
ls_parent_key TYPE /iwbep/s_mgw_tech_pair.
"Get Parent entity name
IF io_tech_request_context->get_source_entity_type_name( ) = 'Material'.
"get parent keys
lt_parent_keys = io_tech_request_context->get_source_keys( ).
READ TABLE lt_parent_keys INTO ls_parent_key WITH KEY name = 'MATERIALNUMBER'.
IF sy-subrc EQ 0.
lv_material_number = ls_parent_key-value.
ENDIF.
ENDIF.
*Get Open search string
DATA: lv_search_string TYPE string,
ltr_vendor_name TYPE RANGE OF name1_gp,
lsr_vendor_name LIKE LINE OF ltr_vendor_name.
lv_search_string = io_tech_request_context->get_search_string( ).
"Create a range table to be used in a SELECT statement. Replace 'Vendor' above
IF lv_search_string IS NOT INITIAL.
CONCATENATE '*' lv_search_string '*' INTO lsr_vendor_name-low.
lsr_vendor_name-option = 'CP'.
lsr_vendor_name-sign = 'I'.
APPEND lsr_vendor_name TO ltr_vendor_name.
ENDIF.
*Top&Skip
DATA: lv_top TYPE i,
lv_skip TYPE i,
lv_total TYPE i,
lv_start_from TYPE i.
lv_top = io_tech_request_context->get_top( ).
IF lv_top EQ 0.
lv_top = 100. "If $top was not sent, send maximum 100 rows
ENDIF.
lv_skip = io_tech_request_context->get_skip( ).
lv_total = lv_top + lv_skip.
lv_start_from = lv_skip + 1.
"Remove rows to be skipped
IF lv_skip GT 0.
DELETE lt_customers FROM 1 TO lv_skip.
ENDIF.
*Orderby
DATA: lt_order TYPE /iwbep/t_mgw_tech_order,
ls_order LIKE LINE OF lt_order,
lt_otab TYPE abap_sortorder_tab,
ls_otab TYPE abap_sortorder.
lt_order = io_tech_request_context->get_orderby( ).
IF lt_order IS NOT INITIAL.
LOOP AT lt_order INTO ls_order.
ls_otab-name = ls_order-property.
IF ls_order-order = lcs_sorting_order-descending.
ls_otab-descending = abap_true.
ELSE.
ls_otab-descending = abap_false.
ENDIF.
APPEND ls_otab TO lt_otab.
ENDLOOP.
SORT et_entityset BY (lt_otab).
ENDIF.