forked from ysichov/Simple-Data-Explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDE_750.abap
2399 lines (2120 loc) · 86.6 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
*&---------------------------------------------------------------------*
*& Report YS_SDE - Simple Data Explorer
*&---------------------------------------------------------------------*
*& version: beta 0.5.200.160
*& GIT: https://github.com/ysichov/SDE/blob/master/SDE%20for%207.50%20abap - here may be most actual version
*& Multi-windows program for viewing tables and 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/
*&---------------------------------------------------------------------*
REPORT ys_sde.
CLASS lcl_data_receiver DEFINITION DEFERRED.
CLASS lcl_data_transmitter DEFINITION DEFERRED.
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 aqadh_range_value,
high TYPE aqadh_range_value,
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,
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 aqadh_range_value,
high TYPE aqadh_range_value,
more_icon TYPE aqadh_type_of_icon,
range TYPE aqadh_t_ranges,
END OF t_sel_row.
DATA: gt_sel TYPE TABLE OF selection_display_s.
FIELD-SYMBOLS: <g_str> TYPE any.
PARAMETERS: gv_tname TYPE tabname VISIBLE LENGTH 15 MATCHCODE OBJECT dd_bastab_for_view.
"Begin of INCLUDE YS_SDE_CLASSES.
CLASS lcl_plugins DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF t_field_links,
tab TYPE tablename,
field TYPE fieldname,
rtab TYPE tablename,
rfield TYPE fieldname,
const TYPE aqadh_range_value,
END OF t_field_links,
BEGIN OF t_el_links,
element TYPE tablename,
rtab TYPE tablename,
rfield TYPE fieldname,
tcode TYPE tcode,
END OF t_el_links.
CLASS-DATA: mt_field_links TYPE TABLE OF t_field_links,
mt_el_links TYPE TABLE OF t_el_links.
CLASS-METHODS: init.
ENDCLASS.
CLASS lcl_plugins IMPLEMENTATION.
METHOD init.
"data elements links
mt_el_links = VALUE #(
( element = 'PERSNO' tcode = 'PA20' )
( element = 'HROBJID' tcode = 'PP01' )
( element = 'HROBJID' rtab = 'HRP1000' rfield = 'OTYPE' )
( element = 'LGART' rtab = 'T512W' rfield = 'LGART' )
).
"field to field links
mt_field_links = VALUE #(
( tab = 'PA0001' field = 'PLANS' rtab = 'HRP1000' rfield = 'OTYPE' const = 'S' )
( tab = 'PA0001' field = 'PLANS' rtab = 'HRP1000' rfield = 'OBJID' )
( tab = 'PA0001' field = 'ORGEH' rtab = 'HRP1000' rfield = 'OTYPE' const = 'O' )
( tab = 'PA0001' field = 'ORGEH' rtab = 'HRP1000' rfield = 'OBJID' )
( tab = 'PA0001' field = 'STELL' rtab = 'HRP1000' rfield = 'OBJID' const = 'C' )
( tab = 'PA0001' field = 'STELL' rtab = 'HRP1000' rfield = 'OBJID' )
( tab = 'HRP1001' field = 'SCLAS' rfield = 'OTYPE' )
( tab = 'HRP1001' field = 'SOBID' rfield = 'OBJID' )
( tab = 'HRP1002' field = 'TABNR' rtab = 'HRT1002' rfield = 'TABNR' )
( tab = 'PA2006' field = 'QUONR' rtab = 'PTQUODED' rfield = 'QUONR' )
( tab = 'PTQUODED' field = 'QUONR' rtab = 'PA2006' rfield = 'QUONR' )
( tab = 'PTQUODED' field = 'DOCNR' rtab = 'PA2001' rfield = 'DOCNR' )
).
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_table_viewer DEFINITION DEFERRED.
CLASS lcl_box_handler DEFINITION DEFERRED.
CLASS lcl_sel_opt DEFINITION DEFERRED.
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 LIKE gv_tname 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>.
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.
"update_texts( ).
ENDMETHOD.
METHOD exist_table.
SELECT COUNT( * ) FROM dd02l
WHERE tabname = i_tab
AND ( tabclass = 'TRANSP' OR tabclass = 'CLUSTER' ).
e_subrc = sy-dbcnt.
ENDMETHOD.
ENDCLASS.
CLASS lcl_rtti DEFINITION.
PUBLIC SECTION.
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.
ENDCLASS.
CLASS lcl_rtti IMPLEMENTATION.
METHOD create_struc_handle.
DATA: lo_texttab TYPE REF TO cl_abap_structdescr,
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.
lo_texttab ?= 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.
"Read table lo_texttab->components with key
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.
READ TABLE lt_field_info INDEX 1 INTO DATA(l_field).
IF l_field-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.
APPEND ls_comp TO e_t_comp.
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.
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', "white 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,
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_field_info IMPORTING i_tab TYPE tabname.
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 get_field_info.
DATA: lv_clause TYPE string,
lr_struc TYPE REF TO data,
lr_table_descr TYPE REF TO cl_abap_structdescr,
it_tabdescr TYPE abap_compdescr_tab,
lt_field_info TYPE TABLE OF dfies,
l_fname TYPE fieldname,
l_tname TYPE tabname,
l_replace TYPE string,
l_texttab TYPE tabname,
lo_str TYPE REF TO cl_abap_structdescr.
lcl_rtti=>create_struc_handle( EXPORTING i_tname = i_tab
IMPORTING e_handle = lo_str ).
CREATE DATA lr_struc TYPE HANDLE lo_str.
lr_table_descr ?= cl_abap_typedescr=>describe_by_data_ref( lr_struc ).
it_tabdescr[] = lr_table_descr->components[].
LOOP AT it_tabdescr INTO DATA(ls) WHERE name NE 'MANDT'.
READ TABLE lcl_alv_common=>mt_tabfields INTO DATA(ls_tf) WITH KEY tabname = i_tab fieldname = ls-name.
IF sy-subrc NE 0.
l_tname = i_tab.
l_fname = ls-name.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = l_tname
fieldname = l_fname
langu = sy-langu
TABLES
dfies_tab = lt_field_info
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
READ TABLE lt_field_info INDEX 1 INTO DATA(l_info).
CHECK sy-subrc = 0.
CLEAR ls_tf.
MOVE-CORRESPONDING l_info TO ls_tf.
"check empty field
DATA: dref TYPE REF TO data,
l_x TYPE xstring.
FIELD-SYMBOLS <field> TYPE any.
IF ls_tf-rollname IS NOT INITIAL.
CREATE DATA dref TYPE (ls_tf-rollname).
ASSIGN dref->* TO <field>.
lv_clause = |{ ls_tf-fieldname } NE ''|.
SELECT SINGLE (ls_tf-fieldname) INTO @<field>
FROM (i_tab)
WHERE (lv_clause).
IF sy-subrc NE 0.
ls_tf-empty = 'X'.
ENDIF.
ELSEIF ls_tf-datatype = 'RAWSTRING'.
lv_clause = |{ ls_tf-fieldname } NE ''|.
SELECT SINGLE (ls_tf-fieldname) INTO @l_x
FROM (i_tab)
WHERE (lv_clause).
IF sy-subrc NE 0.
ls_tf-empty = 'X'.
ENDIF.
ENDIF.
INSERT ls_tf INTO TABLE lcl_alv_common=>mt_tabfields.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD translate_field.
DATA: lv_lang LIKE sy-langu,
lt_field_info TYPE TABLE OF dfies.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = c_fld-tabname "c_fld-ref_table
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.
ENDCLASS.
CLASS lcl_appl DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF sign_option_icon_s,
sign TYPE tvarv_sign,
option TYPE tvarv_opti,
icon_name(64) TYPE c,
icon TYPE aqadh_type_of_icon,
END OF sign_option_icon_s,
BEGIN OF t_obj,
alv_viewer TYPE REF TO lcl_table_viewer,
END OF t_obj,
BEGIN OF t_lang,
spras TYPE spras,
sptxt TYPE sptxt,
END OF t_lang .
CLASS-DATA: m_option_icons TYPE TABLE OF sign_option_icon_s,
mt_lang TYPE TABLE OF t_lang,
mt_obj TYPE TABLE OF t_obj, "main object table
m_ctrl_box_handler TYPE REF TO lcl_box_handler,
c_dragdropalv TYPE REF TO cl_dragdrop.
CLASS-METHODS:
init_icons_table,
init_lang,
suppress_run_button,
exit.
ENDCLASS.
CLASS lcl_data_transmitter DEFINITION.
PUBLIC SECTION.
EVENTS: data_changed EXPORTING VALUE(e_row) TYPE t_sel_row,
col_changed EXPORTING VALUE(e_column) TYPE lvc_fname.
METHODS: emit IMPORTING e_row TYPE t_sel_row,
emit_col IMPORTING e_column TYPE lvc_fname.
ENDCLASS.
CLASS lcl_data_transmitter IMPLEMENTATION.
METHOD emit.
RAISE EVENT data_changed EXPORTING e_row = e_row.
ENDMETHOD.
METHOD emit_col.
RAISE EVENT col_changed EXPORTING e_column = e_column.
ENDMETHOD.
ENDCLASS.
CLASS lcl_data_receiver DEFINITION.
PUBLIC SECTION.
DATA: mo_transmitter TYPE REF TO lcl_data_transmitter,
lo_tab_from TYPE REF TO lcl_table_viewer,
lo_sel_to TYPE REF TO lcl_sel_opt,
m_from_field TYPE lvc_fname,
m_to_field TYPE lvc_fname.
METHODS: constructor
IMPORTING io_transmitter TYPE REF TO lcl_data_transmitter OPTIONAL
io_tab_from TYPE REF TO lcl_table_viewer OPTIONAL
io_sel_to TYPE REF TO lcl_sel_opt OPTIONAL
i_from_field TYPE lvc_fname OPTIONAL
i_to_field TYPE lvc_fname OPTIONAL,
shut_down,
update FOR EVENT data_changed OF lcl_data_transmitter IMPORTING e_row,
update_col FOR EVENT col_changed OF lcl_data_transmitter IMPORTING e_column,
on_grid_button_click
FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING
es_col_id
es_row_no.
ENDCLASS.
CLASS lcl_sel_opt DEFINITION.
PUBLIC SECTION.
DATA: mo_viewer TYPE REF TO lcl_table_viewer,
mo_sel_alv TYPE REF TO cl_gui_alv_grid,
mt_fcat TYPE lvc_t_fcat,
mt_sel_tab TYPE TABLE OF selection_display_s,
ms_layout TYPE lvc_s_layo.
EVENTS: selection_done.
METHODS:
constructor IMPORTING io_viewer TYPE REF TO lcl_table_viewer io_container TYPE REF TO cl_gui_container,
raise_selection_done,
update_sel_tab,
set_value IMPORTING i_field TYPE any i_low TYPE any OPTIONAL i_high TYPE any OPTIONAL i_clear TYPE xfeld DEFAULT 'X' ,
update_sel_row CHANGING c_sel_row TYPE selection_display_s.
PRIVATE SECTION.
METHODS:
init_fcat IMPORTING i_dd_handle TYPE i,
handle_sel_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object,
on_f4 FOR EVENT onf4 OF cl_gui_alv_grid IMPORTING e_fieldname es_row_no er_event_data,
on_grid_button_click FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING
es_col_id
es_row_no,
on_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed,
on_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid IMPORTING e_modified,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm,
handle_doubleclick FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_column es_row_no,
handle_context_menu_request FOR EVENT context_menu_request OF cl_gui_alv_grid IMPORTING e_object.
ENDCLASS.
CLASS lcl_table_viewer DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF t_column_emitter,
column TYPE lvc_fname,
emitter TYPE REF TO lcl_data_transmitter,
END OF t_column_emitter.
DATA: m_lang TYPE ddlanguage,
m_tabname TYPE tabname,
m_texttabname TYPE tabname,
m_count TYPE i,
mo_alv TYPE REF TO cl_gui_alv_grid,
mo_sel TYPE REF TO lcl_sel_opt,
mo_box TYPE REF TO cl_gui_dialogbox_container,
mr_table TYPE REF TO data,
mr_text_table TYPE REF TO data,
mo_splitter TYPE REF TO cl_gui_splitter_container,
mo_sel_parent TYPE REF TO cl_gui_container,
mo_alv_parent TYPE REF TO cl_gui_container,
mt_alv_catalog TYPE lvc_t_fcat,
mt_text_components TYPE abap_component_tab,
"m_check_domain TYPE fieldname,
mo_column_emitters TYPE TABLE OF t_column_emitter,
mo_sel_width TYPE i,
m_visible,
m_std_tbar TYPE x,
m_show_empty.
METHODS:
constructor IMPORTING i_tname TYPE any,
get_where RETURNING VALUE(c_where) TYPE string,
refresh_table FOR EVENT selection_done OF lcl_sel_opt.
PRIVATE SECTION.
METHODS:
create_popup,
create_alv,
create_sel_alv,
set_header,
read_text_table,
update_texts,
link IMPORTING i_str TYPE any
i_column TYPE any RETURNING VALUE(r_done) TYPE xfeld,
create_field_cat IMPORTING i_tname TYPE tabname RETURNING VALUE(et_catalog) TYPE lvc_t_fcat,
on_f4 FOR EVENT onf4 OF cl_gui_alv_grid IMPORTING e_fieldname es_row_no er_event_data,
on_menu_request FOR EVENT context_menu_request OF cl_gui_alv_grid IMPORTING e_object,
handle_tab_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object,
handle_menu_button FOR EVENT menu_button OF cl_gui_alv_grid IMPORTING e_object e_ucomm,
before_user_command FOR EVENT before_user_command OF cl_gui_alv_grid IMPORTING e_ucomm,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm,
handle_doubleclick FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_column es_row_no,
jump_pa20,
jump_pp01.
ENDCLASS.
CLASS lcl_data_receiver IMPLEMENTATION.
METHOD constructor.
lo_sel_to = io_sel_to.
m_from_field = i_from_field.
m_to_field = i_to_field.
lo_tab_from = io_tab_from.
mo_transmitter = io_transmitter.
IF mo_transmitter IS NOT INITIAL.
IF lo_tab_from IS INITIAL.
SET HANDLER me->update FOR io_transmitter.
ELSE.
SET HANDLER me->update_col FOR io_transmitter.
ENDIF.
ELSE.
SET HANDLER me->update FOR ALL INSTANCES.
ENDIF.
ENDMETHOD.
METHOD shut_down.
IF mo_transmitter IS NOT INITIAL.
SET HANDLER me->update FOR mo_transmitter ACTIVATION space.
ELSE.
SET HANDLER me->update FOR ALL INSTANCES ACTIVATION space.
ENDIF.
CLEAR lo_sel_to.
ENDMETHOD.
METHOD on_grid_button_click.
FIELD-SYMBOLS: <f_tab> TYPE STANDARD TABLE,
<f_field> TYPE any.
CHECK m_from_field = es_col_id-fieldname.
ASSIGN lo_tab_from->mr_table->* TO <f_tab>.
READ TABLE <f_tab> INDEX es_row_no-row_id ASSIGNING FIELD-SYMBOL(<tab>).
ASSIGN COMPONENT es_col_id-fieldname OF STRUCTURE <tab> TO <f_field>.
CHECK lo_sel_to IS NOT INITIAL.
lo_sel_to->set_value( i_field = m_to_field i_low = <f_field> ).
lo_sel_to->raise_selection_done( ).
ENDMETHOD.
METHOD update.
DATA: l_updated.
READ TABLE lo_sel_to->mt_sel_tab ASSIGNING FIELD-SYMBOL(<to>) WITH KEY field_label = m_to_field.
IF <to>-range[] = e_row-range[].
l_updated = 'X'."so as not to have an infinite event loop
ENDIF.
MOVE-CORRESPONDING e_row TO <to>.
IF <to>-transmitter IS BOUND AND l_updated IS INITIAL.
<to>-transmitter->emit( EXPORTING e_row = e_row ).
ENDIF.
lo_sel_to->raise_selection_done( ).
ENDMETHOD.
METHOD update_col.
DATA: l_updated,
lt_old_range TYPE aqadh_t_ranges.
DATA: lt_sel_row TYPE t_sel_row.
FIELD-SYMBOLS: <tab> TYPE STANDARD TABLE,
<field> TYPE any.
CHECK lo_sel_to IS NOT INITIAL.
READ TABLE lo_sel_to->mt_sel_tab ASSIGNING FIELD-SYMBOL(<to>) WITH KEY field_label = m_to_field.
lt_old_range = <to>-range.
CLEAR: <to>-sign, <to>-opti, <to>-low, <to>-high, <to>-range.
ASSIGN lo_tab_from->mr_table->* TO <tab>.
LOOP AT <tab> ASSIGNING FIELD-SYMBOL(<row>).
ASSIGN COMPONENT e_column OF STRUCTURE <row> TO <field>.
READ TABLE <to>-range WITH KEY low = <field> TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
APPEND VALUE #( sign = 'I' opti = 'EQ' low = <field> ) TO <to>-range.
ENDIF.
ENDLOOP.
IF sy-subrc NE 0." empty column
APPEND VALUE #( sign = 'I' opti = 'EQ' low = '' ) TO <to>-range.
ENDIF.
LOOP AT <to>-range ASSIGNING FIELD-SYMBOL(<sel>).
<to>-low = <sel>-low.
lo_sel_to->update_sel_row( CHANGING c_sel_row = <to> ).
EXIT.
ENDLOOP.
MOVE-CORRESPONDING <to> TO lt_sel_row.
IF <to>-range = lt_old_range.
l_updated = 'X'."so as not to have an infinite event loop
ENDIF.
IF <to>-transmitter IS BOUND AND l_updated IS INITIAL.
<to>-transmitter->emit( EXPORTING e_row = lt_sel_row ).
lo_sel_to->raise_selection_done( ).
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS lcl_box_handler DEFINITION."for memory clearing
PUBLIC SECTION.
METHODS: on_box_close FOR EVENT close OF cl_gui_dialogbox_container IMPORTING sender.
ENDCLASS.
CLASS lcl_box_handler IMPLEMENTATION.
METHOD on_box_close.
DATA: lv_tabix LIKE sy-tabix.
sender->free( ).
"Free Memory
LOOP AT lcl_appl=>mt_obj ASSIGNING FIELD-SYMBOL(<obj>).
IF <obj>-alv_viewer->mo_box = sender.
lv_tabix = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
IF sy-subrc = 0.
FREE <obj>-alv_viewer->mr_table.
FREE <obj>-alv_viewer->mo_alv.
"shutdown receivers.
IF <obj>-alv_viewer->mo_sel IS NOT INITIAL.
LOOP AT <obj>-alv_viewer->mo_sel->mt_sel_tab INTO DATA(l_sel).
IF l_sel-receiver IS BOUND.
l_sel-receiver->shut_down( ).
ENDIF.
ENDLOOP.
ENDIF.
FREE <obj>-alv_viewer.
DELETE lcl_appl=>mt_obj INDEX lv_tabix.
ENDIF.
ENDMETHOD. "ON_BOX_CLOSE
ENDCLASS. "lcl_box_handler
CLASS lcl_table_viewer IMPLEMENTATION.
METHOD constructor.
m_lang = sy-langu.
mo_sel_width = 0.
m_tabname = i_tname.
create_popup( ).
lcl_ddic=>get_text_table( EXPORTING i_tname = m_tabname IMPORTING e_tab = m_texttabname ).
IF m_texttabname IS NOT INITIAL.
lcl_alv_common=>get_field_info( m_texttabname ).
ENDIF.
lcl_alv_common=>get_field_info( m_tabname ).
lcl_rtti=>create_table_by_name( EXPORTING i_tname = m_tabname CHANGING c_table = mr_table ).
create_alv( ).
create_sel_alv( ).
mo_alv->set_focus( mo_alv ).
ENDMETHOD.
METHOD create_popup.
DATA: l_top TYPE i,
l_left TYPE i.
DATA(l_lines) = lines( lcl_appl=>mt_obj ) - 1.
l_top = 20 + 30 * ( l_lines DIV 5 ) + ( l_lines MOD 5 ) * 50.
l_left = 420 + 300 * ( l_lines DIV 5 ) + ( l_lines MOD 5 ) * 50.
CREATE OBJECT mo_box
EXPORTING
width = '800'
height = '150'
top = l_top
left = l_left
caption = m_tabname
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.
CREATE OBJECT mo_splitter
EXPORTING
parent = mo_box
rows = 1
columns = 2
EXCEPTIONS
OTHERS = 1.
mo_splitter->set_column_mode( mode = mo_splitter->mode_absolute ).
mo_splitter->set_column_width( id = 1 width = mo_sel_width ).
CALL METHOD:
mo_splitter->get_container( EXPORTING
row = 1
column = 1
RECEIVING
container = mo_sel_parent ),
mo_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = mo_alv_parent.
IF lcl_appl=>m_ctrl_box_handler IS INITIAL.
lcl_appl=>m_ctrl_box_handler = NEW #( ).
ENDIF.
SET HANDLER lcl_appl=>m_ctrl_box_handler->on_box_close FOR mo_box.
ENDMETHOD.
METHOD create_alv.
DATA: ls_layout TYPE lvc_s_layo,
effect TYPE i,
lt_f4 TYPE lvc_t_f4.
FIELD-SYMBOLS: <f_tab> TYPE ANY TABLE.
mo_alv = NEW #( i_parent = mo_alv_parent ).
mt_alv_catalog = create_field_cat( m_tabname ).
ASSIGN mr_table->* TO <f_tab>.
read_text_table( ).
lcl_sql=>read_any_table( EXPORTING i_tabname = m_tabname i_where = get_where( ) i_row_count = 100
CHANGING cr_tab = mr_table c_count = m_count ).
update_texts( ).
set_header( ).
ls_layout-col_opt = 'X'.
ls_layout-cwidth_opt = 'X'.
ls_layout-sel_mode = 'D'.
CREATE OBJECT lcl_appl=>c_dragdropalv.
effect = cl_dragdrop=>move + cl_dragdrop=>copy.
CALL METHOD lcl_appl=>c_dragdropalv->add
EXPORTING
flavor = 'Line'
dragsrc = 'X'
droptarget = 'X'
effect = effect.
CALL METHOD lcl_appl=>c_dragdropalv->get_handle IMPORTING handle = DATA(handle_alv).
ls_layout-s_dragdrop-grid_ddid = handle_alv.
SET HANDLER before_user_command
handle_user_command
handle_menu_button
handle_tab_toolbar
handle_doubleclick
lcl_dragdrop=>drag
on_menu_request
on_f4 FOR mo_alv.
CALL METHOD mo_alv->set_table_for_first_display
EXPORTING
i_save = 'X'
i_default = 'X'
is_layout = ls_layout
CHANGING
it_fieldcatalog = mt_alv_catalog
it_outtab = <f_tab>.
mo_alv->get_frontend_fieldcatalog( IMPORTING et_fieldcatalog = mt_alv_catalog ).
LOOP AT mt_alv_catalog ASSIGNING FIELD-SYMBOL(<catalog>).
CLEAR <catalog>-key.
DATA(ls_f4) = VALUE lvc_s_f4( register = 'X' chngeafter = 'X' fieldname = <catalog>-fieldname ).
INSERT ls_f4 INTO TABLE lt_f4.
ENDLOOP.
mo_alv->register_f4_for_fields( it_f4 = lt_f4 ).
mo_alv->set_frontend_fieldcatalog( EXPORTING it_fieldcatalog = mt_alv_catalog ).
LOOP AT mt_alv_catalog ASSIGNING FIELD-SYMBOL(<cat>) WHERE scrtext_l IS INITIAL.
lcl_alv_common=>translate_field( CHANGING c_fld = <cat> ).
ENDLOOP.
mo_alv->set_frontend_fieldcatalog( EXPORTING it_fieldcatalog = mt_alv_catalog ).
me->handle_user_command( EXPORTING e_ucomm = 'HIDE' ).
mo_alv->set_toolbar_interactive( ).
ENDMETHOD.
METHOD create_sel_alv.
IF mo_sel IS INITIAL.
mo_sel = NEW #( io_viewer = me io_container = mo_sel_parent ).
SET HANDLER refresh_table FOR mo_sel.
ELSE.
mo_sel->update_sel_tab( ).
ENDIF.
ENDMETHOD.
METHOD read_text_table.
FIELD-SYMBOLS: <f_tab> TYPE ANY TABLE.
lcl_ddic=>get_text_table( EXPORTING i_tname = m_tabname IMPORTING e_tab = DATA(l_tab) ).
CHECK l_tab IS NOT INITIAL.
lcl_rtti=>create_table_by_name( EXPORTING i_tname = l_tab CHANGING c_table = mr_text_table ).
ASSIGN mr_text_table->* TO <f_tab>.
SELECT * FROM (l_tab) INTO TABLE <f_tab> ORDER BY PRIMARY KEY.
ENDMETHOD.
METHOD set_header.
DATA: lv_text TYPE as4text,
lv_header(80) TYPE c.
SELECT SINGLE ddtext INTO lv_text
FROM dd02t
WHERE tabname = m_tabname
AND ddlanguage = m_lang.
lv_header = |{ m_tabname } - { lv_text } ({ m_count })|.
mo_box->set_caption( lv_header ).
ENDMETHOD.
METHOD on_f4.
FIELD-SYMBOLS: <tab> TYPE STANDARD TABLE.
ASSIGN mr_table->* TO <tab>.
READ TABLE <tab> INDEX es_row_no-row_id ASSIGNING <g_str>.
CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
EXPORTING
tabname = m_tabname
fieldname = e_fieldname
callback_program = sy-repid
callback_form = 'CALLBACK_F4_TAB' "callback_method - doesn't work for local class
EXCEPTIONS
field_not_found = 1
no_help_for_field = 2
inconsistent_help = 3
no_values_found = 4
OTHERS = 5.
ENDMETHOD.
METHOD on_menu_request.
DATA: l_smenu TYPE REF TO cl_ctmenu.
mo_alv->get_current_cell( IMPORTING
es_row_id = DATA(ls_row)
es_col_id = DATA(ls_col) ).
e_object->add_separator( ).
CREATE OBJECT l_smenu.
SELECT SINGLE dbtab INTO @DATA(l_dbtab)
FROM t777d
WHERE dbtab = @m_tabname.
IF sy-subrc = 0.
CALL METHOD l_smenu->add_function
EXPORTING
fcode = 'DETAIL'
text = 'Просмотр объекта'.
* IF l_dbtab+0(2) = 'PA'.
* CALL METHOD l_smenu->add_function
* EXPORTING
* fcode = 'PY'
* text = 'PaYroll Clusters'.
* ENDIF.
ENDIF.
CALL METHOD e_object->add_submenu
EXPORTING
menu = l_smenu
text = 'Data Driven Jumps'.
ENDMETHOD.
METHOD handle_tab_toolbar.
IF m_visible IS INITIAL.
DATA(lt_toolbar) = VALUE ttb_button(
( function = 'SEL_ON' icon = icon_arrow_left quickinfo = 'Show Select-Options' butn_type = 0 )
( butn_type = 3 ) ).
ENDIF.
lt_toolbar = VALUE ttb_button( BASE lt_toolbar
( function = 'REFRESH' icon = icon_refresh quickinfo = 'Refresh' butn_type = 0 )
( function = 'LANGUAGE' icon = icon_foreign_trade quickinfo = 'Languages' butn_type = 2 )
( function = 'OPTIONS' icon = icon_list quickinfo = 'Empty columns options' butn_type = 2 )
( function = 'TABLES' icon = icon_net_graphic quickinfo = 'Table links' butn_type = 0 )
( function = 'TBAR' icon = COND #( WHEN m_std_tbar IS INITIAL THEN icon_column_right ELSE icon_column_left )
quickinfo = COND #( WHEN m_std_tbar IS INITIAL THEN 'Show standard ALV function' ELSE 'Hide standard ALV function') )
( butn_type = 3 ) ).
IF m_std_tbar IS INITIAL.
e_object->mt_toolbar = lt_toolbar.
ELSE.
e_object->mt_toolbar = lt_toolbar = VALUE ttb_button( BASE lt_toolbar ( LINES OF e_object->mt_toolbar ) ).
ENDIF.
ENDMETHOD.
METHOD create_field_cat.
DATA: lv_clause TYPE string,
lr_struc TYPE REF TO data,
lr_table_descr TYPE REF TO cl_abap_structdescr,
it_tabdescr TYPE abap_compdescr_tab,
lt_field_info TYPE TABLE OF dfies,
l_fname TYPE fieldname,
l_tname TYPE tabname,
l_replace TYPE string,
l_texttab TYPE tabname,
lo_str TYPE REF TO cl_abap_structdescr.
lcl_rtti=>create_struc_handle( EXPORTING i_tname = i_tname IMPORTING e_t_comp = mt_text_components e_handle = lo_str ).
CREATE DATA lr_struc TYPE HANDLE lo_str.
lr_table_descr ?= cl_abap_typedescr=>describe_by_data_ref( lr_struc ).
it_tabdescr[] = lr_table_descr->components[].
lcl_ddic=>get_text_table( EXPORTING i_tname = i_tname IMPORTING e_tab = l_texttab ).
l_replace = l_texttab && '_'.
LOOP AT it_tabdescr INTO DATA(ls) WHERE name NE 'MANDT'.
DATA(l_ind) = sy-tabix.
APPEND INITIAL LINE TO et_catalog ASSIGNING FIELD-SYMBOL(<catalog>).
<catalog>-col_pos = l_ind.
READ TABLE lcl_alv_common=>mt_tabfields INTO DATA(ls_tf) WITH KEY tabname = i_tname fieldname = ls-name.
IF sy-subrc NE 0.
l_tname = i_tname.
l_fname = ls-name.
IF l_texttab IS NOT INITIAL.
l_fname = ls-name.
REPLACE l_replace IN l_fname WITH ''.
IF sy-subrc = 0.
l_tname = l_texttab.
ENDIF.
ENDIF.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = l_tname
fieldname = l_fname
langu = sy-langu
TABLES
dfies_tab = lt_field_info
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
CONTINUE.
ENDIF.
CLEAR ls_tf.
MOVE-CORRESPONDING lt_field_info[ 1 ] TO ls_tf.
ls_tf-fieldname = ls-name.
INSERT ls_tf INTO TABLE lcl_alv_common=>mt_tabfields.
ENDIF.
<catalog>-style = lcl_alv_common=>c_white.
MOVE-CORRESPONDING ls_tf TO <catalog>.
<catalog>-no_zero = 'X'.