-
Notifications
You must be signed in to change notification settings - Fork 286
/
zcl_demo_abap_sql_group_by.clas.abap
152 lines (112 loc) · 4.12 KB
/
zcl_demo_abap_sql_group_by.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
150
151
152
"! <p class="shorttext"><strong>Grouping internal tables</strong><br/>ABAP cheat sheet example class</p>
"!
"! <p>The example class demonstrates syntax options when grouping internal tables.<br/>
"! Choose F9 in ADT to run the class.</p>
"!
"! <h2>Note</h2>
"! <p>Find information on <strong>getting started with the example class</strong> and the
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
CLASS zcl_demo_abap_sql_group_by DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES: if_oo_adt_classrun.
CLASS-METHODS: class_constructor.
protected section.
PRIVATE SECTION.
CLASS-DATA:
wa TYPE zdemo_abap_flsch,
member TYPE zdemo_abap_flsch,
members TYPE STANDARD TABLE OF zdemo_abap_flsch WITH EMPTY KEY.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION.
METHOD class_constructor.
"Fill demo database tables.
zcl_demo_abap_aux=>fill_dbtabs( ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
out->write( |ABAP Cheat Sheet Example: Grouping Internal Tables\n\n| ).
SELECT *
FROM zdemo_abap_flsch
INTO TABLE @DATA(fli_tab).
out->write( |1) Representative Binding\n| ).
out->write( |1a) Grouping by one column\n| ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid.
out->write( wa-carrid ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `1b) Members of one column groups` ) ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid.
CLEAR members.
LOOP AT GROUP wa INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `1c) Grouping by two columns` ) ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
out->write( |{ wa-carrid } { wa-airpfrom }| ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `1d) Members of two column groups` ) ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
CLEAR members.
LOOP AT GROUP wa INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `2) Group Key Binding` ) ).
out->write( |2a) Grouping by one column\n| ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid
INTO DATA(key).
out->write( key ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `2b) Members of one column groups` ) ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid
INTO key.
CLEAR members.
LOOP AT GROUP key INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `2c) Grouping by two columns` ) ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
INTO DATA(keys).
out->write( keys ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `2d) Members of two column groups` ) ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
INTO keys.
CLEAR members.
LOOP AT GROUP keys INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `2e) Two column groups without members` ) ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom
index = GROUP INDEX size = GROUP SIZE )
WITHOUT MEMBERS
INTO DATA(keysplus).
out->write( keysplus ).
out->write( |\n| ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.