Simple ALV Report – Details of Y or Z Objects

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
*&---------------------------------------------------------------------*
*& Report Z_OBJECT_TRACKER *
*& Author :Swarna.S.
*&---------------------------------------------------------------------*
*&
*& AS:
*& Simple ALV report -- Details of Y or Z objects
*& showing lists of all the users , date ,time and description for creation
*& or changes done on it
*&
*&---------------------------------------------------------------------*
REPORT z_object_tracker NO STANDARD PAGE HEADING.
 
*Type pools declaration for ALV.
TYPE-POOLS : slis.
 
*Structure declaration for TRDIR table
TYPES : BEGIN OF ty_trdir,
name(120), "Name of the the Y/Z program
cnam TYPE trdir-cnam, "Author
cdat TYPE trdir-cdat, "Created on
subc TYPE trdir-subc, "Program type
END OF ty_trdir.
 
*Structure declaration for the output in ALV fomrat
TYPES : BEGIN OF ty_output,
obj_name TYPE e071-obj_name, "Object Name(Y/Z)
trkorr TYPE e071-trkorr, "Transport Request
objtype(20) TYPE c, "object type
as4user TYPE e070-as4user, "User name
as4date TYPE e070-as4date, "date
as4time TYPE e070-as4time, "time
as4text TYPE e07t-as4text, "Short Text Describing R/3 Repository Objects
END OF ty_output.
 
*Internal table and work area declarations
*Declaration for TRDIR table
DATA : it_trdir TYPE STANDARD TABLE OF ty_trdir,
wa_trdir TYPE ty_trdir.
 
*Declaration for output table
DATA : it_output TYPE STANDARD TABLE OF ty_output,
wa_output TYPE ty_output.
 
*DATA Declarations for ALV grid
DATA: c_ccont TYPE REF TO cl_gui_custom_container,
c_alvgd TYPE REF TO cl_gui_alv_grid,
it_fcat TYPE lvc_t_fcat,
it_layout TYPE lvc_s_layo.
 
* For grid title
DATA : txt1 TYPE string.
DATA : txt2 TYPE string.
DATA : txt3 TYPE string.
DATA : txt4 TYPE string.
DATA : titletext TYPE string.
 
* Selection screen
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
PARAMETERS : p_object LIKE wa_trdir-name.
SELECTION-SCREEN END OF BLOCK blk1.
 
*initialization event
INITIALIZATION.
 
txt1 = 'Object tracker for'.
txt3 = 'Type'.
 
*Start of selection event
START-OF-SELECTION.
 
*Subroutine to get the user name/date/time
PERFORM get_object_details.
*Subroutine to print alv output
PERFORM alv_output.
 
*End of selection event
END-OF-SELECTION.
 
*&---------------------------------------------------------------------*
*& Form alv_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_output.
 
*Call the ALV screen with custom container
CALL SCREEN '0600'.
 
ENDFORM. " alv_output
 
*On this statement double click it takes you to the screen painter SE51.Enter the attributes
*Create a Custom container and name it C_GRID and OK code as OK_CODE.
*Save check and Activate the scren painter.
*NOw a normal screen witn number 600 is created which holds the ALV grid.
 
* PBO of the actual screen , Here we can give a title and customized menus
 
*&---------------------------------------------------------------------*
*& Module STATUS_0600 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0600 OUTPUT.
 
* SET TITLEBAR 'XXXX'.
*
* SET PF-STATUS 'XXXXXXX'.
 
ENDMODULE. " STATUS_0600 OUTPUT
 
* calling the PBO module SET_GRID.
*&---------------------------------------------------------------------*
*& Module SET_GRID OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE set_grid OUTPUT.
 
* Create object for custom container
CREATE OBJECT c_ccont
EXPORTING
container_name = 'C_GRID'.
 
* Create object for ALV grid
 
CREATE OBJECT c_alvgd
EXPORTING
i_parent = c_ccont.
 
* Set field for ALV
PERFORM alv_fieldcat.
 
* Set ALV attributes FOR LAYOUT
PERFORM alv_layout.
 
CHECK NOT c_alvgd IS INITIAL.
 
* Call ALV GRID
CALL METHOD c_alvgd->set_table_for_first_display
EXPORTING
is_layout = it_layout
CHANGING
it_outtab = it_output
it_fieldcatalog = it_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
 
ENDMODULE. " SET_GRID OUTPUT
 
