Hi Ahmed,
there are some reasons for a reversal of a whole transaction no. You can post with different document nos. and the same transaction, it depends on how the general journal is set up.
What you can do:
You can filter the reversal form by setting a filter on the (for example) document no. (like you try to do in code). You can do this on the form when the transaction to reverse is shown. These filters should be respected during the reversal.
with best regards
Jens