-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZSK_ALV_3TAB.ABAP
320 lines (283 loc) · 10.8 KB
/
ZSK_ALV_3TAB.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
*&---------------------------------------------------------------------*
*& Report ZSK_ALV_3TAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
***Create a grid alv report using 3 tables
REPORT ZSK_ALV_3TAB.
***BEGIN DATA DECLARATIONS
***TYPE-POOLS USED
TYPE-POOLS: SLIS.
***TABLE DECLARATIONS
TABLES: MARA, " GENERAL MATERIAL DATA
VBRK, " Billing Document: Header Data
VBRP. " Billing Document: Item Data
***STRUCTURE DECLARATIONS
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR, " Material Number " Field common in vbrp and mara
MTART TYPE MARA-MTART, " Material Type
MBRSH TYPE MARA-MBRSH, " Industry sector
MATKL TYPE MARA-MATKL, " Material Group
MEINS TYPE MARA-MEINS, " Base Unit of Measure
END OF TY_MARA.
TYPES: BEGIN OF TY_VBRK,
FKART TYPE VBRK-FKART, " Billing Type
VBELN TYPE VBRK-VBELN, " Billing Document " Field common in vbrk and vbrp
VBTYP TYPE VBRK-VBTYP, " SD document category
VKORG TYPE VBRK-VKORG, " Sales Organization
VTWEG TYPE VBRK-VTWEG, " Distribution Channel
BELNR TYPE VBRK-BELNR, " Accounting Document Number
END OF TY_VBRK.
TYPES: BEGIN OF TY_VBRP,
VBELN TYPE VBRP-VBELN, " Billing Document " Field common in vbrk and vbrp
GSBER TYPE VBRP-GSBER, " Business Area
VOLUM TYPE VBRP-VOLUM, " Volume
MATNR TYPE VBRP-MATNR, " Material Number " Field common in vbrp and mara
END OF TY_VBRP.
TYPES: BEGIN OF TY_FINAL,
VBELN TYPE VBRK-VBELN, " Billing Document " <=====Key
FKART TYPE VBRK-FKART, " Billing Type
VBTYP TYPE VBRK-VBTYP, " SD document category
VKORG TYPE VBRK-VKORG, " Sales Organization
VTWEG TYPE VBRK-VTWEG, " Distribution Channel
BELNR TYPE VBRK-BELNR, " Accounting Document Number
GSBER TYPE VBRP-GSBER, " Business Area
VOLUM TYPE VBRP-VOLUM, " Volume
MATNR TYPE VBRP-MATNR, " Material Number "<======Key
MTART TYPE MARA-MTART, " Material Type
MBRSH TYPE MARA-MBRSH, " Industry sector
MATKL TYPE MARA-MATKL, " Material Group
MEINS TYPE MARA-MEINS, " Base Unit of Measure
END OF TY_FINAL.
***CREATE INTERNAL TABLE DATA OBJECTS
DATA: IT_MARA TYPE TABLE OF TY_MARA,
WA_MARA LIKE LINE OF IT_MARA.
DATA: IT_VBRK TYPE TABLE OF TY_VBRK,
WA_VBRK LIKE LINE OF IT_VBRK.
DATA: IT_VBRP TYPE TABLE OF TY_VBRP,
WA_VBRP LIKE LINE OF IT_VBRP.
DATA: IT_FINAL TYPE TABLE OF TY_FINAL,
WA_FINAL LIKE LINE OF IT_FINAL.
DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FLDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR VBRK-VBELN.
PARAMETERS: P_FKART TYPE VBRK-FKART.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM PROCESS_DATA.
PERFORM DISPLAY_DATA.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT FKART " Get data from vbrk into it_vbrk based on user input
VBELN
VBTYP
VKORG
VTWEG
BELNR FROM VBRK INTO TABLE IT_VBRK WHERE VBELN IN S_VBELN AND FKART = P_FKART.
IF IT_VBRK IS NOT INITIAL.
SORT IT_VBRK ASCENDING BY VBELN. " The following select on the dependent table works faster because
" the search is lighter due to sorted data
SELECT VBELN " Get data from vbrp into it_vbrp based on data in vbrk(vbeln common field)
GSBER
VOLUM
MATNR FROM VBRP INTO TABLE IT_VBRP FOR ALL ENTRIES IN IT_VBRK WHERE VBELN = IT_VBRK-VBELN.
IF IT_VBRP IS NOT INITIAL.
SORT IT_VBRP ASCENDING BY MATNR.
SELECT MATNR " Get data from mara into it_mara based on data in vbrk(matnr common field)
MTART
MBRSH
MATKL
MEINS FROM MARA INTO TABLE IT_MARA FOR ALL ENTRIES IN IT_VBRP WHERE MATNR = IT_VBRP-MATNR.
ENDIF.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PROCESS_DATA .
LOOP AT IT_VBRK INTO WA_VBRK.
CLEAR WA_FINAL.
WA_FINAL-VBELN = WA_VBRK-VBELN.
WA_FINAL-FKART = WA_VBRK-FKART.
WA_FINAL-BELNR = WA_VBRK-BELNR.
WA_FINAL-VBTYP = WA_VBRK-VBTYP.
WA_FINAL-VKORG = WA_VBRK-VKORG.
WA_FINAL-VTWEG = WA_VBRK-VTWEG.
" Read one row into wa_vbrp from vbrp based on current value of vbeln in wa_final/vbrk
READ TABLE IT_VBRP INTO WA_VBRP WITH KEY VBELN = WA_FINAL-VBELN BINARY SEARCH.
"WA_FINAL-GSBER = WA_VBRP-GSBER.
WA_FINAL-VOLUM = WA_VBRP-VOLUM.
WA_FINAL-MATNR = WA_VBRP-MATNR.
" Read one row into wa_mara from mara based on current value of matnr in wa_final/vbrp
READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = WA_FINAL-MATNR BINARY SEARCH.
WA_FINAL-MTART = WA_MARA-MTART.
WA_FINAL-MBRSH = WA_MARA-MBRSH.
WA_FINAL-MATKL = WA_MARA-MATKL.
WA_FINAL-MEINS = WA_MARA-MEINS.
APPEND WA_FINAL TO IT_FINAL.
ENDLOOP.
ENDFORM. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
" SET LAYOUT
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
WA_LAYOUT-ZEBRA = 'X'.
"SET FIELD CATALOG PARAMETERS
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '1'.
WA_FLDCAT-FIELDNAME = 'VBELN'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'BILLING DOCUMENT'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '2'.
WA_FLDCAT-FIELDNAME = 'FKART'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'BILLING TYPE'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '3'.
WA_FLDCAT-FIELDNAME = 'VBTYP'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'SD DOCUMENT CATEGORY'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '4'.
WA_FLDCAT-FIELDNAME = 'VKORG'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'SALES ORGANIZATION'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '5'.
WA_FLDCAT-FIELDNAME = 'VTWEG'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'DISTRIBUTION CHANNEL'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '6'.
WA_FLDCAT-FIELDNAME = 'BELNR'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'ACCOUNTING DOCUMENT NUMBER'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '7'.
WA_FLDCAT-FIELDNAME = 'GSBER'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'BUSINESS AREA'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '8'.
WA_FLDCAT-FIELDNAME = 'VOLUM'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'VOLUME'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '9'.
WA_FLDCAT-FIELDNAME = 'MATNR'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'MATERIAL NUMBER'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '10'.
WA_FLDCAT-FIELDNAME = 'MTART'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'MATERIAL TYPE'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '11'.
WA_FLDCAT-FIELDNAME = 'MBRSH'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'INDUSTRY SECTOR'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '12'.
WA_FLDCAT-FIELDNAME = 'MATKL'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'MATERIAL GROUP'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '13'.
WA_FLDCAT-FIELDNAME = 'MEINS'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'BASE UNIT OF MEASURE'.
APPEND WA_FLDCAT TO IT_FLDCAT.
" CALL FUNCTION TO DISPLAY THE REPORT USING THE INFO IN FIELD CATALOG
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FLDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_DATA