How to add custom fields to SAP S/4HANA data migration cockpit with data migration modeller. Example with material master.
During last months I posted two blogs referring to the migration of master data (business partners) and transactional data (stock) using S/4HANA data migration cockpit. In both cases I used the standard template provided by the migration tool.
– Load customers with data migration cockpit:
– Load inventory balance with data migration cockpit
This time I am going to show how to add custom fields to a master data object like materials and how to proceed so we can load this extra data with the data migration cockpit.
The Migration object modeler (transaction LTMOM) is used to create your own customer-specific migration objects or add SAP standard objects that are not yet included in the migration cockpit. LTMOM can also be used to adjust the SAP standard migration objects delivered with the cockpit by adding custom fields.
Summary of steps to add custom fields to material master
1. Add custom fields to table MARA using an append (transaction SE11)
2. Enhance BAPI structures to include new custom fields (transaction SE11).
3. Assign field group to the new fields (transaction OMSR)
4. Adjust source structure for material migration object (transaction LTMOM)
5. Map new fields to the Extension structures for material (transaction LTMOM)
- Add custom code to assign the values of new custom fields to extension structures (transaction LTMOM)
- Add structure mapping for extension structures (transaction LTMOM).
6. Save and generate the migration object
7. Download adjusted template with data migration cockpit (transaction LTMC)
8. Migrate your data with data migration cockpit using new file structure that includes custom fields (transaction LTMC)
Enhance table MARA and BAPI structures
With transaction SE11 we can add new fields to table MARA (and eventually to MARC, …) creating one append. I add 3 fields used in the client previous ECC6 version.
Going to transaction LTMOM (data migration modeller), if I double-click on the Target structure I can see the the BAPI used for the data load for materials.
We need to pass the SAP standard delivered structure to upload the customer-defined material master fields (BAPI_TE_E1MARA, BAPI_TE_E1MARAX), which should be enhanced in the same way as MARA table as shown below:
In case we would have added custom fields to table MARC then we would need to do same process for structures BAPI_TE_E1MARC, BAPI_TE_E1MARCX.
Assign field group to the new fields
Another step is to assign field selection group to the new fields. Please check it out in T-code OMSR. Otherwise fields data will not be transferred to database.
This will be used for all material types.
Adjust source structure for material migration object (transaction LTMOM)
To make changes to the object we use transaction LTMOM, selecting the object we are going to use for the data migration (pressing F4 we find all projects and objects).
Press F4 and select the object for materials in my project, in this particular case “Material”:
Then we can display/change the function module used by LTMC as also add code, map structures, etc. These are main options in the menu:
Adjust source structure of Migration Objects. Add fields listed below to source structure S_MARA.
If we had added fields to MARC table we would need to do the same for structure S_MARC.
Add custom code to assign the values of new custom fields to extension structures (transaction LTMOM)
In order to assign the values of custom fields to the extension structures it is necessary to add some custom code.
To know the target structures names we can click in each of them.
In the field mapping we can see where to create code to add conversion logic.
To know which structures, variables and functions to use in the coding, let’s have a look at the target work areas available in the program generated by LTMC.
And source areas:
Now I proceed to add the code for the conversion rules. Double click in BOR_S_MARA in field mapping:
Here it is some pre-existing code, which can be enhanced manually.
Add the following code from the point indicated above.
******************************************************** * NEW CODE FOR Z FIELDS in MARA ******************************************************** DATA: lv_e1mara TYPE bapi_te_e1mara, lv_e1marax TYPE bapi_te_e1marax. *----------------------------------------------------------------- * assign values to structure T28_EXTENSIONIN *----------------------------------------------------------------- * check Z fields are filled with value IF _wa_s_mara-zzmanuf IS NOT INITIAL OR _wa_s_mara-zzmanuf_nr IS NOT INITIAL OR _wa_s_mara-zzoldmat IS NOT INITIAL. CLEAR: _wa_t28_extensionin, lv_e1mara. PERFORM _rule_move_op USING _wa_t28_extensionin-_parentrecno _wa_s_mara-_recno. PERFORM _rule_move_op USING _wa_t28_extensionin-material _wa_s_mara-matnr. PERFORM _rule_move_op USING _wa_t28_extensionin-structure 'BAPI_TE_E1MARA'. lv_e1mara-material = _wa_s_mara-matnr. lv_e1mara-zzmanuf = _wa_s_mara-zzmanuf. lv_e1mara-zzmanuf_nr = _wa_s_mara-zzmanuf_nr. lv_e1mara-zzoldmat = _wa_s_mara-zzoldmat. PERFORM _rule_move_op USING _wa_t28_extensionin-valuepart1 lv_e1mara. * Pseudocode to assign values and add entry in internal table IT_t28_extensionin. mwb:r_data_write( [t28_extensionin] [_wa_t28_extensionin] ). *------------------------------------------------------------------- * assign values to structure T29_EXTENSIONINX *------------------------------------------------------------------- CLEAR _wa_t29_extensioninx. PERFORM _rule_move_op USING _wa_t29_extensioninx-_parentrecno _wa_s_mara-_recno. PERFORM _rule_move_op USING _wa_t29_extensioninx-material _wa_s_mara-matnr. PERFORM _rule_move_op USING _wa_t29_extensioninx-structure 'BAPI_TE_E1MARAX'. lv_e1marax-material = _wa_s_mara-matnr. IF _wa_s_mara-zzmanuf NE space. MOVE 'X' TO lv_e1marax-zzmanuf. ENDIF. IF _wa_s_mara-zzmanuf_nr NE space. MOVE 'X' TO lv_e1marax-zzmanuf_nr. ENDIF. IF _wa_s_mara-zzoldmat NE space. MOVE 'X' TO lv_e1marax-zzoldmat. ENDIF. MOVE lv_e1marax TO _wa_t29_extensioninx-valuepart1. * Pseudocode to assign values and add entry in internal table IT_t29_extensioninx mwb:r_data_write( [t29_extensioninx] [_wa_t29_extensioninx] ). ENDIF.
As info, we can see how the code for function “_rule_move_op” looks like. This is generated with the program being an standard LTMC function.
Here we have the other function used “mwb:r_data_write”, using a pseudocode that is automatically replaced during the program generation.
Add structure mapping for extension structures.
In this step I assign the source structure S_MARA to target extension structures, specifying the mapping type.
Here for T28_EXTENSIONIN. Just need to double click in this structure to add the mapping rule.
There are different mapping types. It can be 1:1, that would mean that for each line of S_MARA there will be one line for T28_EXTENSIONIN. As this only happens when the custom fields are filled, we will use mapping type “split” with target 0 in case fields are empty.
And the same for the T29_EXTENSIONINX.
Save and generate project.
Now I can save and generate the migration object.
it takes some time to generate the function module with the new code and changes.
Download adjusted template with data migration cockpit (transaction LTMC)
It is possible to download the load template with the corresponding button in LTMOM or directly in LTMC (please see my other blogs with instructions).
In the new template it is possible to see the custom added fields.
Migrate your data with data migration cockpit using new file structure that includes custom fields (transaction LTMC)
Now I can fill the load file with the needed data, including the 3 custom fields that are now available.
Once all load steps are done we can see the new materials created with the custom fields filled in table MARA using transaction SE16N:
Simulate import/data conversion in LTMOM
Data migration modeller offers a tool to simulate the import of the file we will load with LTMC. To access to it click on the “simulate” button in the menu.
It is possible to debug the function module while converting the data as also see the records before and after the conversion.
Unfortunately, the log is not as detailed as it used to be with LSMW.
Data migration modeler is the tool to enhance the current LTMC objects, which all are based in function modules that can be modified. With LTMOM you can do almost as much as with LSMW, in which we had instructions like skip_record, skip_transaction, … As inconvenience against LSMW, LTMC has not a clear log display after reading and conversion.
A small quiz, in order to accomodate those new custom fields in addition to standard structure (sender/receiver), have we also adjusted the BAPI implementation so that custom field values can be brought into?
nice Job Fernando.
For me the most dificult part is this one: "Enhance BAPI structures to include new custom fields)
I want to do the same you did, but for equipments instead of materials.
How do I find the structure for my z-fields in function module: DMC_MIG_EQUIPMENT ??
That function module is the ones for the migration object equipment.
Thank you very much.
This post is nice. The direction is cool but the state of LTMC is for me a shame. Tries to hide real backend data from customer and makes error analysing difficult. Locks are not set properly, we had a terrible (yet simple) case yesterday, when it led to a disaster and false results. Thus the stability is for me questionable. I thought nice overhead for a BAPI with less chance for success than LSMW, ALE. What about Transparency? When numerous mappings are entered, limiting insight in 1000 records is far below optimal.