I need to flag the duplicate values and I found a solution using the code below:
sort result_package stable by knumh zzklfn1.
data lv_prev_knumh type c length 10.
loop at result_package assigning <result_fields>.
if <result_fields>-knumh <> lv_prev_knumh.
lv_prev_knumh = <result_fields>-knumh.
<result_fields>-zzstafkz = ''.
else.
<result_fields>-zzstafkz = 'X'.
endif.
endloop.
But obviously the first duplicated value is not flagged. Output is shown below:
| knumh | zzstafkz |
|---|---|
| 001 | |
| 002 | |
| 002 | x |
| 002 | x |
| 003 |
I don't know really what should I do next.
You can simply do it by keeping the reference to the previous record and assign
Xflag when the condition meets.Types declaration and sample data for test:
The logic itself:
Sample output: