Hi,
You would have to trigger a function module from the Clearing Variant configuration.
Use Clearing rule "7", which allows you to clear based on your custom function module.
SAP has provided a sample function module that you can use as a template to trigger your own clearing logic.
related documentation is attached.
I hope this helps.
Regards,
Ivor