0% found this document useful (0 votes)
222 views

How To Get The Updated Data From A Editable ALV (CL - GUI - ALV - GRID)

This document provides code to demonstrate how to get updated data from an editable ALV (CL_GUI_ALV_GRID) grid when a button is clicked. The code creates an ALV grid bound to an internal table using CL_GUI_ALV_GRID. It implements event handlers for the toolbar and user commands to check for data changes and refresh the internal table with the updated data from the ALV grid.

Uploaded by

koisak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
222 views

How To Get The Updated Data From A Editable ALV (CL - GUI - ALV - GRID)

This document provides code to demonstrate how to get updated data from an editable ALV (CL_GUI_ALV_GRID) grid when a button is clicked. The code creates an ALV grid bound to an internal table using CL_GUI_ALV_GRID. It implements event handlers for the toolbar and user commands to check for data changes and refresh the internal table with the updated data from the ALV grid.

Uploaded by

koisak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

| Demo & Utility codes | Tips & Tricks | Best Practices

How to get the updated data from a editable ALV (CL_GUI_ALV_GRID)


This program demonstrates how to get the updated data when a button is clicked in the GUI toolbar or ALV toolbar. The ALV is created using
CL_GUI_ALV_GRID.

1 *&---------------------------------------------------------------------*
2 *& Report ZZSOURAV_REFRESH_ALV
3 *&
4 *&---------------------------------------------------------------------*
5 *&
6 *&
Search This Blog
7 *&---------------------------------------------------------------------*
8 Search
9 REPORT zzsourav_refresh_alv.
10 DATA: ok_code TYPE syucomm.
11 *----------------------------------------------------------------------* ALE (1)
12 * CLASS main DEFINITION ALV (8)
13 *----------------------------------------------------------------------* BADI (1)
14 * BOL Programming (1)
15 *----------------------------------------------------------------------* Custom Conversion Exit (1)
16 CLASS main DEFINITION.
Dynamic Internal Table (2)
17 PUBLIC SECTION.
EDI (1)
18 DATA: i_sbook TYPE STANDARD TABLE OF sbook INITIAL SIZE 0,
Excel upload (1)
19 i_sbook_old TYPE STANDARD TABLE OF sbook INITIAL SIZE 0.
20 F4 Help (2)

21 METHODS:constructor, HTML in ABAP (1)


