-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzcl_itab_vslice.clas.abap
149 lines (136 loc) · 4.56 KB
/
zcl_itab_vslice.clas.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
class zcl_itab_vslice definition
public
final
create public .
public section.
class-methods get_col
importing it_tab type standard table
iv_col type string
exporting et_tab type standard table.
class-methods get_cols
importing it_tab type standard table
it_cols type string_table
exporting et_tab1 type standard table
et_tab2 type standard table
et_tab3 type standard table
et_tab4 type standard table
et_tab5 type standard table
et_tab6 type standard table
et_tab7 type standard table
et_tab8 type standard table
et_tab9 type standard table.
class-methods get_itab_components
importing it_tab type standard table
returning value(rt_components) type abap_component_tab.
class-methods get_col_unique_sort
importing it_tab type standard table
iv_col type string
exporting et_tab type standard table.
class-methods get_cols_unique_sort
importing it_tab type standard table
it_cols type string_table
exporting et_tab1 type standard table
et_tab2 type standard table
et_tab3 type standard table
et_tab4 type standard table
et_tab5 type standard table
et_tab6 type standard table
et_tab7 type standard table
et_tab8 type standard table
et_tab9 type standard table.
" Get RANGE from itab
" Get RANGES from itab
" Get COL from itab
" Get COLS from itab
" Get UNIQUE COL from itab
" Get UNIQUE COLS from itab
" Get COL SUM from itab
* name type string,
* type type ref to cl_abap_datadescr,
* as_include type abap_bool,
* suffix type string,
protected section.
private section.
endclass.
class zcl_itab_vslice implementation.
method get_itab_components.
data: lt_comp type abap_component_tab.
data(lo_tab_descr) = cast cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( p_data = it_tab ) ).
data(lo_struct_descr) = cast cl_abap_structdescr( lo_tab_descr->get_table_line_type( ) ).
rt_components = lo_struct_descr->get_components( ).
endmethod.
method get_col.
loop at it_tab assigning field-symbol(<ls_row>).
assign component iv_col of structure <ls_row> to field-symbol(<lv_in>).
check <lv_in> is assigned.
append initial line to et_tab assigning field-symbol(<ls_out>).
<ls_out> = <lv_in>.
unassign: <lv_in>, <ls_out>.
endloop.
endmethod.
method get_cols.
field-symbols: <ls_out> type any,
<lt_tab> type standard table.
loop at it_cols assigning field-symbol(<lv_col>).
case sy-tabix.
when 1.
assign et_tab1 to <lt_tab>.
when 2.
assign et_tab2 to <lt_tab>.
when 3.
assign et_tab3 to <lt_tab>.
when 4.
assign et_tab4 to <lt_tab>.
when 5.
assign et_tab5 to <lt_tab>.
when 6.
assign et_tab6 to <lt_tab>.
when 7.
assign et_tab7 to <lt_tab>.
when 8.
assign et_tab8 to <lt_tab>.
when 9.
assign et_tab9 to <lt_tab>.
endcase.
get_col( exporting it_tab = it_tab
iv_col = <lv_col>
importing et_tab = <lt_tab> ).
endloop.
endmethod.
method get_col_unique_sort.
get_col( exporting it_tab = it_tab
iv_col = iv_col
importing et_tab = et_tab ).
sort et_tab by (iv_col).
delete adjacent duplicates from et_tab comparing (iv_col).
endmethod.
method get_cols_unique_sort.
field-symbols: <ls_out> type any,
<lt_tab> type standard table.
loop at it_cols assigning field-symbol(<lv_col>).
case sy-tabix.
when 1.
assign et_tab1 to <lt_tab>.
when 2.
assign et_tab2 to <lt_tab>.
when 3.
assign et_tab3 to <lt_tab>.
when 4.
assign et_tab4 to <lt_tab>.
when 5.
assign et_tab5 to <lt_tab>.
when 6.
assign et_tab6 to <lt_tab>.
when 7.
assign et_tab7 to <lt_tab>.
when 8.
assign et_tab8 to <lt_tab>.
when 9.
assign et_tab9 to <lt_tab>.
endcase.
get_col_unique_sort( exporting it_tab = it_tab
iv_col = <lv_col>
importing et_tab = <lt_tab> ).
endloop.
endmethod.
endclass.