Hello Caroline,
Lets try this way,
sort the internal table by position num, P and obsolete.
loop at itab into wa.
if wa-position = lv_prev_pos.
if wa-obsolete <> 'X'.
delete itab from wa.
endif.
endif.
lv_prev_pos = wa_position.
endloop.
Please publish if you face any issue.
Thanks and Regards,
Bhaskar