In this post, I will describe my own experience to extend migration object “Purchasing contract” in order to allow input of condition scales.
As per SAP deliverd template, we can only enter simple conditions, without quantity nor value scales. As described in my previous post about Migration Cockpit, I will demonstrate that it is not much difficult than to use BAPI to create a contract.
Though this blog post is specific to purchasing contracts, you should apply the same approach for any migration object enhancement.
- Assess the current situation
- Understand and make BAPI work
- Set up mappings in LTMC
- Debug BAPI call in case of error
Out of the box, scales cannot be filled in the delivered template:
This can be confirmed if you open the object in the migration modeler (LTMOM), nothing in the source structure:
And nothing in the structure mapping:
But don’t be afraid, we are at home, remember target structures are actually structures of BAPI BAPI_CONTRACT_CREATE:
This simply means once we know how to call BAPI, we know how to call it from Migration Cockpit. But hold on, this may sound as a dumb question, but do you know how to create a contract actually?
The following may be obvious, but the correct approach is not to go and fill randomly your structure mappings and field mappings until it works. Just take a breath, go step by step
- Do you really know how to manually create a contract in (ME31K for instance)?
- Then, do you know how to create the exact same contract with BAPI?
- Then, and only then, go and map structure and fields accordingly in LTMOM
Create manually a sample contract with ME31K
First things first, start by creating a sample contract with scale conditions (as you would like Migration Cockpit to create them). You can use ME31K or Fiori app, as you wish.
In my case, I want my contract to contain price conditions with scales.
Try not to make it too simple, put at least 2 items, different values, etc.
Try to create the same contract with BAPI
Now that we have a sample contract, our goal is to be able to programmatically reach the same document. We are really lucky, as this BAPI is not just a lonely “Create” function, but contains method like “GetDetails”.
I will not go through a long explanation of what is exactly a BAPI, but you may know you can see it (the real object which holds this function) with SWO1:
Or with transaction BAPI:
Or even simpler, in object list of the function group:
Method display, actually BAPI_CONTRACT_GETDETAIL is a great helper function in our case as it will speed up our analysis: a call to BAPI_CONTRACT_GETDETAIL with our sample contract number as argument will reveal a lot of the expected input parameters for scales in BAPI_CONTRACT_CREATE.
Call it in SE37:
And output structures and values reflect more or less the expected input parameters:
In my case, my sample contract contains 2 items and both price conditions have 3 steps. I will save you time by summarizing my analysis steps, but I have inferred that the important fields to be populated in input parameters are:
Scale types, to be provided in ITEM_CONDITION
And of course, the scales themselves
Then, I create a variant in SE37 that I can execute in a test sequence with BAPI_TRANSACTION_COMMIT: my BAPI analysis is complete, I know for sure the required fields to manage scale conditions in a contract. I can set the relevant mapping in LTMOM.
I repeat it again and again, you must be sure of your BAPI parameter before you do any mapping in LTMC. Start by adapting source structures by adding scales under item structure (it is a copy-paste of BAPIMEOUTITEMSCALEQUAN)
Next, map the required target structures:
Finally, map the required fields of ITEM_COND_VALIDI:
And for scales (quantity):
You may have noticed 2 custom rules:
- INIT_LINE_NO : this resets global variable g_scale_item to 1
- INCREMENT_LINE_NO : this increments global variable g_scale_item
g_scale_item is a global variable (you can use the same way as you use to do in LSMW) which will be used to set value in ITEM_COND_SCALE-LINE_NO automatically.
Once all changes are done, generate function group.
If you have reached this step, you know by heart your required BAPI parameters for BAPI_CONTRACT_CREATE: this is going to be the final step, all previous mappings operations which you have set up will be applied in the generated functions.
All these mappings are the less “visible” parts of the cockpit (but you can still debug it if required). To ensure you get to BAPI_CONTRACT_CREATE with all parameters filled as expected, set an external breakpoint in it, and check all parameters are filled correctly. If not, fix your mapping, retry, etc.
I hope this explanation is clear enough and will help you in extending SAP-delivered migration templates to meet your requirements. Remember LTMOM is not a monolithic tool, the logic of data creation remains outside, in BAPI function (or any other function like the one for customer/supplier). Once you know how to create with a BAPI call, you are in a safe place.