BAdI for Choosing Future Positions When Creating Close Transactions

Some time ago I had a conversation with a very experienced colleague of mine. We were discussing Commodity Future handling via BAPI, where he told me that he is missing the flexibility to assign lots on Closing transactions.

I then asked him  if he was familiar with the BAdI BADI_TRQ_LOT_ASSIGNMENT, to which he replied in the negative. This BAdI would certainly have helped him. Since the topic is unknown to many, I would like to deepen it once and post it here.

But from the start. When you create a closing Future position in FTR_CREATE and try to save or check you will get the popup as displayed in the screenshot shown below. An alternative to that is that you have setup your system in a way that it is not displayed, but Last in First out (LIFO) or First in First out (FIFO) is automatically applied.
One more alternative is that the Assigned Units are preset following the LIFO or FIFO approach.

When creating closing transactions via calling the BAPIs you will not see the popup, as BAPIs are supposed to run without user interaction. Therefore, you have either setup your system to use FIFO or LIFO.

All that setup is done in the customizing activity “Assign Consumption Sequence Procedure”. It can be found by following the customizing path:

Treasury and Risk Management -> Transaction Manager -> General Settings -> Accounting -> Settings for Position Management -> Assign Consumption Sequence Procedure

And in that customizing activity you can also define the Consumption Sequence to be “BAdI”.
If that Consumption Sequence is chosen the system will call the implementation of BAdI BADI_TRQ_LOT_ASSIGNMENT and a custom specific consumption sequence can be implemented.

For example, I used that BAdI once in a case where a customer uses an own solution for entering financial deals in the system and triggers the creation of the actual TRM Financial Transaction via BAPIs.
The customer had now the requirement that whenever a closing Future was entered in his custom solution he wanted to have the open positions being closed out according to the data maintained in his custom built solution.
I solved that by implementing this BAdI and by having the consumption sequence been setup accordingly.

How is it for you? Did you know about that possibility? Did you ever have the need for a custom consumption sequence?