New ABAP syntax, VALUE FOR skip appending entry if it already exists

Hello experts,

 I have the following case – this piece of code is being called inside of a loop where I am being given several entries for each key. On the first iteration we go through all the entries and everything is okay. But the program is a dynpro so when the user interacts with it somehow we restart the loop and we go over the same entries again. So my goal is to prevent that and just keep the entries from the first run, if we go over the entries again with the same key then we just need to update the values with the new ones. Is it still possible with the new syntax?

What I am trying is:

r_unduplicated_values = VALUE #( FOR row_of_tab_with_duplicates IN tab_with_duplicates
                                                        ( CORRESPONDING #( row_of_tab_with_duplicates ) ) .

The closest thing I was able to do was:
r_unduplicated_values = VALUE #( FOR row_of_tab_with_duplicates IN tab_with_duplicates
                                                       ( COND #( WHEN NOT line_exists( r_unduplicated_values[ key = row_of_tab_with_duplicates-key ] )
THEN CORRESPONDING #( row_of_tab_with_duplicates ) ) ) ).

 

But unfortunately this will just append empty rows in the case that the line already exists in the table

What do I need to add to this syntax skeleton so that when a row has already been added like the one we are currently processing in the FOR loop it skips appending this row and continues with the other rows?

I know it is possible to just let it append the duplicates and then sort + delete duplicates but I wanted to do it all at once if possible with the new syntax.

 

Thank you!

Scroll to Top