The solution to this problem consists of a so called currency swap. For this purpose, an intermediate clearing account is used, and the posting is split up into two documents. One document debits the position account and credits the clearing account in position currency, while the second document debits the clearing account and credits the bank clearing in payment currency. Thus, the clearingaccount is posted to in different currencies, and the balance of the clearing account is always zero in the local currency.
check also this thread: Currency Swap - position/payment currency