I need to flag the duplicate fields in a table but sy-tabix is always increasing. I expect for every knum group, a 1 in sy-tabix. Here is the code.
sort result_package stable by knumh zzklfn1.
loop at result_package assigning <result_fields>
group by ( knum = <result_fields>-knum ).
if sy-tabix > 1.
data(lv_duplicate) = 'x'.
endif.
lv_duplicate = ''.
endloop.
How to flag the duplicate record?
Tried to code but sy-tabix is increasing.
It depends for what you need this flag. You can do it simple: after sorting the table just loop over it and compare the current work area with the previous one and mark the duplicate flag if they are the same (or compare only the fields of interest).
If at the end you need the list without duplicates, after sorting you can use
ADJACENT DUPLICATESkeyword to remove duplicates:deletes all rows in certain groups of rows following one another, except for the first row of the group.
Additionally you can specify what to compare:
If the addition COMPARING is not specified, the groups are determined by the content of the key fields of the table key being used. If no explicit table key is specified, the primary table key is used implicitly.