Documente Academic
Documente Profesional
Documente Cultură
MakingALVtoreacttoChangedataautomaticallyABAPDevelopmentSCNWiki
GettingStarted Newsletters
Welcome,Guest
Login
Register
Store
SearchtheCommunity
Products
Services&Support
AboutSCN
Downloads
Industries
Training&Education
Partnership
DeveloperCenter
LinesofBusiness
UniversityAlliances
Events&Webinars
Innovation
ABAPDevelopment / ABAPDevelopment
MakingALVtoreacttoChangedataautomatically
AddedbyPadmavathiPalli,lasteditedbySmrutiRanjanMohantyonOct18,2013
Thethreadathttps://forums.sdn.sap.com/thread.jspa?threadID=985676&tstart=0hasmotivatedmetowritethisminitutorialwhichmightbeusefulforothers.
Scenario:
TomakeALVtoreacttodatachangeautomaticallywithoutanyneedfortheusertoclickonENTERoranyotherbutton/menuitem.
Procedure:
Inordertomakethesystemreacttoaneditevent,weneedtofirstregistertheeditevent.
Toregistertheeditevent,callthemethodREGISTER_EDIT_EVENT
CALLMETHODcont_editalvgd>register_edit_event
Exporting
{}I_event_id=cl_gui_alv_grid=>mc_evt_modified.
Whenuserpress'ENTER'theeventMC_EVT_ENTERistriggeredwhichautomaticallysetsthevariableM_cell_editto'X'.
ButiftheuserbypassestheenterkeythenthevariableM_CELL_EDIThastobesetexplicitlywhichisdonebypassingmc_evt_modifiedtotheexportingparameterI_EVENT_IDinsteadof
mc_evt_enter.
InthePAIevent,callthemethodCHECK_CHANGED_DATA.Thismethodautomaticallytriggersthedata_changedevent.
Bydefault,SAPrecognizes'ENTER'event.WhenonlytheCHECK_CHANGED_DATAiscalledinPAIevent,thenthe'ENTER'eventisnotrecognizedbythesystem.Inordertohaveboththeevents
recognizedbythesystem,weneedtoregistertheeditevent.
Samplecode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
REPORTZ_ALV_EDIT_EVENT.
*"Tabledeclarations...................................................
TABLES:
SPFLI."FlightScheduleDetails
*"Datadeclarations...................................................
*"*
*Workvariables*
*"*
DATA:
W_GRIDTYPEREFTOCL_GUI_ALV_GRID,"Referenceobjectforalvgrid
W_CONTAINERTYPEREFTOCL_GUI_CUSTOM_CONTAINER.
"Referenceobjectforcontainer
*"*
*StructuretoholdFlightScheduledetails*
*"*
DATA:
FS_SPFLITYPESPFLI.
*"*
*StructuretoholdFieldCatalogdetails*
*"*
DATA:
WA_FIELD_CATALOGTYPELVC_S_FCAT.
*"*
http://wiki.scn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically
1/7
5/16/2015
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
MakingALVtoreacttoChangedataautomaticallyABAPDevelopmentSCNWiki
*StructuretoholdLayoutoftheALVReport*
*"*
DATA:
WA_LAYOUTTYPELVC_S_LAYO.
*"*
*InternaltabletoholdFlightScheduledetailsfromtableSPFLI*
*"*
DATA:
T_SPFLILIKE
STANDARDTABLE
OFFS_SPFLI.
*"*
*InternaltabletoholdFieldCatalogDetails*
*"*
DATA:
T_FIELD_CATALOGTYPELVC_T_FCAT.
*"*
*STARTOFSELECTIONEVENT*
*"*
STARTOFSELECTION.
*Dataretrievalfromthedatabasetable
SELECT*FROMSPFLIINTOTABLET_SPFLI.
CALLSCREEN100.
*&*
*&Moduleset_layoutOUTPUT
*&*
*Thismoduleisusedtosetthelayoutforthealvgriddisplay*
**
MODULESET_LAYOUTOUTPUT.
WA_LAYOUTGRID_TITLE='SPFLITABLEDETAILS'.
WA_LAYOUTZEBRA='X'.
WA_LAYOUTEDIT='X'.
ENDMODULE."set_layoutOUTPUT
*&*
*&Modulefield_catalogOUTPUT
*&*
*Thismoduleisusedtopopulatethefieldcatalog*
**
MODULEFIELD_CATALOGOUTPUT.
CLEARWA_FIELD_CATALOG.
WA_FIELD_CATALOGFIELDNAME='CARRID'.
WA_FIELD_CATALOGREF_FIELD='CARRIDS'.
WA_FIELD_CATALOGREF_TABLE='SPFLI'.
WA_FIELD_CATALOGCOL_POS=1.
APPENDWA_FIELD_CATALOGTOT_FIELD_CATALOG.
CLEARWA_FIELD_CATALOG.
WA_FIELD_CATALOGFIELDNAME='CONNID'.
WA_FIELD_CATALOGREF_FIELD='CONNID'.
WA_FIELD_CATALOGREF_TABLE='SPFLI'.
WA_FIELD_CATALOGCOL_POS=2.
APPENDWA_FIELD_CATALOGTOT_FIELD_CATALOG.
CLEARWA_FIELD_CATALOG.
WA_FIELD_CATALOGFIELDNAME='CITYFROM'.
WA_FIELD_CATALOGREF_FIELD='CITYFROM'.
WA_FIELD_CATALOGREF_TABLE='SPFLI'.
WA_FIELD_CATALOGCOL_POS=3.
APPENDWA_FIELD_CATALOGTOT_FIELD_CATALOG.
CLEARWA_FIELD_CATALOG.
WA_FIELD_CATALOGFIELDNAME='CITYTO'.
WA_FIELD_CATALOGREF_FIELD='CITYTO'.
WA_FIELD_CATALOGREF_TABLE='SPFLI'.
WA_FIELD_CATALOGCOL_POS=4.
APPENDWA_FIELD_CATALOGTOT_FIELD_CATALOG.
ENDMODULE."field_catalogOUTPUT
http://wiki.scn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically
2/7
5/16/2015
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
MakingALVtoreacttoChangedataautomaticallyABAPDevelopmentSCNWiki
*&*
*&ModuleUSER_COMMAND_0100INPUT
*&*
*ThismoduleisusedtohandlethePAIevents
**
MODULEUSER_COMMAND_0100INPUT.
CASESYUCOMM.
WHEN'OK'.
*Callingthecheck_changed_datamethodtotriggerthedata_changed
*event
*
CALLMETHODW_GRID>CHECK_CHANGED_DATA
*IMPORTING
*E_VALID=
*CHANGING
*C_REFRESH='X'
.
UPDATESPFLIFROMTABLET_SPFLI.
WHEN'BACK'OR'EXIT'OR'CANCEL'.
LEAVETOSCREEN0.
ENDCASE."CASESYUCOMM
ENDMODULE."USER_COMMAND_0100INPUT
*&*
*&Modulemanage_alv_gridOUTPUT
*&*
*ThismoduleisusedtomanagetheGriddisplay
**
MODULEMANAGE_ALV_GRIDOUTPUT.
IFW_GRIDISINITIAL.
CREATEOBJECTW_CONTAINER
EXPORTING
CONTAINER_NAME='CONTAINER1'
EXCEPTIONS
CNTL_ERROR=1
CNTL_SYSTEM_ERROR=2
CREATE_ERROR=3
LIFETIME_ERROR=4
LIFETIME_DYNPRO_DYNPRO_LINK=5
OTHERS=6
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF."IFSYSUBRCNE0
CREATEOBJECTW_GRID
EXPORTING
I_PARENT=W_CONTAINER
EXCEPTIONS
ERROR_CNTL_CREATE=1
ERROR_CNTL_INIT=2
ERROR_CNTL_LINK=3
ERROR_DP_CREATE=4
OTHERS=5.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF."IFSYSUBRCNE0
CALLMETHODW_GRID>SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME='SPFLI'
IS_LAYOUT=WA_LAYOUT
CHANGING
http://wiki.scn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically
3/7
5/16/2015
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
MakingALVtoreacttoChangedataautomaticallyABAPDevelopmentSCNWiki
IT_OUTTAB=T_SPFLI[]
IT_FIELDCATALOG=T_FIELD_CATALOG
EXCEPTIONS
INVALID_PARAMETER_COMBINATION=1
PROGRAM_ERROR=2
TOO_MANY_LINES=3
OTHERS=4.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF."IFSYSUBRCNE0
ENDIF."IFW_GRIDISINITIAL
*RegisteringtheEDITEvent
CALLMETHODW_GRID>REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID=CL_GUI_ALV_GRID=>MC_EVT_MODIFIED
EXCEPTIONS
ERROR=1
OTHERS=2.
IFSYSUBRC<>0.
*MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
*WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF."IFSYSUBRCNE0
ENDMODULE."manage_alv_gridOUTPUT
*&*
*&ModuleSTATUS_0100OUTPUT
*&*
*ThismoduleisusedtosetthePFStatusandtitlebar*
**
MODULESTATUS_0100OUTPUT.
SETPFSTATUS'ALVS_GUI'.
SETTITLEBAR'ALV_TITLE'.
ENDMODULE."STATUS_0100OUTPUT
Scenario1:WhenthereisnocalltothemethodREGISTER_EVT_MODIFIEDandjustgowiththecallingofthemethodCHECK_CHANGED_DATAinthePAIevent.
Thewholescenariowouldworkfinewhenyouchangethedataandpressthe"OK"buttonontheapplicationtoolbar.
But,whenyouchangethedataandpressthe'ENTER'keythentheeventdata_changedisnottriggered.
1.ChangethedataintheeditableALVandpress'ENTER'key.
http://wiki.scn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically
4/7
5/16/2015
MakingALVtoreacttoChangedataautomaticallyABAPDevelopmentSCNWiki
ThechangesarenotreflectedintheALVasnodata_changedeventhasbeentriggered.
Scenario2:WhenyouregistertheediteventandcallthemethodCHECK_CHANGED_DATAinthePAIevent.
1.ChangethedataintheeditableALVandpressthe'OK'buttonontheapplicationtoolbar.
http://wiki.scn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically
5/7
5/16/2015
MakingALVtoreacttoChangedataautomaticallyABAPDevelopmentSCNWiki
ThechangeddataisrecognizedandisreflectedontotheeditableALV
Inthesamecase,whenyouchangethedataintheALVandpress'ENTER'key,youcanstillseethechangesreflected.
ClickonENTER.
http://wiki.scn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically
6/7
5/16/2015
MakingALVtoreacttoChangedataautomaticallyABAPDevelopmentSCNWiki
Thechangeeventistriggeredandthedatahasbeenchangedaccordingly.
alv
abap
event
1Comment
AdrianBruwer
Superusefulpost!ThankyouverymuchPadmavathiPalli
Adrian
ContactUs
Privacy
SAPHelpPortal
TermsofUse
LegalDisclosure
Copyright
http://wiki.scn.sap.com/wiki/display/ABAP/Making+ALV+to+react+to+Change+data+automatically
FollowSCN
7/7