‎2012 Jan 06 8:44 AM
Hello,
I would like to implement edit functionality of an internal table with ALV based on class CL_GUI_ALV_GRID. Some fields of internal table are key fields and the combination of them should be unique. The user has a possibility to add a new record (all fields in new record are editable) or change values in an existing record (only non-key fields are editable). So far so good, it works.
I'm doing a validation of entered data in the event DATA_CHANGED. In this event I'm checking if the new record is a duplicate combination of existing key fields. If yes, then all fields of the new record are reported as error with ADD_PROTOCOL_ENTRY method. This removes all entries related to this row from MT_GOOD_CELLS table and this is ok for me.
My problem: after validation ALV inserts such empty row in my internal table and next time, when the user makes a correction, this record is an update and not a new record (there is no entry in MT_INSERTED_ROWS).
Question: Is there a possibility to avoid ALV inserting a new record when all its cells are bad?
Regards,
Annie
‎2012 Jan 06 10:45 AM
Hi,
I did the same ALV and event handle. We use this ALV to edit/insert records in the Z table.
My solution was to create two internal tables, one for inserted records and other to update records.
If user change the empty row, it was a update row to ALV, but a new line in output table. Then i did a select to check if the updated ALV row exists. When user press the SAVE button, the program process the records to update and the records to insert. I did not find a way to block the empty row create.
Best regards.
‎2012 Jan 06 10:45 AM
Hi,
I did the same ALV and event handle. We use this ALV to edit/insert records in the Z table.
My solution was to create two internal tables, one for inserted records and other to update records.
If user change the empty row, it was a update row to ALV, but a new line in output table. Then i did a select to check if the updated ALV row exists. When user press the SAVE button, the program process the records to update and the records to insert. I did not find a way to block the empty row create.
Best regards.
‎2012 Jan 06 10:56 AM
Hi,
I dont know how to avoid addition of empty row,
But to fix your issue,
Whenever ADD_PROTOCOL_ENTRY catches error,
you can delete the row from internal table with key as initial.
Regards,
Harsh Bansal
‎2012 Jan 09 11:22 AM
Hi,
As far as i have understood your problem,you can try the following to avoid the insertion of an empty row:
When you must be creating an empty row,just set a flag say flag_create = 'X'.
Then when you are performing the validation then if there is an error then check for this flag that is :
if flag_create = 'X'.
then delete from the internal table based on sy-tabix.
endif.
This way the new row that got appended with wrong values will get deleted and the code will not consider this as an updated row.
Kindly <<deleted> if useful.:)
Follow the rules of engagement
Edited by: Vijay Babu Dudla on Jan 9, 2012 7:07 AM
‎2012 Jan 12 1:38 PM
Hello,
Thanks a lot for all answers. If I delete the empty rows from the internal table, the new inputs are stored in MT_INSERTED_ROWS as I wanted. Then I've to deal with next problems, which I haven't expected,
for example if user entered two new rows: first row is wrong (1) and the second is ok (2). ALV will do both inserts,
then I'm deleting the empty one (1), and next time the corrected row (1) overwrites the row, which was inserted previously (2).
I think, I've to implement it without removing empty rows.
Cheers,
Annie
‎2012 Jan 12 2:12 PM
Hi,
I think its happening because you are deleting the rows with sy-tabix.And since you are looping and then deleting so everytime the sy-tabix value is remaining the same.Hence its getting overwritten.
For this you can try setting another flag as soon as one line is deleted like below:
loop at internal table into work area.
if flag_delete is initial.
delete from the internal table based on sy-tabix.
flag_delete = 'X'.
endif.
endloop.
This is just a format that you can try implementing in your logic.
I hope it serves useful to you.:)