22 handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid Module Pool (3)
23 IMPORTING e_object e_interactive, Performance Tuning (1)
24 handle_user_command FOR EVENT REGEX (1)
25 user_command OF cl_gui_alv_grid Selection Screen (3)
26 IMPORTING e_ucomm, TMG (1)
27 check_changed_data.
Traffic Light (1)
28 PROTECTED SECTION.
Transaction Codes (2)
29
Useful Function Modules (4)
30
31 PRIVATE SECTION. Utility Codes (12)
32 TYPE-POOLS: icon. Utility Tips (20)
33 DATA:container TYPE REF TO cl_gui_custom_container,
34 oref_alv TYPE REF TO cl_gui_alv_grid, Subscribe via email
35 wa_layout TYPE lvc_s_layo,
36 i_fieldcatalog TYPE lvc_t_fcat.
Enter your email address:
37 METHODS:get_field_catalog,get_layout.
38 ENDCLASS. "main DEFINITION
39 *----------------------------------------------------------------------*
40 * CLASS main IMPLEMENTATION Subscribe
41 *----------------------------------------------------------------------*
42 *
43 *----------------------------------------------------------------------* Followers Total Pageviews
44 CLASS main IMPLEMENTATION.
45 METHOD constructor. Obserwatorzy (14)
46
47 SELECT * FROM sbook INTO TABLE i_sbook
4
48 UP TO 50 ROWS.
49 i_sbook_old[] = i_sbook[].
50
51 CREATE OBJECT container
52 EXPORTING
53 * parent =
54 container_name = 'CONT1'
55 * style =
56 * lifetime = lifetime_default
57 repid = sy-repid Obserwuj
58 dynnr = '0100'
59 * no_autodef_progid_dynnr =
60 EXCEPTIONS
61 cntl_error = 1
62 cntl_system_error = 2
63 create_error = 3
64 lifetime_error = 4
65 lifetime_dynpro_dynpro_link = 5
66 OTHERS = 6
67 .
68 IF sy-subrc <> 0.
69 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
70 * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
71 ENDIF.
72
73
74 CREATE OBJECT oref_alv
75 EXPORTING
76 * i_shellstyle = 0
77 * i_lifetime =
78 i_parent = container
79 * i_appl_events = space
80 * i_parentdbg =
81 * i_applogparent =
82 * i_graphicsparent =
83 * i_name =
84 * i_fcat_complete = space
85 EXCEPTIONS
86 error_cntl_create = 1
Explore...ABAP: How to get the updated data from a editable ALV (... http://abap-explorer.blogspot.com/2008/09/how-to-get-updated-data-f...

87 error_cntl_init = 2
88 W tej witrynie są wykorzystywane
error_cntl_link = 3 pliki cookie, których Google używa do świadczenia swoich usług
89 ierror_dp_create
analizowania ruchu.= Twój
4 adres IP i nazwa klienta użytkownika oraz dane dotyczące wydajności DOWIEDZ SIĘ WIĘCEJ OK
90 iOTHERS
bezpieczeństwa są=udostępniane
5 firmie Google, by zapewnić odpowiednią jakość usług, generować statystyki
91 użytkowania
. oraz wykrywać nadużycia i na nie reagować.
92 IF sy-subrc <> 0.
93 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
94 * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
95 ENDIF.
96
97 CALL METHOD me->get_field_catalog.
98 CALL METHOD me->get_layout.
99
100 CALL METHOD oref_alv->set_table_for_first_display
101 EXPORTING
102 * i_buffer_active =
103 * i_bypassing_buffer =
104 * i_consistency_check =
105 * i_structure_name =
106 * is_variant =
107 * i_save =
108 * i_default = 'X'
109 is_layout = wa_layout
110 * is_print =
111 * it_special_groups =
112 * it_toolbar_excluding =
113 * it_hyperlink =
114 * it_alv_graphics =
115 * it_except_qinfo =
116 * ir_salv_adapter =
117 CHANGING
118 it_outtab = i_sbook
119 it_fieldcatalog = i_fieldcatalog
120 * it_sort =
121 * it_filter =
122 EXCEPTIONS
123 invalid_parameter_combination = 1
124 program_error = 2
125 too_many_lines = 3
126 OTHERS = 4
127 .
128 IF sy-subrc <> 0.
129 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
130 * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
131 ENDIF.
132 SET HANDLER me->handle_toolbar FOR oref_alv.
133 SET HANDLER me->handle_user_command FOR oref_alv.
134
135 CALL METHOD oref_alv->set_toolbar_interactive.
136
137 ENDMETHOD. "constructor
138 METHOD get_layout.
139 wa_layout-cwidth_opt = 'X'.
140 ENDMETHOD. "get_layout
141 METHOD get_field_catalog.
142 FIELD-SYMBOLS: <lf1> TYPE lvc_s_fcat.
143
144 CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
145 EXPORTING
146 * I_BUFFER_ACTIVE =
147 i_structure_name = 'SBOOK'
148 i_client_never_display = 'X'
149 * I_BYPASSING_BUFFER =
150 i_internal_tabname = 'I_SBOOK'
151 CHANGING
152 ct_fieldcat = i_fieldcatalog
153 EXCEPTIONS
154 inconsistent_interface = 1
155 program_error = 2
156 OTHERS = 3
157 .
158 IF sy-subrc <> 0.
159 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
160 * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
161 ENDIF.
162
163 LOOP AT i_fieldcatalog ASSIGNING <lf1>.
164 IF <lf1>-fieldname = 'SMOKER'.
165 <lf1>-edit = 'X'. " REUSE_ALV_GRID_DISPLAY
166 ENDIF.
167 ENDLOOP.
168 ENDMETHOD. "get_field_catalog
169 METHOD handle_toolbar.
170 DATA: l_toolbar TYPE stb_button.
171 CLEAR l_toolbar.
172 * append an icon to show booking table
173 CLEAR l_toolbar.
174 MOVE 'SAVE' TO l_toolbar-function.
175 MOVE icon_system_save TO l_toolbar-icon.
176 MOVE 'Save' TO l_toolbar-quickinfo.
177 MOVE 'Save' TO l_toolbar-text.
178 MOVE ' ' TO l_toolbar-disabled.
179 APPEND l_toolbar TO e_object->mt_toolbar.
180
181 ENDMETHOD. "handle_toolbar
182 METHOD handle_user_command.
183 CASE e_ucomm.
184 WHEN 'SAVE'.
185 IF i_sbook[] <> i_sbook_old[].
186 MESSAGE i001(00) WITH 'You have changed some data'.
187 ELSE.
188 MESSAGE i001(00) WITH 'No data changed'.
189 ENDIF.
190 ENDCASE.
191 ENDMETHOD. "user_command

2z4 22.02.2022, 20:44


Explore...ABAP: How to get the updated data from a editable ALV (... http://abap-explorer.blogspot.com/2008/09/how-to-get-updated-data-f...

192 METHOD check_changed_data.


193 W tej witrynie są wykorzystywane pliki cookie, których Google używa do świadczenia swoich usług
194 CALLi analizowania ruchu. Twój adres IP i nazwa klienta użytkownika oraz dane dotyczące wydajności
METHOD oref_alv->check_changed_data DOWIEDZ SIĘ WIĘCEJ OK
195 * i bezpieczeństwa są udostępniane firmie Google, by zapewnić odpowiednią jakość usług, generować
IMPORTING statystyki
196 * użytkowania
e_valid =oraz wykrywać nadużycia i na nie reagować.
197 * CHANGING
198 * c_refresh = 'X'
199 .
200
201
202 ENDMETHOD. "CHECK_CHANGED_DATA
203 ENDCLASS. "main IMPLEMENTATION
204
205 START-OF-SELECTION.
206
207 DATA: oref_main TYPE REF TO main.
208 CREATE OBJECT oref_main.
209
210 CALL SCREEN 0100.
211 *&---------------------------------------------------------------------*
212 *& Module STATUS_0100 OUTPUT
213 *&---------------------------------------------------------------------*
214 * text
215 *----------------------------------------------------------------------*
216 MODULE status_0100 OUTPUT.
217 SET PF-STATUS 'S0100'.
218 * SET TITLEBAR 'xxx'.
219
220 ENDMODULE. " STATUS_0100 OUTPUT
221 *&---------------------------------------------------------------------*
222 *& Module USER_COMMAND_0100 INPUT
223 *&---------------------------------------------------------------------*
224 * text
225 *----------------------------------------------------------------------*
226 MODULE user_command_0100 INPUT.
227
228 CASE ok_code.
229 WHEN 'BACK'.
230
231 SET SCREEN 00.
232 LEAVE SCREEN.
233 WHEN 'SAVE'.
234 " Check this part if the button is SAP standard toolbar
235 CALL METHOD oref_main->check_changed_data.
236 IF oref_main->i_sbook[] NE oref_main->i_sbook_old[].
237 MESSAGE i001(00) WITH 'You have changed some data'.
238 ELSE.
239 MESSAGE i001(00) WITH 'No data changed'.
240 ENDIF.
241
242 ENDCASE.
243 ENDMODULE. " USER_COMMAND_0100 INPUT

Initial ALV display with editable column:

When any of the "SAVE" button is clicked but no changed data:

When something is changed and any of the "SAVE" button is clicked:

3z4 22.02.2022, 20:44


Explore...ABAP: How to get the updated data from a editable ALV (... http://abap-explorer.blogspot.com/2008/09/how-to-get-updated-data-f...

W tej witrynie są wykorzystywane pliki cookie, których Google używa do świadczenia swoich usług
i analizowania ruchu. Twój adres IP i nazwa klienta użytkownika oraz dane dotyczące wydajności DOWIEDZ SIĘ WIĘCEJ OK
i bezpieczeństwa są udostępniane firmie Google, by zapewnić odpowiednią jakość usług, generować statystyki
użytkowania oraz wykrywać nadużycia i na nie reagować.

1 comment:

Kedi Sevenler Kulübü June 26, 2013 at 6:45 PM

Nice Post. Thans you help me a lot.

Reply

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

Simple theme. Powered by Blogger.

4z4 22.02.2022, 20:44

You might also like