-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZSCL_ODATA_TOOLS.TXT
2964 lines (2388 loc) · 104 KB
/
ZSCL_ODATA_TOOLS.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
class ZSCL_ODATA_TOOLS definition
public
final
create public .
public section.
types:
ty_t_mgw_request type table of ref to /iwbep/cl_mgw_request .
types:
begin of ty_s_nav_prop,
principal_entity type string,
principal_property type string,
principal_structure type string,
principal_field type fieldname,
dependent_entity type string,
dependent_property type string,
dependent_structure type string,
dependent_field type fieldname,
end of ty_s_nav_prop .
types:
ty_t_nav_prop type table of ty_s_nav_prop .
constants GC_MAX_HITS type INT4 value 1000 ##NO_TEXT.
class-methods ADD_MESSAGE_TO_HEADER
importing
!IO_SRV_RUNTIME type ref to /IWBEP/IF_MGW_CONV_SRV_RUNTIME .
class-methods CONVERT_EXPAND_TO_FILTER
importing
!IO_REQUEST_EXP type ref to /IWBEP/CL_MGW_REQUEST
!IV_ENTITY_TYPE_A type STRING
!IV_ENTITY_TYPE_B type STRING
!IS_ENTITY_A type ANY
!IO_MODEL type ref to /IWBEP/CL_MGW_ODATA_MODEL optional
returning
value(RV_REQUEST_FILTER) type ref to /IWBEP/CL_MGW_REQUEST
raising
/IWBEP/CX_MGW_TECH_EXCEPTION .
class-methods CONVERT_EXPAND_TO_FILTER_MUL
importing
!IO_REQUEST_EXP type ref to /IWBEP/CL_MGW_REQUEST
!IV_ENTITY_TYPE_A type STRING
!IV_ENTITY_TYPE_B type STRING
!IT_DATA type STANDARD TABLE
!IO_MODEL type ref to /IWBEP/IF_MGW_ODATA_FW_MODEL optional
exporting
!ES_NAV_PROP type TY_S_NAV_PROP
value(ET_REQUEST_FILTER) type TY_T_MGW_REQUEST
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION
/IWBEP/CX_MGW_TECH_EXCEPTION .
class-methods CONVERT_SELECT_OPTIONS
importing
!IV_NAME type CDSVIEW_SOURCE optional
!IV_STRUCTURE type ANY optional
changing
!CT_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION optional
!CT_FILTER_EXPRESSIONS type /IWBEP/IF_MGW_CORE_SRV_RUNTIME=>TT_EXPRESSIONS optional
raising
resumable(/IWBEP/CX_MGW_BUSI_EXCEPTION) .
class-methods COPY_DATA_TO_REF
importing
!IS_DATA type ANY
changing
!CR_DATA type ref to DATA .
class-methods EXPAND_GENERIC_ENTITY_SET
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
!IO_EXPAND_NODE type ref to /IWBEP/CL_MGW_EXPAND_NODE
!IO_DATA_PROVIDER type ref to /IWBEP/IF_MGW_APPL_SRV_RUNTIME
changing
!CT_DATA type STANDARD TABLE
!CT_EXPANDED_PROPERTIES type STRING_TABLE
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION
/IWBEP/CX_MGW_TECH_EXCEPTION .
class-methods FETCH_CDS_DATA_BY_KEYS
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/IF_MGW_REQ_ENTITYSET
!IV_CDS_VIEW type CDSVIEW_SOURCE optional
!IV_REMOVE_DUPLICATES type ABAP_BOOL default ABAP_FALSE
changing
!CT_ENTITY_SET type STANDARD TABLE
!CS_RESPONSE_CONTEXT type /IWBEP/IF_MGW_APPL_SRV_RUNTIME=>TY_S_MGW_RESPONSE_CONTEXT
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION .
class-methods GET_CDS_DATA
importing
!IV_CDS_VIEW type CDSVIEW_SOURCE
!IT_FILTER_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION optional
!IV_FILTER_STRING type STRING optional
!IT_SELECT type STRING_TABLE optional
!IV_SELECT_KEYS type ABAP_BOOL optional
!IT_ORDER_BY type STRING_TABLE optional
!IV_MAX_HITS type MAX_HITS optional
!IV_DISTINCT type ABAP_BOOL default ABAP_TRUE
!IV_COUNT type ABAP_BOOL default ABAP_FALSE
!IV_DATA type ABAP_BOOL default ABAP_TRUE
!IV_SELECT_BY_KEYS type ABAP_BOOL default ABAP_FALSE
exporting
!EV_COUNT type INT4
changing
!CT_DATA type STANDARD TABLE
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION .
class-methods GET_CDS_ENTITY
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/IF_MGW_REQ_ENTITY
!IV_CDS_VIEW type CDSVIEW_SOURCE optional
changing
!CS_ENTITY type ANY
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION .
class-methods GET_CDS_ENTITY_SET
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/IF_MGW_REQ_ENTITYSET
!IV_CDS_VIEW type CDSVIEW_SOURCE optional
!IV_DISTINCT type ABAP_BOOL default ABAP_TRUE
!IT_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION optional
changing
!CT_ENTITY_SET type STANDARD TABLE
!CS_RESPONSE_CONTEXT type /IWBEP/IF_MGW_APPL_SRV_RUNTIME=>TY_S_MGW_RESPONSE_CONTEXT
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION .
class-methods GET_CDS_KEYS
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/IF_MGW_REQ_ENTITYSET
!IV_CDS_VIEW type CDSVIEW_SOURCE optional
!IT_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION optional
changing
!CT_ENTITY_SET type STANDARD TABLE
!CS_RESPONSE_CONTEXT type /IWBEP/IF_MGW_APPL_SRV_RUNTIME=>TY_S_MGW_RESPONSE_CONTEXT
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION .
class-methods GET_CONVERTED_FILTER_STRING
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/IF_MGW_REQ_ENTITYSET
!IV_CDS_NAME type CDSVIEW_SOURCE
returning
value(RV_FILTER_STRING) type STRING
raising
resumable(/IWBEP/CX_MGW_BUSI_EXCEPTION) .
class-methods GET_EXPANDED_ENTITYSET
importing
!IV_ENTITY_NAME type STRING
!IV_ENTITY_SET_NAME type STRING
!IV_SOURCE_NAME type STRING
!IT_FILTER_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION optional
!IT_ORDER type /IWBEP/T_MGW_SORTING_ORDER optional
!IS_PAGING type /IWBEP/S_MGW_PAGING optional
!IT_NAVIGATION_PATH type /IWBEP/T_MGW_NAVIGATION_PATH optional
!IT_KEY_TAB type /IWBEP/T_MGW_NAME_VALUE_PAIR optional
!IV_FILTER_STRING type STRING optional
!IV_SEARCH_STRING type STRING optional
!IO_EXPAND type ref to /IWBEP/IF_MGW_ODATA_EXPAND
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/IF_MGW_REQ_ENTITYSET
!IO_DATA_PROVIDER type ref to /IWBEP/IF_MGW_APPL_SRV_RUNTIME
exporting
!ER_ENTITYSET type ref to DATA
!ET_EXPANDED_CLAUSES type STRING_TABLE
!ET_EXPANDED_TECH_CLAUSES type STRING_TABLE
!ES_RESPONSE_CONTEXT type /IWBEP/IF_MGW_APPL_SRV_RUNTIME=>TY_S_MGW_RESPONSE_CONTEXT
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION
/IWBEP/CX_MGW_TECH_EXCEPTION .
class-methods GET_SERVICE_MODEL
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
returning
value(RO_MODEL) type ref to /IWBEP/CL_MGW_ODATA_MODEL
raising
/IWBEP/CX_MGW_TECH_EXCEPTION .
class-methods GET_SO_FROM_NAVIGATION
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
returning
value(RT_SELECT_OPTIONS) type /IWBEP/T_MGW_SELECT_OPTION .
class-methods GET_TEXT_FROM_KEY
importing
!IV_OBJECT type TDOBJECT
!IV_NAME type TDOBNAME
!IV_ID type TDID
!IV_SPRAS type SPRAS
returning
value(EV_TEXT) type STRING_UNICODE .
class-methods IMPLEMENT_FILTERING
importing
!IT_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION
changing
!CT_DATA type STANDARD TABLE
raising
resumable(/IWBEP/CX_MGW_BUSI_EXCEPTION) .
class-methods IMPLEMENT_ORDERBY
importing
!IT_ORDER type /IWBEP/T_MGW_SORTING_ORDER optional
!IT_ORDER_TECH type /IWBEP/T_MGW_TECH_ORDER optional
changing
!CT_DATA type STANDARD TABLE .
class-methods IMPLEMENT_PAGING
importing
!IS_PAGING type /IWBEP/S_MGW_PAGING
changing
!CT_DATA type STANDARD TABLE .
class-methods IS_FIELD_REQUESTED
importing
!IV_FIELD type STRING optional
!IT_FIELDS type STRING_TABLE optional
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
returning
value(RV_OK) type ABAP_BOOL .
class-methods RAISE_EXCEPTION
importing
!IV_BUSI type ABAP_BOOL default ABAP_TRUE
!IV_TECH type ABAP_BOOL default ABAP_FALSE
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION
/IWBEP/CX_MGW_TECH_EXCEPTION .
protected section.
class-methods BUILD_ORDER_BY_TABLE
importing
!IV_CDS_VIEW type CDSVIEW_SOURCE
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
returning
value(RT_ORDER_BY) type STRING_TABLE .
class-methods BUILD_SELECT_TABLE
importing
!IV_CDS_VIEW type CDSVIEW_SOURCE
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
!IV_KEY_FIELDS_ONLY type ABAP_BOOL default ABAP_FALSE
returning
value(RT_SELECT) type STRING_TABLE .
class-methods BUILD_WHERE_TABLE
importing
!IV_CDS_VIEW type CDSVIEW_SOURCE
!IT_SELECT_OPTION type /IWBEP/T_MGW_SELECT_OPTION optional
!IV_FILTER_STRING type STRING optional
!IV_SELECT_BY_KEYS type ABAP_BOOL default ABAP_FALSE
returning
value(RT_WHERE) type STRING_TABLE .
private section.
class-methods CHECK_FIELD_
importing
!IV_TABLE type STRING
!IV_FIELD type STRING
returning
value(RV_FIELD) type STRING .
class-methods CHECK_SELECT_
importing
!IV_TABLE type STRING
!IT_SELECT type STRING_TABLE
returning
value(RT_SELECT) type STRING_TABLE .
class-methods CHECK_TABLE_
importing
!IV_TABLE type STRING
returning
value(RV_TABLE) type STRING .
class-methods CONVERT_SO_DDIC_
importing
!IR_STRUCT_DESCR type ref to CL_ABAP_TYPEDESCR
changing
!CT_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION optional
!CT_FILTER_EXPRESSIONS type /IWBEP/IF_MGW_CORE_SRV_RUNTIME=>TT_EXPRESSIONS optional
raising
resumable(ZCX_ODATA_TOOLS) .
class-methods CONVERT_SO_FREE_
importing
!IR_STRUCT_DESCR type ref to CL_ABAP_TYPEDESCR
changing
!CT_SELECT_OPTIONS type /IWBEP/T_MGW_SELECT_OPTION optional
!CT_FILTER_EXPRESSIONS type /IWBEP/IF_MGW_CORE_SRV_RUNTIME=>TT_EXPRESSIONS optional
raising
resumable(ZCX_ODATA_TOOLS) .
class-methods DB_COUNT_
importing
!IT_FROM type STRING_TABLE
!IT_WHERE type STRING_TABLE
returning
value(RV_COUNT) type INT4
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION .
class-methods DB_SELECT_
importing
!IT_SELECT type STRING_TABLE optional
!IT_FROM type STRING_TABLE optional
!IT_WHERE type STRING_TABLE optional
!IT_ORDER_BY type STRING_TABLE optional
!IV_MAX_HITS type MAX_HITS default 100
!IV_COUNT type ABAP_BOOL default ABAP_FALSE
!IV_DATA type ABAP_BOOL default ABAP_TRUE
!IV_DISTINCT type ABAP_BOOL default ABAP_FALSE
!IV_SELECT_BY_KEYS type ABAP_BOOL default ABAP_FALSE
exporting
!EV_COUNT type INT4
changing
!CT_DATA type STANDARD TABLE
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION
CX_SY_DYNAMIC_OSQL_ERROR .
class-methods DETERMINE_CDS_
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
returning
value(RV_CDS_NAME) type CDSVIEW_SOURCE .
class-methods GET_KEY_FIELDS_
importing
!IV_CDS_VIEW type CDSVIEW_SOURCE
returning
value(RT_KEY_FIELDS) type STRING_TABLE .
class-methods REMOVE_DUPLICATES_BY_KEY_
importing
!IV_CDS_VIEW type CDSVIEW_SOURCE
changing
!CT_DATA type STANDARD TABLE
raising
/IWBEP/CX_MGW_BUSI_EXCEPTION .
class-methods _GET_DDIC_STRUCTURE_FOR_ET_
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
!IV_ENTITY_TYPE_NAME type STRING
returning
value(RV_STRUCTURE_NAME) type STRING
raising
/IWBEP/CX_MGW_TECH_EXCEPTION .
class-methods _GET_ES_BY_ET_
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
!IV_ET_NAME type STRING
returning
value(RV_ES_NAME) type STRING
raising
/IWBEP/CX_MGW_TECH_EXCEPTION .
class-methods _GET_NAVIGATION_PROPERTIES_
importing
!IO_TECH_REQUEST_CONTEXT type ref to /IWBEP/CL_MGW_REQUEST
!IV_PRINCIPAL_ET type STRING
!IV_DEPENDENT_ET type STRING
exporting
!ET_NAV_PROPS type TY_T_NAV_PROP
raising
/IWBEP/CX_MGW_TECH_EXCEPTION .
ENDCLASS.
CLASS ZSCL_ODATA_TOOLS IMPLEMENTATION.
method add_message_to_header.
data(lr_msg_cont) = io_srv_runtime->get_message_container( ).
check: lr_msg_cont is bound.
check: sy-msgid is not initial and
sy-msgty is not initial.
message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into data(lv_dummy).
lr_msg_cont->add_message( iv_msg_type = sy-msgty
iv_msg_id = sy-msgid
iv_msg_number = sy-msgno
iv_msg_text = conv #( lv_dummy )
iv_add_to_response_header = abap_true ).
endmethod.
method build_order_by_table.
data: lv_string type string.
data(ls_details) = io_tech_request_context->get_request_details( ).
" If $orderby is not initial...
check: ls_details-technical_request-order[] is not initial.
loop at ls_details-technical_request-order into data(ls_order).
if check_field_( iv_table = conv #( iv_cds_view )
iv_field = conv #( ls_order-property ) ) is not initial.
translate ls_order-order to upper case.
case ls_order-order(3).
when 'DES'. ls_order-order = 'DESCENDING'. "#EC NO_TEXT
when 'ASC'. ls_order-order = 'ASCENDING'. "#EC NO_TEXT
endcase.
concatenate ls_order-property ls_order-order into lv_string separated by space.
translate lv_string to upper case.
append lv_string to rt_order_by[].
endif.
endloop.
" Add Commas Here...
loop at rt_order_by assigning field-symbol(<fs_order_by>).
if sy-tabix <> lines( rt_order_by[] ).
concatenate <fs_order_by> ',' into <fs_order_by> separated by space.
endif.
endloop.
endmethod.
method build_select_table.
data(ls_details) = io_tech_request_context->get_request_details( ).
if iv_key_fields_only = abap_true or
io_tech_request_context->/iwbep/if_mgw_req_entityset~has_count( ) = abap_true.
" Only Key Fields...
rt_select[] = get_key_fields_( iv_cds_view = iv_cds_view ).
else.
rt_select[] = ls_details-technical_request-select_strings[].
endif.
" If $select is not initial...
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if rt_select[] is not initial.
" Add Key Fields... Always... Otherwise, no sense...
loop at get_key_fields_( iv_cds_view = iv_cds_view ) into data(lv_key_field).
collect lv_key_field into rt_select[].
endloop.
" Add Sort Fields... Always... Otherwise, ABAP dump...
loop at ls_details-technical_request-order into data(ls_order).
collect conv string( ls_order-property ) into rt_select[].
endloop.
endif.
" Check Select...
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
rt_select = check_select_( it_select = rt_select[]
iv_table = conv #( iv_cds_view ) ).
endmethod.
method build_where_table.
data: lv_where type string.
data: lt_ranges type rsds_trange.
data: ls_range type rsds_range.
data: lt_frange type rsds_frange_t.
data: ls_frange type rsds_frange.
data: lt_where type rsds_twhere.
data: lt_parts type string_table.
data: lt_parts_ok type string_table.
data lv_whitelist type string.
data lv_part_ok type string.
" Check Table...
if check_table_( conv #( iv_cds_view ) ) is initial.
return.
endif.
" Read Data via Select Options...
if it_select_option[] is not initial.
loop at it_select_option into data(ls_so).
clear: lv_where, lt_ranges, ls_range, lt_frange, ls_frange, lt_where.
ls_frange-fieldname = ls_so-property.
move-corresponding: ls_so-select_options[] to ls_frange-selopt_t[].
" Conversion for ABAP and SQL Syntax...
loop at ls_frange-selopt_t[] assigning field-symbol(<fs_selopt>).
case to_upper( <fs_selopt>-option ).
when 'EQ'. <fs_selopt>-option = '='.
when 'GT'. <fs_selopt>-option = '>'.
when 'LT'. <fs_selopt>-option = '<'.
when 'GE'. <fs_selopt>-option = '>='.
when 'LE'. <fs_selopt>-option = '<='.
when 'NE'. <fs_selopt>-option = '<>'.
endcase.
endloop.
append ls_frange to lt_frange[].
ls_range-tablename = iv_cds_view.
ls_range-frange_t[] = lt_frange[].
append ls_range to lt_ranges[].
" Check Field...
if check_field_( iv_table = conv #( iv_cds_view )
iv_field = conv #( ls_frange-fieldname ) ) is initial.
continue.
endif.
" Needed to avoid ATC Check Prio 1...
call function 'FREE_SELECTIONS_RANGE_2_WHERE'
exporting
field_ranges = lt_ranges
importing
where_clauses = lt_where.
loop at lt_where into data(ls_where).
loop at ls_where-where_tab into data(l_clause).
concatenate lv_where l_clause-line into lv_where separated by space.
endloop.
endloop.
condense lv_where.
if lv_where is not initial.
if rt_where[] is not initial.
append ' AND ' to rt_where[].
endif.
append lv_where to rt_where[].
endif.
endloop.
endif.
" Read Data via Filter String...
if iv_filter_string is not initial.
clear: lt_parts[], lv_where.
lv_where = iv_filter_string.
replace all occurrences of '(' in lv_where with ' ( '.
replace all occurrences of ')' in lv_where with ' ) '.
condense lv_where.
split lv_where at space into table lt_parts[].
clear: lv_where.
loop at lt_parts[] into data(lv_part).
try.
lv_whitelist = lv_part.
lv_part_ok = cl_abap_dyn_prg=>check_whitelist_str(
val = lv_part
whitelist = lv_whitelist ).
catch cx_abap_not_in_whitelist.
assert 1 = 2.
endtry.
append lv_part_ok to lt_parts_ok.
endloop.
concatenate lines of lt_parts_ok into lv_where separated by space.
condense lv_where.
" Put all in brackets...
if not lv_where cp '(*)'.
concatenate '(' lv_where ')' into lv_where separated by space.
endif.
" Can be a Combination...
if rt_where[] is not initial.
append ' AND ' to rt_where[].
endif.
append lv_where to rt_where[].
endif.
" Select by Keys...
if iv_select_by_keys = abap_true.
data(lt_key_fields) = get_key_fields_( iv_cds_view ).
loop at lt_key_fields into data(lv_key_field).
clear: lv_where.
translate lv_key_field to lower case.
lv_where = |{ lv_key_field } = @ct_data-{ lv_key_field }|. " CT_DATA is a constant !!!
if rt_where[] is not initial.
append ' AND ' to rt_where[].
endif.
append lv_where to rt_where[].
endloop.
endif.
endmethod.
method check_field_.
statics: sv_table type ddobjname,
st_dfies type table of dfies,
st_list type string_hashed_table.
clear: rv_field.
if sv_table <> iv_table.
clear: sv_table, st_dfies[], st_list[].
sv_table = iv_table.
call function 'DDIF_NAMETAB_GET'
exporting
tabname = sv_table
tables
dfies_tab = st_dfies
exceptions
not_found = 1
others = 2.
if sy-subrc <> 0.
return.
endif.
loop at st_dfies into data(ls_dfies).
collect conv string( ls_dfies-fieldname ) into st_list[].
endloop.
endif.
try.
rv_field = cl_abap_dyn_prg=>check_whitelist_tab( val = iv_field whitelist = st_list ).
catch cx_abap_not_in_whitelist into data(lx_abap_not_in_whitelist).
return.
endtry.
endmethod.
method check_select_.
clear: rt_select[].
loop at it_select into data(lv_field).
lv_field = check_field_( iv_table = iv_table iv_field = lv_field ).
if lv_field is not initial.
append lv_field to rt_select[].
endif.
endloop.
endmethod.
method check_table_.
data: lt_whitelist type string_hashed_table.
data: lt_packages type string_hashed_table.
clear: rv_table.
check: iv_table(2) = 'ZS'
or iv_table(3) = 'ZZS'
or iv_table(5) = 'ZDMSH'
or iv_table(2) = 'YS'.
try.
collect iv_table into lt_whitelist.
rv_table = cl_abap_dyn_prg=>check_whitelist_tab( val = iv_table
whitelist = lt_whitelist ).
catch cx_abap_not_in_whitelist.
return.
endtry.
try.
clear: lt_packages.
rv_table = cl_abap_dyn_prg=>check_table_name_tab( val = iv_table
packages = lt_packages ).
catch cx_abap_not_a_table.
return. " Check for existance...
catch cx_abap_not_in_package.
"return. " Check for package is not relevent...
endtry.
endmethod.
method convert_expand_to_filter.
data: lo_request_context type ref to /iwbep/cl_mgw_request.
data: ls_request type /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
data: ls_request_new type /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
data: lr_request type ref to /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
field-symbols:
<ls_request> type /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
define: _move.
ls_request_new-&1 = ls_request-&1.
end-of-definition.
" Get Request Data...
ls_request = io_request_exp->get_request_details( ).
data(lv_entity_set_a) = _get_es_by_et_( io_tech_request_context = io_request_exp iv_et_name = iv_entity_type_a ).
data(lv_entity_set_b) = _get_es_by_et_( io_tech_request_context = io_request_exp iv_et_name = iv_entity_type_b ).
" Check Navigation Properties...
call method _get_navigation_properties_
exporting
io_tech_request_context = io_request_exp
iv_principal_et = iv_entity_type_a
iv_dependent_et = iv_entity_type_b
importing
et_nav_props = data(lt_nav_props).
if lt_nav_props[] is initial.
return.
endif.
" Copy Technical Details...
_move: service_doc_name, namespace, version, cache_timestamp, base_url,
http_method, icf_root_node, system_alias_info, context_params,
format, type, operation, incoming_message.
" Set Source and Target Properties...
ls_request_new-source_entity = iv_entity_type_b.
ls_request_new-target_entity = iv_entity_type_b.
ls_request_new-source_entity_set = lv_entity_set_b.
ls_request_new-source_entity_set = lv_entity_set_b.
ls_request_new-technical_request-service_name = ls_request_new-service_doc_name.
ls_request_new-technical_request-service_version = ls_request_new-version.
ls_request_new-technical_request-source_entity_type = ls_request_new-source_entity.
ls_request_new-technical_request-target_entity_type = ls_request_new-target_entity.
ls_request_new-technical_request-source_entity_set = ls_request_new-source_entity_set.
ls_request_new-technical_request-target_entity_set = ls_request_new-target_entity_set.
ls_request_new-technical_request-request_header = ls_request-technical_request-request_header.
" Filter Tabs...
loop at lt_nav_props assigning field-symbol(<fs_nav_prop>).
assign component <fs_nav_prop>-principal_field of structure is_entity_a
to field-symbol(<fs_key_value>).
if sy-subrc = 0.
" Request Filters...
append value #( property = <fs_nav_prop>-dependent_property
select_options = value #( ( sign = 'I' option = 'EQ' low = <fs_key_value> ) ) )
to ls_request_new-filter_select_options[].
" Technical Request Filters...
append value #( property = <fs_nav_prop>-dependent_field
select_options = value #( ( sign = 'I' option = 'EQ' low = <fs_key_value> ) ) )
to ls_request_new-technical_request-filter_select_options[].
endif.
endloop.
" Create New Request Context...
create data lr_request like ls_request_new.
assign lr_request->* to <ls_request>.
<ls_request> = ls_request_new.
create object rv_request_filter
exporting
ir_request_details = lr_request
it_headers = ls_request_new-technical_request-request_header
io_model = io_model.
endmethod.
method convert_expand_to_filter_mul.
" The below is going to work only if the reference key is one field !!!
data: lo_request_filter type ref to /iwbep/cl_mgw_request.
data: ls_request type /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
data: ls_request_new type /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
data: lr_request type ref to /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
data: lt_select_options type /iwbep/t_cod_select_options.
data: lt_key_tab type /iwbep/t_mgw_name_value_pair.
data: lv_max_hits type i.
field-symbols:
<ls_request> type /iwbep/if_mgw_core_srv_runtime=>ty_s_mgw_request_context.
define: _move.
ls_request_new-&1 = ls_request-&1.
end-of-definition.
data(lv_data_lines) = lines( it_data[] ).
check: lv_data_lines > 0.
" Get Request Data...
ls_request = io_request_exp->get_request_details( ).
data(lv_entity_set_a) = _get_es_by_et_( io_tech_request_context = io_request_exp iv_et_name = iv_entity_type_a ).
data(lv_entity_set_b) = _get_es_by_et_( io_tech_request_context = io_request_exp iv_et_name = iv_entity_type_b ).
" Check Navigation Properties...
call method _get_navigation_properties_
exporting
io_tech_request_context = io_request_exp
iv_principal_et = iv_entity_type_a
iv_dependent_et = iv_entity_type_b
importing
et_nav_props = data(lt_nav_props).
if lines( lt_nav_props[] ) <> 1.
raise exception type /iwbep/cx_mgw_busi_exception
exporting
entity_type = iv_entity_type_a
message_unlimited = 'Expand Operation Not Possible !'.
endif.
read table lt_nav_props into es_nav_prop index 1.
" Copy Technical Details...
_move: service_doc_name, namespace, version, cache_timestamp, base_url,
http_method, icf_root_node, system_alias_info, context_params,
format, type, operation, incoming_message.
" Set Source and Target Properties...
ls_request_new-source_entity = iv_entity_type_b.
ls_request_new-target_entity = iv_entity_type_b.
ls_request_new-source_entity_set = lv_entity_set_b.
ls_request_new-target_entity_set = lv_entity_set_b.
ls_request_new-technical_request-service_name = ls_request_new-service_doc_name.
ls_request_new-technical_request-service_version = ls_request_new-version.
ls_request_new-technical_request-source_entity_type = ls_request_new-source_entity.
ls_request_new-technical_request-target_entity_type = ls_request_new-target_entity.
ls_request_new-technical_request-source_entity_set = ls_request_new-source_entity_set.
ls_request_new-technical_request-target_entity_set = ls_request_new-target_entity_set.
ls_request_new-technical_request-request_header = ls_request-technical_request-request_header.
" Special Handling for Max Hits...
lv_max_hits = ls_request-paging-top + ls_request-paging-skip.
if lv_max_hits > gc_max_hits.
ls_request_new-paging-top = lv_max_hits.
endif.
" Build Filter Table...
data(lv_key_field) = es_nav_prop-principal_field.
loop at it_data assigning field-symbol(<fs_data>).
data(lv_tabix) = sy-tabix.
assign component lv_key_field of structure <fs_data> to field-symbol(<fs_key>).
if sy-subrc = 0.
append value #( sign = 'I' option = 'EQ' low = <fs_key> ) to lt_select_options[].
append value #( name = lv_key_field value = <fs_key> ) to lt_key_tab[].
if lines( lt_select_options[] ) >= 50 or lv_tabix = lv_data_lines. " Pack Size 50 or Last Row...
" Set Select Options...
sort lt_select_options[].
ls_request_new-filter_select_options[] = value #( ( property = es_nav_prop-dependent_field
select_options = lt_select_options[] ) ).
ls_request_new-technical_request-filter_select_options[] = ls_request_new-filter_select_options[].
" Set Key...
move-corresponding: lt_key_tab[] to ls_request_new-key_tab[].
move-corresponding: lt_key_tab[] to ls_request_new-technical_request-key_tab[].
" Create New Request Context...
create data lr_request like ls_request_new.
assign lr_request->* to <ls_request>.
<ls_request> = ls_request_new.
create object lo_request_filter
exporting
ir_request_details = lr_request
it_headers = ls_request_new-technical_request-request_header
io_model = io_model.
if lo_request_filter is bound.
append lo_request_filter to et_request_filter[].
endif.
clear: lt_select_options[],
lt_key_tab[].
endif. " if lines( lt_select_options[] ) >= 50....
endif.
endloop.
endmethod. "#EC CI_VALPAR
method convert_select_options.
statics: so_str_descr type ref to cl_abap_structdescr,
sv_name type cdsview_source.
" Get Descriptor...
if iv_name is supplied.
if iv_name ne sv_name or so_str_descr is not bound.
clear: sv_name, so_str_descr.
so_str_descr ?= cl_abap_structdescr=>describe_by_name( iv_name ).
check: so_str_descr is bound.
sv_name = iv_name.
endif.
elseif iv_structure is supplied.
clear: sv_name, so_str_descr.
so_str_descr ?= cl_abap_structdescr=>describe_by_data( iv_structure ).
check: so_str_descr is bound.
endif.
" Convert Options...
try.
if so_str_descr->is_ddic_type( ).
convert_so_ddic_( exporting ir_struct_descr = so_str_descr
changing ct_select_options = ct_select_options
ct_filter_expressions = ct_filter_expressions ).
else.
convert_so_free_( exporting ir_struct_descr = so_str_descr
changing ct_select_options = ct_select_options
ct_filter_expressions = ct_filter_expressions ).
endif.
catch cx_root into data(lx_root).
raise exception type /iwbep/cx_mgw_busi_exception
exporting
previous = lx_root.
endtry.
endmethod.
method convert_so_ddic_.
data: lr_str_descr type ref to cl_abap_structdescr.
data: lt_fields type ddfields.
data: lt_comps type cl_abap_structdescr=>component_table.
data: lt_range_comps type cl_abap_structdescr=>component_table.
data: lr_range_str_descr type ref to cl_abap_structdescr.
data: lr_range_tab_descr type ref to cl_abap_tabledescr.
data: lr_range_line type ref to data.
data: lr_range_tab_i type ref to data.
data: lr_range_tab_e type ref to data.
data: lr_field type ref to data.
data: lv_func_name type rs38l-name.
data: lv_include_found type abap_bool.
data: lv_tabix type i.
data: lv_max_len type i.
field-symbols: <fs_ext_tab> type standard table,
<fs_int_tab> type standard table,
<fs_line> type any,
<fs_any> type any.
" Get Descriptor...
lr_str_descr ?= ir_struct_descr.
check: lr_str_descr is bound.
check: lr_str_descr->is_ddic_type( ) is not initial.
" Get Fields...
lt_fields = lr_str_descr->get_ddic_field_list( ).
" Get Components (Can Be Includes)
lt_comps = lr_str_descr->get_components( ).
do.
lv_include_found = abap_false.
* loop at lt_comps into data(ls_comps) where as_include = abap_true.
* lv_tabix = sy-tabix.
* lv_include_found = abap_true.
*
* clear: lr_str_descr.
* lr_str_descr ?= ls_comps-type.
* if lr_str_descr is bound.
* insert lines of lr_str_descr->get_components( ) into lt_comps[] index lv_tabix.
* endif.
* delete table lt_comps from ls_comps. <<<<<<<<< STOPPED WORKING....
* endloop.
loop at lt_comps assigning field-symbol(<fs_comp>) where as_include = abap_true.
lv_tabix = sy-tabix.
lv_include_found = abap_true.
clear: lr_str_descr.
lr_str_descr ?= <fs_comp>-type.
if lr_str_descr is bound.
insert lines of lr_str_descr->get_components( ) into lt_comps[] index lv_tabix.
endif.
clear: <fs_comp>.
endloop.
if lv_include_found = abap_false.
delete lt_comps[] where table_line is initial.
exit.
endif.
enddo.
" Convert Select Options...
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
loop at ct_select_options assigning field-symbol(<fs_select_option>).
read table lt_fields assigning field-symbol(<fs_field>)
with key fieldname = <fs_select_option>-property.
if sy-subrc = 0.
" Explicitly Check on Field Length...
" Should never happen, if SEGW is correct. JIRA: https://sapjira.wdf.sap.corp/browse/KNGMHM02-22811
loop at <fs_select_option>-select_options assigning field-symbol(<fs_so>).
lv_max_len = <fs_field>-outputlen.
if lv_max_len > 0.
if strlen( <fs_so>-low ) > lv_max_len or strlen( <fs_so>-high ) > lv_max_len.
zcx_odata_tools=>raise_length_exceeded_l( property = <fs_select_option>-property
length = lv_max_len ).
endif.