* PAI module of the screen created. In case we use an interactive ALV or
*for additional functionalities we can create OK codes and based on the user command
*we can do the coding.
 
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0600 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0600 INPUT.
 
ENDMODULE. " USER_COMMAND_0600 INPUT
 
*&---------------------------------------------------------------------*
*& Form get_object_details
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* Subroutine to fetch the details of the object through the necessary
* selections in the database.
*
*----------------------------------------------------------------------*
FORM get_object_details.
 
*Select values from TRDIR
SELECT name cnam cdat subc FROM trdir INTO TABLE it_trdir
WHERE name EQ p_object AND
( name LIKE 'Z%' OR name LIKE 'Y%' ).
 
*Select values from CTS tables
IF sy-subrc IS INITIAL.
 
SELECT a~obj_name a~trkorr b~as4user b~as4date b~as4time c~as4text
INTO CORRESPONDING FIELDS OF TABLE it_output
FROM e071 AS a INNER JOIN e070 AS b
ON a~trkorr = b~trkorr
INNER JOIN e07t AS c
ON a~trkorr = c~trkorr
FOR ALL ENTRIES IN it_trdir
WHERE a~obj_name = it_trdir-name
AND c~langu = sy-langu AND
a~lockflag <> ' '.
 
ENDIF.
 
* Appending the selected values to our output internal table
LOOP AT it_output INTO wa_output.
 
AT NEW obj_name.
READ TABLE it_trdir INTO wa_trdir WITH KEY name = wa_output-obj_name.
 
CASE wa_trdir-subc.
WHEN '1'.
wa_output-objtype = 'Executable Program'.
WHEN 'I'.
wa_output-objtype = 'Include Program'.
WHEN 'M'.
wa_output-objtype = 'Module Pool'.
WHEN 'F'.
wa_output-objtype = 'Function group'.
WHEN 'S'.
wa_output-objtype = 'Subroutine Pool'.
WHEN 'J'.
wa_output-objtype = 'Interface'.
WHEN 'K'.
wa_output-objtype = 'Class'.
ENDCASE.
 
MODIFY it_output FROM wa_output
TRANSPORTING objtype
WHERE obj_name EQ wa_output-obj_name.
 
CLEAR : wa_output , wa_trdir.
ENDAT.
ENDLOOP.
 
SORT it_output BY obj_name as4date as4time.
 
*FOR grid TITLE
TXT4 = wa_output-objTYPE.
txt2 = wa_output-obj_name.
CONCATENATE txt1 txt2 TXT3 TXT4 INTO titletext SEPARATED BY space.
 
ENDFORM. "get_object_details
 
*&--------------------------------------------------------------------*
*& Form alv_fieldcat
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM alv_fieldcat.
 
DATA lv_fldcat TYPE lvc_s_fcat.
 
CLEAR lv_fldcat.
 
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '1'.
lv_fldcat-fieldname = 'AS4DATE'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = '20'.
lv_fldcat-scrtext_m = 'Date'.
APPEND lv_fldcat TO it_fcat.
 
CLEAR lv_fldcat.
 
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '2'.
lv_fldcat-fieldname = 'AS4TIME'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = '20'.
lv_fldcat-scrtext_m = 'Time'.
APPEND lv_fldcat TO it_fcat.
 
CLEAR lv_fldcat.
 
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '3'.
lv_fldcat-fieldname = 'AS4USER'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = '20'.
lv_fldcat-scrtext_m = 'Developer'.
APPEND lv_fldcat TO it_fcat.
 
CLEAR lv_fldcat.
 
lv_fldcat-row_pos = '1'.
lv_fldcat-col_pos = '4'.
lv_fldcat-fieldname = 'AS4TEXT'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = '20'.
lv_fldcat-scrtext_m = 'Object Desc'.
APPEND lv_fldcat TO it_fcat.
 
CLEAR lv_fldcat.
 
ENDFORM. "ALV_FIELDCAT
 
*&--------------------------------------------------------------------*
*& Form alv_layout
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM alv_layout.
 
it_layout-cwidth_opt = 'X'.
it_layout-zebra = 'X'.
it_layout-grid_title = titletext.
 
ENDFORM. "ALV_LAYOUT

Create the screen 0600 for the above program and place a custom container on the same:

Create a Custom container and name it C_GRID and OK code as OK_CODE.

Name the custom container C_GRID and give ok code as OK_CODE.

Also in the Flow Logic enter a PBO Module as SET_GRID.

Activate and Execute the Code.

Selection screen for entering the Y/Z Object name.

Execute .

ALV output.