-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZSK_ALV.ABAP
282 lines (254 loc) · 9.83 KB
/
ZSK_ALV.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
*&---------------------------------------------------------------------*
*& Report ZSK_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSK_ALV.
***BEGIN DATA DECLARATIONS
***TYPE POOLS USED
TYPE-POOLS: SLIS. " SLIS is a type group for ALV and especially used to build Field Catalogs,LAYOUT
" FIELD CATALOG WILL HANDLE PRESENTAION/DISPLAY FOR US INSTEAD OF WRITE STATEMENTS AND CAN BE REUSED
" SLIS contains definations for types, structures and tables/INTERNAL TABLES which we use in ALV.
***TABLE DECLARATIONS
TABLES: MARA,
MAKT.
***BEGIN STRUCTURE DECLARATIONS FOR INTERNAL TABLES
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
TYPES: BEGIN OF TY_MAKT,
MATNR TYPE MAKT-MATNR,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MAKT.
TYPES: BEGIN OF TY_FINAL,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_FINAL.
***BEGIN INTERNAL TABLE DATA OBJECT CREATION
DATA: IT_MARA TYPE TABLE OF TY_MARA,
WA_MARA LIKE LINE OF IT_MARA.
DATA: IT_MAKT TYPE TABLE OF TY_MAKT,
WA_MAKT LIKE LINE OF IT_MAKT.
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. " OR LIKE LINE OF IT_FLDCAT
***SLIS_T_FIELDCAT_ALV IS THE INTERNAL TABLE FOR FIELD THAT IS ALREADY DEFINED(AND OBJECT CREATED) IN SLIS
***TYPE POOL. IT IS CREATED USING THE STRUCTURE SLIS_FIELDCAT_ALV IN SLIS. WE CREATE OUR INTERNAL TABLE
***IT_FLDCAT FOR FIELDCATALOG FROM THE PREDEFINED INTERNAL TABLE SLIS_T_FIELDCAT_ALV AND WE CREATE THE
***WORK AREA FOR OUR INTERNAL TABLE IT_FIELDCAT FROM THE STRCUTURE SLIS_FIELDCAT_ALV WHICH IS USED TO CREATE
***THE PREDEFINED INTERNAL TABLE SLIS_T_FIELDCAT_ALV.
DATA: IT_LAYOUT TYPE TABLE OF SLIS_LAYOUT_ALV,
WA_LAYOUT LIKE LINE OF IT_LAYOUT. " OR DIRECTLY WA_LAYOUT TYPE SLIS_LAYOUT_ALV
***SLIS_LAYOUT_ALV IS PRE-DEFINED STRUCTURE IN SLIS. USED TO CUSTOMISE THE LOOK/FEEL AND LAYOUT OF REPORT.
***SELECTION SCREEN
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
PARAMETERS: P_MBRSH TYPE MARA-MBRSH.
SELECTION-SCREEN END OF BLOCK B1.
***BEGIN MAIN EXECUTION
START-OF-SELECTION.
***SUBROUTINE DECLARATIONS AND CALLS.
PERFORM GET_DATA. " FOR DEFINITION D-CLICK SUB-ROUTINE NAME HERE AND SELECT(LEFT-MOST) MAIN-PROG
PERFORM PROCESS_DATA.
PERFORM DISPLAY_DATA.
END-OF-SELECTION.
***BEGIN SUBROUTINE DEFINITIONS
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT MATNR
MTART
MBRSH
MATKL
MEINS FROM MARA INTO TABLE IT_MARA WHERE MATNR IN S_MATNR AND MBRSH = P_MBRSH.
IF IT_MARA IS NOT INITIAL.
SORT IT_MARA ASCENDING BY MATNR.
SELECT MATNR
MAKTX FROM MAKT INTO TABLE IT_MAKT FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PROCESS_DATA .
LOOP AT IT_MARA INTO WA_MARA.
CLEAR WA_FINAL.
WA_FINAL-MATNR = WA_MARA-MATNR.
WA_FINAL-MTART = WA_MARA-MTART.
WA_FINAL-MBRSH = WA_MARA-MBRSH.
WA_FINAL-MATKL = WA_MARA-MATKL.
WA_FINAL-MEINS = WA_MARA-MEINS.
READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_FINAL-MATNR BINARY SEARCH.
WA_FINAL-MAKTX = WA_MAKT-MAKTX.
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 = '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 = '2'.
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 = '3'.
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 = '4'.
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 = '5'.
WA_FLDCAT-FIELDNAME = 'MEINS'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'BASE UNIT OF MEASURE'.
APPEND WA_FLDCAT TO IT_FLDCAT.
CLEAR WA_FLDCAT.
WA_FLDCAT-COL_POS = '6'.
WA_FLDCAT-FIELDNAME = 'MAKTX'.
WA_FLDCAT-TABNAME = 'IT-FINAL'.
WA_FLDCAT-SELTEXT_L = 'MATERIAL DESCRIPTION'.
APPEND WA_FLDCAT TO IT_FLDCAT.
" CALL FUNCTION TO DISPLAY THE REPORT USING THE INFO IN FIELD CATALOG
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' " GRID ALV
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID "CURRENT REPORT/CALLING PROGRAM
* 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 " LAYOUT TO USE
IT_FIELDCAT = IT_FLDCAT " FIELD CATALOG TO USE
* 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 " CONTENT TABLE TO USE
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.
*CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' " LIST ALV
* 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_STRUCTURE_NAME =
* IS_LAYOUT = WA_FLDCAT
* 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
** IR_SALV_LIST_ADAPTER =
** IT_EXCEPT_QINFO =
** I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
** 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