-
Notifications
You must be signed in to change notification settings - Fork 18
/
SDE_750.abap
3897 lines (3390 loc) · 140 KB
/
SDE_750.abap
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
*&---------------------------------------------------------------------*
*& Simple SQL Explorer
*&---------------------------------------------------------------------*
*& version: beta 0.7.252.202
*& GIT: https://github.com/ysichov/SDE/blob/master/SDE_750.abap - here may be most actual version
*& AbapGit https://github.com/ysichov/SDE_abapgit
*& RU description https://ysychov.wordpress.com/2020/02/10/simple-data-explorer/
*& EN description https://blogs.sap.com/2020/03/22/simple-data-explorer/
*& Multi-windows program for viewing tables, views, salary clusters, CDS and some links between them
*& Written by Yurii Sychov
*& e-mail: [email protected]
*& skype: ysichov
*& blog: https://ysychov.wordpress.com/blog/
*& LinkedIn: https://www.linkedin.com/in/ysychov/
*&---------------------------------------------------------------------*
*& External resources
*& https://github.com/bizhuka/eui - ALV listboxes
REPORT z_sde.
FIELD-SYMBOLS: <g_str> TYPE any.
CLASS lcl_data_receiver DEFINITION DEFERRED.
CLASS lcl_data_transmitter DEFINITION DEFERRED.
CLASS lcl_types DEFINITION ABSTRACT.
PUBLIC SECTION.
TYPES:
BEGIN OF selection_display_s,
ind TYPE i,
field_label TYPE lvc_fname,
int_type(1),
inherited TYPE aqadh_type_of_icon,
emitter TYPE aqadh_type_of_icon,
sign TYPE tvarv_sign,
opti TYPE tvarv_opti,
option_icon TYPE aqadh_type_of_icon,
low TYPE string,
high TYPE string,
more_icon TYPE aqadh_type_of_icon,
range TYPE aqadh_t_ranges,
name TYPE reptext,
element TYPE text60,
domain TYPE text60,
datatype TYPE string,
length TYPE i,
transmitter TYPE REF TO lcl_data_transmitter,
receiver TYPE REF TO lcl_data_receiver,
color TYPE lvc_t_scol,
style TYPE lvc_t_styl,
drop_down TYPE int4,
END OF selection_display_s,
BEGIN OF t_sel_row,
sign TYPE tvarv_sign,
opti TYPE tvarv_opti,
option_icon TYPE aqadh_type_of_icon,
low TYPE string, "aqadh_range_value,
high TYPE string, "aqadh_range_value,
more_icon TYPE aqadh_type_of_icon,
range TYPE aqadh_t_ranges,
END OF t_sel_row.
CLASS-DATA: mt_sel TYPE TABLE OF lcl_types=>selection_display_s.
ENDCLASS.
CLASS lcl_table_viewer DEFINITION DEFERRED.
CLASS lcl_box_handler DEFINITION DEFERRED.
CLASS lcl_sel_opt DEFINITION DEFERRED.
"Begin of INCLUDE YS_SDE_CLASSES.
CLASS lcl_popup DEFINITION.
PUBLIC SECTION.
CLASS-DATA m_counter TYPE i.
DATA: mo_box TYPE REF TO cl_gui_dialogbox_container,
mo_splitter TYPE REF TO cl_gui_splitter_container,
mo_parent TYPE REF TO cl_gui_container,
m_additional_name TYPE string.
METHODS: constructor IMPORTING i_additional_name TYPE string OPTIONAL,
create IMPORTING i_width TYPE i
i_hight TYPE i
i_name TYPE text100 OPTIONAL
RETURNING VALUE(ro_box) TYPE REF TO cl_gui_dialogbox_container,
on_box_close FOR EVENT close OF cl_gui_dialogbox_container IMPORTING sender.
ENDCLASS.
CLASS lcl_popup IMPLEMENTATION.
METHOD constructor.
m_additional_name = i_additional_name.
ENDMETHOD.
METHOD create.
DATA: l_top TYPE i,
l_left TYPE i.
ADD 1 TO m_counter.
l_top = l_left = 10 + 10 * ( m_counter DIV 5 ) + ( m_counter MOD 5 ) * 50.
CREATE OBJECT ro_box
EXPORTING
width = i_width
height = i_hight
top = l_top
left = l_left
caption = i_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
event_already_registered = 6
error_regist_event = 7
OTHERS = 8.
IF sy-subrc <> 0.
RETURN.
ENDIF.
ENDMETHOD.
METHOD on_box_close.
sender->free( ).
ENDMETHOD.
ENDCLASS.
CLASS lcl_ddic DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: get_text_table IMPORTING i_tname TYPE tabname
EXPORTING e_tab TYPE tabname.
ENDCLASS.
CLASS lcl_ddic IMPLEMENTATION.
METHOD get_text_table.
CALL FUNCTION 'DDUT_TEXTTABLE_GET'
EXPORTING
tabname = i_tname
IMPORTING
texttable = e_tab.
ENDMETHOD.
ENDCLASS.
CLASS lcl_dd_data DEFINITION."drag&drop data
PUBLIC SECTION.
DATA: m_row TYPE i,
m_column TYPE lvc_s_col.
ENDCLASS.
CLASS lcl_dragdrop DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
drag FOR EVENT ondrag OF cl_gui_alv_grid IMPORTING e_dragdropobj e_row e_column ,
drop FOR EVENT ondrop OF cl_gui_alv_grid IMPORTING e_dragdropobj e_row.
ENDCLASS.
CLASS lcl_sql DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
read_any_table IMPORTING i_tabname TYPE tabname
i_where TYPE string
i_row_count TYPE i OPTIONAL
CHANGING cr_tab TYPE REF TO data
c_count TYPE i,
exist_table IMPORTING i_tab TYPE tabname RETURNING VALUE(e_subrc) LIKE sy-subrc,
exist_view IMPORTING i_tab TYPE tabname RETURNING VALUE(e_subrc) LIKE sy-subrc,
exist_cds IMPORTING i_tab TYPE tabname RETURNING VALUE(e_subrc) LIKE sy-subrc .
ENDCLASS.
CLASS lcl_sql IMPLEMENTATION.
METHOD read_any_table.
FIELD-SYMBOLS: <f_tab> TYPE ANY TABLE.
ASSIGN cr_tab->* TO <f_tab>.
c_count = lines( <f_tab> ).
CHECK lcl_sql=>exist_table( i_tabname ) = 1.
IF i_where IS NOT INITIAL.
TRY.
SELECT * FROM (i_tabname) INTO CORRESPONDING FIELDS OF TABLE <f_tab> WHERE (i_where) ORDER BY PRIMARY KEY
.
CATCH cx_sy_dynamic_osql_semantics. "#EC NO_HANDLER
CATCH cx_sy_dynamic_osql_syntax. "#EC NO_HANDLER
CATCH cx_sy_conversion_no_number. "#EC NO_HANDLER
ENDTRY.
ELSE.
IF i_row_count IS NOT SUPPLIED.
SELECT * FROM (i_tabname) INTO CORRESPONDING FIELDS OF TABLE <f_tab> ORDER BY PRIMARY KEY.
ELSE.
SELECT * FROM (i_tabname) INTO CORRESPONDING FIELDS OF TABLE <f_tab> UP TO i_row_count ROWS ORDER BY PRIMARY KEY..
ENDIF.
ENDIF.
c_count = sy-dbcnt.
ENDMETHOD.
METHOD exist_table.
SELECT COUNT( * ) FROM dd02l
WHERE tabname = i_tab
AND ( tabclass = 'TRANSP' OR tabclass = 'CLUSTER' ).
e_subrc = sy-dbcnt.
ENDMETHOD.
METHOD exist_view.
SELECT COUNT( * ) FROM dd02l
WHERE tabname = i_tab
AND tabclass = 'VIEW'.
e_subrc = sy-dbcnt.
ENDMETHOD.
METHOD exist_cds.
SELECT COUNT( * ) FROM dd02l
WHERE tabname = i_tab
AND tabclass = 'VIEW'
AND applclass = 'SDGV'.
e_subrc = sy-dbcnt.
ENDMETHOD.
ENDCLASS.
CLASS lcl_alv_common DEFINITION.
PUBLIC SECTION.
CONSTANTS: c_white(4) TYPE x VALUE '00000001', "white background
c_grey(4) TYPE x VALUE '00000003', "gray background
c_green(4) TYPE x VALUE '00000216', "green +underline
c_blue(4) TYPE x VALUE '00000209', " blue font +underline
c_bold(4) TYPE x VALUE '00000020'.
TYPES: BEGIN OF t_tabfields.
INCLUDE TYPE dfies.
TYPES: empty TYPE xfeld,
is_text TYPE xfeld,
END OF t_tabfields.
CLASS-DATA: mt_tabfields TYPE HASHED TABLE OF t_tabfields WITH UNIQUE KEY tabname fieldname.
CLASS-METHODS:
refresh IMPORTING i_obj TYPE REF TO cl_gui_alv_grid i_layout TYPE lvc_s_layo OPTIONAL i_soft TYPE char01 OPTIONAL,
translate_field IMPORTING i_lang TYPE ddlanguage OPTIONAL CHANGING c_fld TYPE lvc_s_fcat,
get_selected IMPORTING i_obj TYPE REF TO cl_gui_alv_grid RETURNING VALUE(e_index) TYPE i.
ENDCLASS.
CLASS lcl_alv_common IMPLEMENTATION.
METHOD refresh.
DATA l_stable TYPE lvc_s_stbl.
l_stable = 'XX'.
IF i_layout IS SUPPLIED.
i_obj->set_frontend_layout( i_layout ) .
ENDIF.
i_obj->refresh_table_display( EXPORTING is_stable = l_stable i_soft_refresh = i_soft ).
ENDMETHOD.
METHOD translate_field.
DATA: lt_field_info TYPE TABLE OF dfies.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = c_fld-tabname
fieldname = c_fld-fieldname
langu = i_lang
TABLES
dfies_tab = lt_field_info
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc = 0.
READ TABLE lt_field_info INDEX 1 INTO DATA(l_info).
IF l_info-scrtext_l IS INITIAL AND l_info-scrtext_m IS INITIAL AND l_info-scrtext_s IS INITIAL.
IF l_info-fieldtext IS NOT INITIAL.
MOVE l_info-fieldtext TO: c_fld-reptext, c_fld-scrtext_l, c_fld-scrtext_m, c_fld-scrtext_s .
ELSE.
MOVE l_info-fieldname TO: c_fld-reptext, c_fld-scrtext_l, c_fld-scrtext_m, c_fld-scrtext_s .
ENDIF.
ELSE.
c_fld-scrtext_l = l_info-scrtext_l.
c_fld-scrtext_m = l_info-scrtext_m.
c_fld-scrtext_s = l_info-scrtext_s.
IF l_info-reptext IS NOT INITIAL.
c_fld-reptext = l_info-reptext.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD get_selected.
i_obj->get_selected_cells( IMPORTING et_cell = DATA(lt_sel_cells) ).
IF lines( lt_sel_cells ) > 0.
e_index = lt_sel_cells[ 1 ]-row_id.
ELSE.
i_obj->get_selected_rows( IMPORTING et_index_rows = DATA(lt_sel_rows) ).
IF lines( lt_sel_rows ) > 0.
e_index = lt_sel_rows[ 1 ]-index.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS lcl_rtti DEFINITION.
PUBLIC SECTION.
CONSTANTS:
BEGIN OF mc_ui_type,
" Simple UI types
char TYPE string VALUE 'char',
numc TYPE string VALUE 'numc',
numeric TYPE string VALUE 'numeric',
boolean TYPE string VALUE 'boolean',
date TYPE string VALUE 'date',
time TYPE string VALUE 'time',
datetime TYPE string VALUE 'datetime',
" Complext UI types
string TYPE string VALUE 'string',
range TYPE string VALUE 'range',
table TYPE string VALUE 'table',
END OF mc_ui_type .
TYPES: BEGIN OF ts_field_desc,
name(61),
sys_type TYPE abap_typekind, " SYSTEM
ui_type TYPE string, " Only for KIND = P
length TYPE i, " Only for KIND = P
decimals TYPE i, " Only for KIND = P
" For editing in ALV
rollname(61),
label TYPE dfies-fieldtext,
" Table description
table_kind TYPE abap_tablekind,
unique TYPE abap_bool,
key TYPE abap_keydescr_tab,
key_defkind TYPE abap_keydefkind,
sub_fdesc TYPE string,
END OF ts_field_desc .
TYPES:
tt_field_desc TYPE HASHED TABLE OF ts_field_desc WITH UNIQUE KEY name .
TYPES:
tt_unique_type TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line .
CLASS-METHODS:
create_table_by_name IMPORTING i_tname TYPE tabname
CHANGING c_table TYPE REF TO data,
create_struc_handle IMPORTING i_tname TYPE tabname
EXPORTING e_t_comp TYPE abap_component_tab
e_handle TYPE REF TO cl_abap_structdescr,
create_structure IMPORTING io_range TYPE REF TO cl_abap_datadescr OPTIONAL
iv_sub_fdesc TYPE string OPTIONAL
it_field_desc TYPE tt_field_desc OPTIONAL
RETURNING VALUE(ro_struct) TYPE REF TO cl_abap_structdescr,
find_table_fieldname
IMPORTING
ir_unique_type TYPE REF TO tt_unique_type
CHANGING
cv_rollname TYPE csequence
cv_label TYPE csequence OPTIONAL,
get_field_desc
IMPORTING
iv_field_name TYPE csequence OPTIONAL
iv_data TYPE any OPTIONAL
is_sh_field TYPE dfies OPTIONAL
ir_unique_type TYPE REF TO tt_unique_type OPTIONAL
RETURNING VALUE(rs_field_desc) TYPE ts_field_desc,
create_type_descr IMPORTING iv_rollname TYPE csequence OPTIONAL
is_field_desc TYPE ts_field_desc OPTIONAL
VALUE(ir_type) TYPE REF TO data OPTIONAL
RETURNING
VALUE(ro_type) TYPE REF TO cl_abap_datadescr,
find_drop_down IMPORTING io_grid TYPE REF TO cl_gui_alv_grid
CHANGING cs_fieldcat TYPE lvc_s_fcat cv_drdn_hndl TYPE i,
is_list_box IMPORTING iv_tabname TYPE dfies-tabname iv_fieldname TYPE dfies-fieldname
EXPORTING ev_list_box TYPE abap_bool es_sh_desc TYPE shlp_descr.
ENDCLASS.
CLASS lcl_rtti IMPLEMENTATION.
METHOD create_struc_handle.
DATA: ls_comp TYPE abap_componentdescr,
lt_components TYPE abap_component_tab,
lt_field_info TYPE TABLE OF dfies.
lcl_ddic=>get_text_table( EXPORTING i_tname = i_tname IMPORTING e_tab = DATA(l_texttab) ).
e_handle ?= cl_abap_typedescr=>describe_by_name( i_tname ).
IF l_texttab IS NOT INITIAL.
DATA(lo_texttab) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_name( l_texttab ) ).
LOOP AT e_handle->components INTO DATA(l_descr).
ls_comp-name = l_descr-name.
ls_comp-type ?= e_handle->get_component_type( ls_comp-name ).
APPEND ls_comp TO lt_components.
ENDLOOP.
LOOP AT lo_texttab->components INTO l_descr.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = l_texttab
fieldname = l_descr-name
langu = sy-langu
TABLES
dfies_tab = lt_field_info
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
CHECK sy-subrc = 0.
IF lt_field_info[ 1 ]-keyflag = abap_false.
ls_comp-name = l_texttab && '_' && l_descr-name.
ls_comp-type ?= lo_texttab->get_component_type( l_descr-name ).
APPEND: ls_comp TO lt_components,
ls_comp TO e_t_comp.
READ TABLE lcl_alv_common=>mt_tabfields INTO DATA(ls_tf) WITH KEY tabname = i_tname fieldname = l_texttab.
IF sy-subrc NE 0.
MOVE-CORRESPONDING lt_field_info[ 1 ] TO ls_tf.
ls_tf-tabname = i_tname.
ls_tf-fieldname = ls_comp-name.
ls_tf-is_text = abap_true.
INSERT ls_tf INTO TABLE lcl_alv_common=>mt_tabfields.
ENDIF.
ENDIF.
ENDLOOP.
e_handle = cl_abap_structdescr=>create( lt_components ).
ENDIF.
ENDMETHOD.
METHOD create_table_by_name.
DATA: lo_new_tab TYPE REF TO cl_abap_tabledescr,
lo_new_type TYPE REF TO cl_abap_structdescr.
create_struc_handle( EXPORTING i_tname = i_tname IMPORTING e_handle = lo_new_type ).
lo_new_tab = cl_abap_tabledescr=>create(
p_line_type = lo_new_type
p_table_kind = cl_abap_tabledescr=>tablekind_std
p_unique = abap_false ).
CREATE DATA c_table TYPE HANDLE lo_new_tab. "Create a New table type
ENDMETHOD.
METHOD is_list_box. "copied from https://github.com/bizhuka/eui
CLEAR: ev_list_box,
es_sh_desc.
CALL FUNCTION 'F4IF_DETERMINE_SEARCHHELP'
EXPORTING
tabname = iv_tabname
fieldname = iv_fieldname
IMPORTING
shlp = es_sh_desc
EXCEPTIONS
OTHERS = 1.
" Fixed values of domains
CHECK sy-subrc = 0 AND es_sh_desc-shlptype = 'FV'.
ev_list_box = abap_true.
ENDMETHOD.
METHOD find_drop_down. "copied from https://github.com/bizhuka/eui
DATA:
ls_sh_desc TYPE shlp_descr,
lv_list_box TYPE abap_bool,
lt_fielddescr TYPE ddfields,
ls_field TYPE REF TO dfies,
lt_field_desc TYPE tt_field_desc,
ls_field_desc TYPE ts_field_desc,
lo_struc TYPE REF TO cl_abap_structdescr,
lo_table TYPE REF TO cl_abap_tabledescr,
lr_table TYPE REF TO data,
lt_shlp_return TYPE STANDARD TABLE OF ddshretval,
ls_shlp_return TYPE REF TO ddshretval,
lv_prev_pos TYPE i,
ls_call_control TYPE ddshf4ctrl,
ls_fld_prop TYPE REF TO ddshfprop,
lt_shlp_descr_tab TYPE shlp_desct,
lt_shlp_record TYPE STANDARD TABLE OF seahlpres,
lt_dropdown TYPE lvc_t_dral,
ls_dropdown TYPE lvc_s_dral.
FIELD-SYMBOLS:
<lt_table> TYPE STANDARD TABLE,
<ls_row> TYPE any,
<lv_value> TYPE any,
<lv_low> TYPE any,
<lv_txt> TYPE csequence.
" No need
IF cs_fieldcat-ref_table = abap_undefined AND cs_fieldcat-ref_field = abap_undefined.
CLEAR cs_fieldcat-ref_table.
CLEAR cs_fieldcat-ref_field.
RETURN.
ENDIF.
" No need
CHECK cs_fieldcat-checkbox <> abap_true
AND cs_fieldcat-hotspot <> abap_true.
" Get top SH
is_list_box(
EXPORTING
iv_tabname = cs_fieldcat-ref_table
iv_fieldname = cs_fieldcat-ref_field
IMPORTING
ev_list_box = lv_list_box
es_sh_desc = ls_sh_desc ).
CHECK lv_list_box = abap_true.
" Work with copy
lt_fielddescr[] = ls_sh_desc-fielddescr[].
"TRY.
" Strucure fields
LOOP AT lt_fielddescr REFERENCE INTO ls_field.
ls_field_desc = get_field_desc( is_sh_field = ls_field->* ).
INSERT ls_field_desc INTO TABLE lt_field_desc.
ENDLOOP.
" Output table
lo_struc = create_structure( it_field_desc = lt_field_desc ).
lo_table = cl_abap_tabledescr=>create( p_line_type = lo_struc ).
" Asign it
CREATE DATA lr_table TYPE HANDLE lo_table.
ASSIGN lr_table->* TO <lt_table>.
CALL FUNCTION 'F4IF_SELECT_VALUES'
EXPORTING
shlp = ls_sh_desc
maxrows = 0 " all values of domain
call_shlp_exit = abap_true " 'SELECT' only!
TABLES
return_tab = lt_shlp_return.
**********************************************************************
" Copied from --> METHOD get_sh_table.
**********************************************************************
" Show all fields
LOOP AT ls_sh_desc-fieldprop REFERENCE INTO ls_fld_prop.
ls_fld_prop->shlpoutput = abap_true.
ENDLOOP.
" Call with SELECT event only (probably no texts)
IF ls_sh_desc-intdescr-selmexit IS INITIAL.
CALL FUNCTION 'F4IF_SELECT_VALUES'
EXPORTING
shlp = ls_sh_desc
maxrows = 0 " all values of domain
call_shlp_exit = abap_true " 'SELECT' only!
TABLES
return_tab = lt_shlp_return.
ELSE.
" Get records first
CALL FUNCTION 'F4IF_SELECT_VALUES'
EXPORTING
shlp = ls_sh_desc
maxrows = 0 " all values of domain
call_shlp_exit = abap_true
TABLES
record_tab = lt_shlp_record.
" Disp event
ls_call_control-step = 'DISP'.
ls_call_control-maxrecords = 0. " all values of domain
APPEND ls_sh_desc TO lt_shlp_descr_tab.
CALL FUNCTION ls_sh_desc-intdescr-selmexit
TABLES
shlp_tab = lt_shlp_descr_tab
record_tab = lt_shlp_record
CHANGING
shlp = ls_sh_desc
callcontrol = ls_call_control.
" To normal state -> lt_shlp_return
CLEAR lt_shlp_return.
PERFORM transform_outval IN PROGRAM saplsdsd
TABLES lt_shlp_record lt_shlp_return
USING ls_call_control ls_sh_desc.
ENDIF.
" Write data to table
lv_prev_pos = 0.
SORT ls_sh_desc-fielddescr BY fieldname.
LOOP AT lt_shlp_return REFERENCE INTO ls_shlp_return.
" New row ?
IF lv_prev_pos <> ls_shlp_return->recordpos.
APPEND INITIAL LINE TO <lt_table> ASSIGNING <ls_row>.
ENDIF.
lv_prev_pos = ls_shlp_return->recordpos.
" value
ASSIGN COMPONENT ls_shlp_return->fieldname OF STRUCTURE <ls_row> TO <lv_value>.
CHECK sy-subrc = 0.
" Copy field field
READ TABLE ls_sh_desc-fielddescr REFERENCE INTO ls_field BINARY SEARCH
WITH KEY fieldname = ls_shlp_return->fieldname.
" Special case for certain types
CASE ls_field->inttype.
WHEN cl_abap_typedescr=>typekind_time.
CONCATENATE ls_shlp_return->fieldval+0(2)
ls_shlp_return->fieldval+3(2)
ls_shlp_return->fieldval+6(2) INTO <lv_value>.
WHEN cl_abap_typedescr=>typekind_date.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = ls_shlp_return->fieldval
IMPORTING
date_internal = <lv_value>
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
CLEAR <lv_value>.
ENDIF.
" Integer, byte, short
WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2.
RETURN.
* REPLACE ALL OCCURRENCES OF '.' IN ls_shlp_return->fieldval WITH ''.
* CONDENSE ls_shlp_return->fieldval NO-GAPS.
* <lv_value> = ls_shlp_return->fieldval.
WHEN OTHERS.
<lv_value> = ls_shlp_return->fieldval.
ENDCASE.
ENDLOOP.
" Next handle
ADD 1 TO cv_drdn_hndl.
" Prepare field catalog
cs_fieldcat-drdn_hndl = cv_drdn_hndl.
cs_fieldcat-drdn_alias = abap_true.
LOOP AT <lt_table> ASSIGNING <ls_row>.
ASSIGN COMPONENT:
'_LOW' OF STRUCTURE <ls_row> TO <lv_low>,
'_TEXT' OF STRUCTURE <ls_row> TO <lv_txt>.
ls_dropdown-handle = cs_fieldcat-drdn_hndl.
ls_dropdown-int_value = <lv_low>.
ls_dropdown-value = <lv_low>.
"CONCATENATE ls_dropdown-value ` - ` <lv_txt> INTO ls_dropdown-value.
" Add new item to dropdown
APPEND ls_dropdown TO lt_dropdown.
ENDLOOP.
io_grid->set_drop_down_table(
it_drop_down_alias = lt_dropdown ).
ENDMETHOD.
METHOD get_field_desc.
DATA:
ls_header TYPE x030l,
lr_table_descr TYPE REF TO cl_abap_tabledescr,
lr_struct_descr TYPE REF TO cl_abap_structdescr,
lv_cnt TYPE i,
lr_row TYPE REF TO data,
lo_type TYPE REF TO cl_abap_typedescr,
lt_sub_fdesc TYPE tt_field_desc,
ls_subfield TYPE ts_field_desc.
FIELD-SYMBOLS:
<ls_comp_tab> TYPE abap_compdescr,
<ls_row> TYPE any,
<lv_subvalue> TYPE any,
<ls_subfield> LIKE ls_subfield.
IF is_sh_field IS NOT INITIAL.
rs_field_desc-name = is_sh_field-fieldname.
rs_field_desc-sys_type = is_sh_field-inttype.
rs_field_desc-length = is_sh_field-leng.
rs_field_desc-decimals = is_sh_field-decimals.
rs_field_desc-label = is_sh_field-fieldtext.
rs_field_desc-rollname = is_sh_field-rollname.
ELSE.
lo_type = cl_abap_typedescr=>describe_by_data( iv_data ).
rs_field_desc-name = iv_field_name.
rs_field_desc-sys_type = lo_type->type_kind. "kind.
rs_field_desc-length = lo_type->length.
rs_field_desc-decimals = lo_type->decimals.
IF lo_type->is_ddic_type( ) = abap_true.
rs_field_desc-rollname = lo_type->get_relative_name( ).
ENDIF.
ENDIF.
CASE rs_field_desc-sys_type.
WHEN cl_abap_typedescr=>typekind_char.
" Also CHAR
CASE rs_field_desc-rollname.
WHEN 'XSDBOOLEAN'.
rs_field_desc-ui_type = mc_ui_type-boolean.
WHEN 'XSDDATETIME_Z' OR 'XSDDATETIME_LONG_Z' OR
'XSDDATETIME_OFFSET' OR 'XSDDATETIME_LOCAL' OR 'XSDDATETIME_LOCAL_DT'.
rs_field_desc-ui_type = mc_ui_type-datetime.
WHEN OTHERS.
rs_field_desc-ui_type = mc_ui_type-char.
ENDCASE.
WHEN cl_abap_typedescr=>typekind_num OR cl_abap_typedescr=>typekind_numeric.
rs_field_desc-ui_type = mc_ui_type-numc.
" Memo text
WHEN cl_abap_typedescr=>typekind_string.
rs_field_desc-ui_type = mc_ui_type-string.
rs_field_desc-rollname = 'STRINGVAL'.
WHEN cl_abap_typedescr=>typekind_table.
rs_field_desc-ui_type = mc_ui_type-table.
lr_table_descr ?= lo_type.
rs_field_desc-table_kind = lr_table_descr->table_kind.
rs_field_desc-unique = lr_table_descr->has_unique_key.
rs_field_desc-key = lr_table_descr->key.
rs_field_desc-key_defkind = lr_table_descr->key_defkind.
" No need for standardc table
IF rs_field_desc-table_kind = cl_abap_tabledescr=>tablekind_std.
CLEAR rs_field_desc-key.
ENDIF.
" Only for structures
TRY.
lr_struct_descr ?= lr_table_descr->get_table_line_type( ).
CATCH cx_sy_move_cast_error.
* MESSAGE s016(zeui_message) WITH rs_field_desc-name INTO sy-msgli.
* zcx_eui_exception=>raise_sys_error( ).
ENDTRY.
" For speed creation
IF lr_struct_descr->is_ddic_type( ) = abap_true.
ls_header = lr_struct_descr->get_ddic_header( ).
rs_field_desc-rollname = ls_header-tabname.
ENDIF.
" Create STANDARD table for field catalog!
CREATE DATA lr_row TYPE HANDLE lr_struct_descr.
ASSIGN lr_row->* TO <ls_row>.
CLEAR:
rs_field_desc-sub_fdesc,
lt_sub_fdesc.
LOOP AT lr_struct_descr->components ASSIGNING <ls_comp_tab>.
ASSIGN COMPONENT <ls_comp_tab>-name OF STRUCTURE <ls_row> TO <lv_subvalue>.
" Recursion
ls_subfield = get_field_desc( iv_field_name = <ls_comp_tab>-name
iv_data = <lv_subvalue>
ir_unique_type = ir_unique_type ).
INSERT ls_subfield INTO TABLE lt_sub_fdesc.
ENDLOOP.
" Select option ?
DO 1 TIMES.
lv_cnt = lines( lt_sub_fdesc ).
CHECK lv_cnt = 4.
" Check by name
LOOP AT lt_sub_fdesc TRANSPORTING NO FIELDS WHERE
name = 'SIGN' OR name = 'OPTION' OR name = 'LOW' OR name = 'HIGH'. "#EC CI_HASHSEQ
lv_cnt = lv_cnt - 1.
ENDLOOP.
" Select-option
CHECK lv_cnt = 0.
rs_field_desc-ui_type = mc_ui_type-range.
" No need in components
CLEAR rs_field_desc-sub_fdesc.
" Where to find TABLE-FIELDNAME
READ TABLE lt_sub_fdesc ASSIGNING <ls_subfield>
WITH TABLE KEY name = 'LOW'.
rs_field_desc-rollname = <ls_subfield>-rollname.
rs_field_desc-label = <ls_subfield>-label.
ENDDO.
" Date
WHEN cl_abap_typedescr=>typekind_date.
rs_field_desc-ui_type = mc_ui_type-date.
" Time
WHEN cl_abap_typedescr=>typekind_time.
rs_field_desc-ui_type = mc_ui_type-time.
" Integer, byte, short
WHEN cl_abap_typedescr=>typekind_int OR cl_abap_typedescr=>typekind_int1 OR cl_abap_typedescr=>typekind_int2.
rs_field_desc-ui_type = mc_ui_type-numeric.
" Double
WHEN cl_abap_typedescr=>typekind_packed OR cl_abap_typedescr=>typekind_float OR
'/' OR 'a' OR 'e'. " cl_abap_typedescr=>typekind_decfloat OR cl_abap_typedescr=>typekind_decfloat16 OR cl_abap_typedescr=>typekind_decfloat34.
rs_field_desc-ui_type = mc_ui_type-numeric.
WHEN OTHERS.
ENDCASE.
" TABLE-FIELDNAME from search help
IF is_sh_field-reffield IS NOT INITIAL.
CONCATENATE is_sh_field-reftable '-' is_sh_field-reffield INTO rs_field_desc-rollname.
ENDIF.
" Try to find TABLE-FIELDNAME
IF
rs_field_desc-ui_type <> mc_ui_type-table AND
rs_field_desc-ui_type <> mc_ui_type-string AND
rs_field_desc-rollname NP '*-*'.
find_table_fieldname(
EXPORTING
ir_unique_type = ir_unique_type
CHANGING
cv_rollname = rs_field_desc-rollname
cv_label = rs_field_desc-label ).
ENDIF.
" Set default text
IF rs_field_desc-label IS INITIAL.
rs_field_desc-label = rs_field_desc-name.
ENDIF.
ENDMETHOD.
METHOD find_table_fieldname.
TYPES:
BEGIN OF ts_dd03l,
tabname TYPE dd03l-tabname,
fieldname TYPE dd03l-fieldname,
shlporigin TYPE dd03l-shlporigin,
tab_len TYPE i,
END OF ts_dd03l.
DATA:
lv_rollname TYPE rollname,
lt_dd03l TYPE STANDARD TABLE OF ts_dd03l,
ls_dd03l TYPE REF TO ts_dd03l,
lv_tabfld TYPE string,
ls_dd04t TYPE dd04t,
lo_type TYPE REF TO cl_abap_datadescr.
FIELD-SYMBOLS:
<lt_unique_type> TYPE tt_unique_type.
" Table Fields
CHECK cv_rollname IS NOT INITIAL.
lv_rollname = cv_rollname.
SELECT d~tabname d~fieldname d~shlporigin INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
FROM dd03l AS d UP TO 100 ROWS
WHERE d~rollname = lv_rollname AND d~as4local = 'A' AND d~tabname NOT LIKE '/%' AND d~depth = 0.
" Find short table name
LOOP AT lt_dd03l REFERENCE INTO ls_dd03l.
ls_dd03l->tab_len = strlen( ls_dd03l->tabname ).
" In the end
IF ls_dd03l->shlporigin IS NOT INITIAL.
ls_dd03l->tab_len = ls_dd03l->tab_len - 1000.
ENDIF.
ENDLOOP.
SORT lt_dd03l BY tab_len ASCENDING.
" Try to find
ASSIGN ir_unique_type->* TO <lt_unique_type>.
LOOP AT lt_dd03l REFERENCE INTO ls_dd03l.
CONCATENATE ls_dd03l->tabname '-' ls_dd03l->fieldname INTO lv_tabfld.
" if type exist
TRY.
lo_type = create_type_descr( iv_rollname = lv_tabfld ).
* CATCH zcx_eui_exception.
* CLEAR lo_type.
ENDTRY.
CHECK lo_type IS NOT INITIAL.
" Get next item
IF ir_unique_type IS NOT INITIAL.
READ TABLE <lt_unique_type> TRANSPORTING NO FIELDS
WITH TABLE KEY table_line = lv_tabfld.
CHECK sy-subrc <> 0.
" Do not repeat types
INSERT lv_tabfld INTO TABLE <lt_unique_type>.
ENDIF.
cv_rollname = lv_tabfld.
DO 1 TIMES.
" If have no text
CHECK cv_label IS SUPPLIED AND cv_label IS INITIAL.
" №2
SELECT SINGLE * INTO ls_dd04t
FROM dd04t
WHERE rollname = lv_rollname
AND ddlanguage = sy-langu
AND as4local = 'A'
AND as4vers = 0.
CHECK sy-subrc = 0.
IF ls_dd04t-ddtext IS NOT INITIAL.
cv_label = ls_dd04t-ddtext.
ELSE.
cv_label = ls_dd04t-reptext.
ENDIF.
ENDDO.
RETURN.
ENDLOOP.
ENDMETHOD.
METHOD create_structure. "copied from https://github.com/bizhuka/eui
DATA:
lt_comp TYPE abap_component_tab,
lt_sub_fdesc TYPE tt_field_desc.
FIELD-SYMBOLS:
<ls_field_desc> TYPE ts_field_desc,
<ls_subfield> TYPE ts_field_desc,
<ls_comp> LIKE LINE OF lt_comp.
" №2 For select-options
IF io_range IS NOT INITIAL.
APPEND INITIAL LINE TO lt_comp ASSIGNING <ls_comp>.
<ls_comp>-name = 'SIGN'.
<ls_comp>-type = cl_abap_elemdescr=>get_c( p_length = 1 ).
APPEND INITIAL LINE TO lt_comp ASSIGNING <ls_comp>.
<ls_comp>-name = 'OPTION'.
<ls_comp>-type = cl_abap_elemdescr=>get_c( p_length = 2 ).
APPEND INITIAL LINE TO lt_comp ASSIGNING <ls_comp>.
<ls_comp>-name = 'LOW'.
<ls_comp>-type = io_range.
APPEND INITIAL LINE TO lt_comp ASSIGNING <ls_comp>.
<ls_comp>-name = 'HIGH'.
<ls_comp>-type = io_range.
ENDIF.
" №4 Called from constructor if have in DB cluster
LOOP AT it_field_desc ASSIGNING <ls_field_desc>.
" Create sub levels
APPEND INITIAL LINE TO lt_comp ASSIGNING <ls_comp>.
<ls_comp>-name = <ls_field_desc>-name.
<ls_comp>-type = create_type_descr( is_field_desc = <ls_field_desc> ).
ENDLOOP.
ro_struct = cl_abap_structdescr=>create( lt_comp ).
ENDMETHOD.
METHOD create_type_descr. "copied from https://github.com/bizhuka/eui
DATA:
lo_line TYPE REF TO cl_abap_datadescr,
lo_type TYPE REF TO cl_abap_typedescr,
lv_sys_type TYPE abap_typekind,
lv_message TYPE string.
" No type
CLEAR ro_type.
" №0
IF is_field_desc IS SUPPLIED.
" For tables speed 1
IF is_field_desc-rollname IS NOT INITIAL.
ro_type = create_type_descr(
iv_rollname = is_field_desc-rollname ).
ENDIF.
IF ro_type IS INITIAL.
lv_sys_type = is_field_desc-sys_type.
" For old option wrong is_field_desc-sys_type
IF lv_sys_type = cl_abap_typedescr=>typekind_table AND is_field_desc-ui_type = mc_ui_type-range.
" usually char
lv_sys_type = cl_abap_typedescr=>typekind_char.
" Show warning
CONCATENATE `No right type for ` is_field_desc-name ` ` is_field_desc-rollname `!` INTO lv_message.
MESSAGE lv_message TYPE 'S' DISPLAY LIKE 'W'.
ENDIF.
CASE lv_sys_type.
WHEN cl_abap_typedescr=>typekind_char.
ro_type = cl_abap_elemdescr=>get_c( p_length = is_field_desc-length ).
WHEN cl_abap_typedescr=>typekind_date.
ro_type = cl_abap_elemdescr=>get_d( ).
WHEN cl_abap_typedescr=>typekind_int.
ro_type = cl_abap_elemdescr=>get_i( ).
WHEN cl_abap_typedescr=>typekind_float.
ro_type = cl_abap_elemdescr=>get_f( ).
WHEN cl_abap_typedescr=>typekind_num.