11-11-2007 4:56 AM
Hi all,
I have one ALV output which contains 10 fields(10 fields are getting displayed from one internal table).Among these 10 fields,3 fields are flags,which user can select them and save them.I have to again save these flags status(whether they are checked or not) into database table.I am able to catch all those changes into the same internal table using the method 'Check_changed_data' in the class CL_GUI_ALV_GRID.But my problem is how to save those status values(flag status) into the database table?This database table contains some more fields also other than these flags.So how to update this table also?
So,can any one suggest me how to do this?How to compare those valuesif possible please send the code.Is there any FM in CL_GUI_ALV_GRID Class?
Thanks,.
Balaji
11-11-2007 10:16 AM
Say your ALV grid has 2 checkboxes on row 1 where other fields are werks = 1000 and matnr = 222. Both checkboxes are not ticked.
Now user ticks checkbox 1 and hits save button.
In order to update this data in the database your ALV grid must contain the primary keys of the database table in which you want to update the data. Say for e.g. your database table X has primiary keys werks and matnr.
First do a select * from X into itab and sort it by the primary keys. Also sort the itab that you pass to the ALV grid in the same order.
Now after you've got the new values via event check_changed_data you read itab with key index row_id. Then <b>modify</b> the database table or use <b>update set</b> command to change the database table line where werks = 1000 and matnr = 222. Now use <b>Commit Work</b>.
Hope this solves your issue.
Don't forget to reward points.
Cheers,
Sougata.
11-11-2007 8:20 PM
Hi,
Sorry u didnt get my question properly.My question one itab which is passed to ALV grid contains all the changed data.U said is correct.Say 2 fields say check boxex are ticked.But these check boxes are not primary keys in the database table that has to be updated.
My question is how to compare field by field whehter that first,second. check box is checked or not.Remember like that I have 6 check boxes to be checked and all these check boxes are not primary keys in that database table.
Thanks,
Balaji
11-11-2007 10:54 PM
The primary key fields of the database table (that you want to update) has to be in the same row of the ALV Grid, displayed or hidden. See example below.
<u>Database table <b>ZDBTAB</b> structure</u>
Mandt - Key
Werks - Key
Matnr - Key
Zfield - non-key
Checkbox1 - non-key
Checkbox2 - non-key
<u>ALV GRID Row 1 displaying database table <b>ZDBTAB</b></u>
<u>Column names</u>
Werks (hidden) Matnr (displayed) Zfield (hidden) Checkbox1(displayed) CBox2(displayed)
Now say user ticks CBox1. You catch this change already bu using the method check_changed_data. Your internal table IT_CHNG has one line now with row id of the ALV grid.
Now, previously we had selected * from ZDBTAB and placed it in ITAB.
so now read table ITAB with index IT_CHNG-row_id. Only the fieldname CBOX1 and value = 'X' for this row id has changed in the grid that must be updated and all other fields remains the same. Here you pass CBOX1 = 'X' and <b>Modify</b> ZDBTAB current line where WERKS = ITAB-WERKS and MATNR = ITAB-MATNR and leave the other fields alone.
Similaryly in case of 6 Checkboxes, if IT_CHANGE comes up with CB1, CB2 & CB3 then the old values of these checkboxes must have been just opposite to what they are now because its either 'X' or space.
<b>I've spent a lot of time for you so please don't forget to reward points.</b>
Cheers,
Sougata.
Where's my points mate??????
Message was edited by:
Sougata Chatterjee