10/2/2018 Create a simple Editable ALV grid.
~ New To SAP
New To SAP
SAP resource site
HOME ABOUT PRIVACY POLICY
Create a simple Editable ALV grid. Recommended Books
ALV grid is normally used to display the report/program output. But there are cases where you need
Search This Site
edit functionality in ALV grid.
Go!
Having a editable column/ field is very simple in ALV grid. During field catalog population just set the
edi property of the column. Popular Posts
Control Break Statements in SAP ABAP
I.e, Handling Currencies having Zero Decimals in SAP
wa_fieldcat-edit = 'X'. ABAP
Creating a function module and using it [Tutorial]
Now , Not so easy task is to code the logic to save the data after edit operation.
VOFM Routines–A Short Guide
We have to use events for the same.
Enhancements in SAP ABAP [ Introduction ]
i_callback_user_command = gt_callback_subroutine
is used to activate a subroutine 'USER_COMMAND' which will be triggered on each user action on
Recent Posts
ALV (Mouse click , Button click etc).We need to code in this subroutine.
Create a simple Editable ALV grid.
SAVE button is having a function code '&DATA_SAVE'. So we need to check if sy-ucom = Change the decimal/time/date formats of the user
'&DATA_SAVE'.
Create PR from Sales Order line item automatically
Complete Sales Order / Delivery flow in SAP
Whenever any edit is done in ALV grid , the same is reflected back in the internal table used. So we
can use the latest contents of internal table to update/ do our operations. To get only those fields VOFM Routines–A Short Guide
which are modified , better to copy the internal table to some temp table and compare each row with
the new contents. Copyright
© 2012-2017 newtosap.aditech.info The contents of
SO, here is the program incorporating all things explained. this site are copyrighted and may not be reproduced
on other websites. All product names are
trademarks of their respective companies.
1 *&---------------------------------------------------------------------* newtosap.aditech.info is in no way affiliated with
2 *& Report ZAU_ALVGRIDTEST SAP AG.SAP and any other SAP trademarks are
3 *& registered trademarks of SAP AG in Germany and
4 *&---------------------------------------------------------------------* in several other countries. Every effort is made to
5 *&+ ensure content integrity. Use information on this site
*& at your own risk.
6
7 *&---------------------------------------------------------------------*
8 Total Pageviews
9 REPORT zau_alvgridtest.
738,732
10 TYPE-POOLS:icon. " Just include this
11 TYPES: BEGIN OF ty_matnr,
12 matnr TYPE mara-matnr,
13 ersda TYPE mara-ersda,
14 ernam TYPE mara-ernam,
15 mtart TYPE mara-mtart,
16 status TYPE char4, " Reserve a field for traffic lights
17 rowcolor(4) TYPE c, "row colour
18 END OF ty_matnr.
19
20 TYPE-POOLS : slis.
21 TABLES: mara.
22
23 DATA : wa_fieldcat TYPE slis_fieldcat_alv, "workspace
24 it_fieldcat TYPE slis_t_fieldcat_alv, " Table
http://newtosap.aditech.info/2013/04/create-simple-editable-alv-grid_86.html 1/6
10/2/2018 Create a simple Editable ALV grid. ~ New To SAP
25 it_mara TYPE STANDARD TABLE OF ty_matnr,
26 it_maracp TYPE STANDARD TABLE OF ty_matnr,
27 it_changes TYPE STANDARD TABLE OF ty_matnr,
28 wa_mara TYPE ty_matnr,
29 wa_maracp TYPE ty_matnr,
30 g_top_of_page TYPE slis_formname VALUE 'F_TOP_OF_PAGE', "for avl header.
31 it_layout TYPE slis_layout_alv,
32 gt_callback_subroutine TYPE slis_formname VALUE 'USER_COMMAND',
33 lv_run TYPE i VALUE '0'.
34
35
36 SELECT-OPTIONS : s_matnr FOR mara-matnr.
37
38 PARAMETERS: rd1 RADIOBUTTON GROUP rb DEFAULT 'X',
39 rd2 RADIOBUTTON GROUP rb .
40
41 START-OF-SELECTION.
42 IF s_matnr IS NOT INITIAL.
43 SELECT matnr ersda
44 ernam mtart
45 FROM mara
46 INTO TABLE it_mara
47 WHERE matnr IN s_matnr.
48
49 IF it_mara IS NOT INITIAL.
50 LOOP AT it_mara INTO wa_mara.
51
52 IF lv_run EQ 0.
53 wa_mara-rowcolor = 'C300'.
54 wa_mara-status = icon_red_light. "Update the traffic lights as you wish, j
55
56 MODIFY it_mara FROM wa_mara.
57 lv_run = 1.
58 ELSE.
59 wa_mara-rowcolor = 'C600'.
60 wa_mara-status = icon_green_light.
61 MODIFY it_mara FROM wa_mara .
62 lv_run = 0.
63 ENDIF.
64 ENDLOOP.
65 PERFORM f_build_catalog.
66 IF rd1 EQ 'X'.
67
68 * it_layout-info_fieldname = 'ROWCOLOR'.
69 PERFORM f_display_grid.
70 ELSE.
71 * it_layout-info_fieldname = 'ROWCOLOR'.
72 PERFORM f_display_list.
73 ENDIF.
74 ENDIF.
75 ENDIF.
76 *&---------------------------------------------------------------------*
77 *& Form f_build_catalog
78 *&---------------------------------------------------------------------*
79 * text
80 *----------------------------------------------------------------------*
81 FORM f_build_catalog.
82 wa_fieldcat-fieldname = 'MATNR'.
83 wa_fieldcat-seltext_m = 'Material Value'.
84 wa_fieldcat-col_pos = 1.
85 wa_fieldcat-key = 'X'.
86
87 wa_fieldcat-hotspot = 'X'.
88 APPEND wa_fieldcat TO it_fieldcat.
89 CLEAR wa_fieldcat.
90
http://newtosap.aditech.info/2013/04/create-simple-editable-alv-grid_86.html 2/6
10/2/2018 Create a simple Editable ALV grid. ~ New To SAP
91 wa_fieldcat-fieldname = 'ERSDA'.
92 wa_fieldcat-seltext_m = 'Created On'.
93 wa_fieldcat-edit = 'X'.
94 wa_fieldcat-col_pos = 2.
95 APPEND wa_fieldcat TO it_fieldcat.
96 CLEAR wa_fieldcat.
97
98 wa_fieldcat-fieldname = 'ERNAM'.
99 wa_fieldcat-seltext_m = 'Created by'.
100 wa_fieldcat-edit = 'X'.
101 wa_fieldcat-col_pos = 3.
102 APPEND wa_fieldcat TO it_fieldcat.
103 CLEAR wa_fieldcat.
104
105 wa_fieldcat-fieldname = 'MTART'.
106 wa_fieldcat-seltext_m = 'Material Type'.
107 wa_fieldcat-edit = 'X'.
108 wa_fieldcat-col_pos = 4.
109 APPEND wa_fieldcat TO it_fieldcat.
110 CLEAR wa_fieldcat.
111
112 wa_fieldcat-fieldname = 'STATUS'.
113 wa_fieldcat-seltext_m = 'Status'.
114 wa_fieldcat-icon = 'X'. " Display the field as ICON
115 wa_fieldcat-col_pos = 5.
116 APPEND wa_fieldcat TO it_fieldcat.
117 CLEAR wa_fieldcat.
118
119
120
121 ENDFORM. "f_build_catalog
122
123 *&---------------------------------------------------------------------*
124 *& Form f_display_grid
125 *&---------------------------------------------------------------------*
126 * text
127 *----------------------------------------------------------------------*
128 FORM f_display_grid.
129 it_maracp[] = it_mara[].
130 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
131 EXPORTING
132 * I_INTERFACE_CHECK = ' '
133 * I_BYPASSING_BUFFER = ' '
134 * I_BUFFER_ACTIVE = ' '
135 i_callback_program = sy-repid
136 * I_CALLBACK_PF_STATUS_SET = ' '
137 i_callback_user_command = gt_callback_subroutine
138 i_callback_top_of_page = g_top_of_page
139 * I_CALLBACK_HTML_TOP_OF_PAGE = ' '
140 * I_CALLBACK_HTML_END_OF_LIST = ' '
141 * I_STRUCTURE_NAME =
142 * I_BACKGROUND_ID = ' '
143 * I_GRID_TITLE =
144 * I_GRID_SETTINGS =
145 is_layout = it_layout
146 it_fieldcat = it_fieldcat
147 * IT_EXCLUDING =
148 * IT_SPECIAL_GROUPS =
149 * IT_SORT =
150 * IT_FILTER =
151 * IS_SEL_HIDE =
152 * I_DEFAULT = 'X'
153 * I_SAVE = ' '
154 * IS_VARIANT =
155 * IT_EVENTS =
156 * IT_EVENT_EXIT =
http://newtosap.aditech.info/2013/04/create-simple-editable-alv-grid_86.html 3/6
10/2/2018 Create a simple Editable ALV grid. ~ New To SAP
157 * IS_PRINT =
158 * IS_REPREP_ID =
159 * I_SCREEN_START_COLUMN = 0
160 * I_SCREEN_STARlv_line = 0
161 * I_SCREEN_END_COLUMN = 0
162 * I_SCREEN_END_LINE = 0
163 * I_HTML_HEIGHT_TOP = 0
164 * I_HTML_HEIGHT_END = 0
165 * IT_ALV_GRAPHICS =
166 * IT_HYPERLINK =
167 * IT_ADD_FIELDCAT =
168 * IT_EXCEPT_QINFO =
169 * IR_SALV_FULLSCREEN_ADAPTER =
170 * IMPORTING
171 * E_EXIT_CAUSED_BY_CALLER =
172 * ES_EXIT_CAUSED_BY_USER =
173 TABLES
174 t_outtab = it_mara
175 EXCEPTIONS
176 program_error = 1
177 OTHERS = 2
178 .
179 IF sy-subrc <> 0.
180 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
181 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
182 ENDIF.
183 ENDFORM. "f_display_grid
184 *&---------------------------------------------------------------------*
185 *& Form user_command
186 *&---------------------------------------------------------------------*
187 * text
188 *----------------------------------------------------------------------*
189 * -->P_UCOMM text
190 * -->P_SELFIELD text
191 *----------------------------------------------------------------------*
192 FORM user_command USING p_ucomm LIKE sy-ucomm
193 p_selfield TYPE slis_selfield.
194 "p_ucomm will hold user action like double click, clicking a button ,etc
195 CASE p_ucomm.
196 WHEN '&IC1'. " SAP standard code for double-clicking
197 READ TABLE it_mara INTO wa_mara INDEX p_selfield-tabindex. " Getting Row data
198 CASE p_selfield-fieldname.
199 WHEN 'MATNR'. " Column data
200 SET PARAMETER ID: 'MAT' FIELD p_selfield-value.
201
202 CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
203 WHEN 'MTART'.
204 MESSAGE p_selfield-value TYPE 'S'.
205 ENDCASE.
206 WHEN
207 PERFORM f_save_data.
208 MESSAGE 'Trying to save' TYPE 'S'.
209 "It_changes hold all the change made in the ALV
210 ENDCASE.
211 ENDFORM. "user_command
212 *&---------------------------------------------------------------------*
213 *& Form f_save_data
214 *&---------------------------------------------------------------------*
215 * text
216 *----------------------------------------------------------------------*
217 FORM f_save_data.
218 clear it_changes[].
219 LOOP AT it_mara INTO wa_mara.
220 READ TABLE it_maracp INTO wa_maracp index sy-tabix.
221 IF wa_maracp NE wa_mara.
222 APPEND wa_mara TO it_changes.
http://newtosap.aditech.info/2013/04/create-simple-editable-alv-grid_86.html 4/6
10/2/2018 Create a simple Editable ALV grid. ~ New To SAP
223 ENDIF.
224 clear wa_maracp.
225 ENDLOOP.
226 ENDFORM. "f_save_data
227 *&---------------------------------------------------------------------*
228 *& Form f_display_list
229 *&---------------------------------------------------------------------*
230 * text
231 *----------------------------------------------------------------------*
232 FORM f_display_list.
233 CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
234 EXPORTING
235 * I_INTERFACE_CHECK = ' '
236 * I_BYPASSING_BUFFER =
237 * I_BUFFER_ACTIVE = ' '
238 i_callback_program = sy-cprog
239 * I_CALLBACK_PF_STATUS_SET = ' '
240 i_callback_user_command = gt_callback_subroutine
241 * I_STRUCTURE_NAME =
242 is_layout = it_layout
243 it_fieldcat = it_fieldcat
244 * IT_EXCLUDING =
245 * IT_SPECIAL_GROUPS =
246 * IT_SORT =
247 * IT_FILTER =
248 * IS_SEL_HIDE =
249 * I_DEFAULT = 'X'
250 * I_SAVE = ' '
251 * IS_VARIANT =
252 * IT_EVENTS =
253 * IT_EVENT_EXIT =
254 * IS_PRINT =
255 * IS_REPREP_ID =
256 * I_SCREEN_START_COLUMN = 0
257 * I_SCREEN_STARlv_line = 0
258 * I_SCREEN_END_COLUMN = 0
259 * I_SCREEN_END_LINE = 0
260 * IR_SALV_LIST_ADAPTER =
261 * IT_EXCEPT_QINFO =
262 * I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
263 * IMPORTING
264 * E_EXIT_CAUSED_BY_CALLER =
265 * ES_EXIT_CAUSED_BY_USER =
266 TABLES
267 t_outtab = it_mara
268 EXCEPTIONS
269 program_error = 1
270 OTHERS = 2
271 .
272 IF sy-subrc <> 0.
273 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
274 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
275 ENDIF.
276
277 ENDFORM. "f_display_list
278
279 *&---------------------------------------------------------------------*
280 *& Form f_top_of_page
281 *&---------------------------------------------------------------------*
282 * text
283 *----------------------------------------------------------------------*
284 FORM f_top_of_page.
285
286 DATA: it_header TYPE slis_t_listheader,
287 wa_header TYPE slis_listheader,
lv_line LIKE wa_header-info,
http://newtosap.aditech.info/2013/04/create-simple-editable-alv-grid_86.html 5/6
10/2/2018 Create a simple Editable ALV grid. ~ New To SAP
288
289 ld_lines TYPE i,
290 ld_linesc(10) TYPE c.
291
292 * Title
293 wa_header-typ = 'H'.
294 wa_header-info = 'MARA Table Report'.
295 APPEND wa_header TO it_header.
296 CLEAR wa_header.
297
298 * Date
299 wa_header-typ = 'S'.
300 wa_header-key = 'Date: '.
301 CONCATENATE sy-datum+6(2) '.'
302 sy-datum+4(2) '.'
303 sy-datum(4) INTO wa_header-info. "todays date
304 APPEND wa_header TO it_header.
305 CLEAR: wa_header.
306
307 * Total No. of Records Selected
308 DESCRIBE TABLE it_mara LINES ld_lines.
309 ld_linesc = ld_lines.
310 CONCATENATE 'Total No. of Records Selected: ' ld_linesc
311 INTO lv_line SEPARATED BY space.
312 wa_header-typ = 'A'.
313 wa_header-info = lv_line.
314 APPEND wa_header TO it_header.
315 CLEAR: wa_header, lv_line.
316
317 CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
318 EXPORTING
319 it_list_commentary = it_header.
320 .
321 CLEAR it_header.
322 ENDFORM. "TOP-OF-PAGE
ZAU_ALVGRIDTEST.abap hosted with ❤ by GitHub view raw
This entry was posted in abap, alv, report
Newer Post Home Older Post
Copyright © 2012-2015 New To SAP
http://newtosap.aditech.info/2013/04/create-simple-editable-alv-grid_86.html 6/6