Technical Articles
How to migrate materials with user fields using the Migration Cockpit
In this blog post you will learn how to adjust Material migration object in order to populate customer basic and plant data. It could be used as “cooking receipt” for other material enhancements migration or even for the other object using the same BAPI capabilities. Same approach could be used for some other migration objects such as Sales Order or FI – G/L account balance and open/line item.
BAPI_MATERIAL_SAVEREPLICA is used for Material migration. In case Material Master data was enhanced to fulfill customer needs corresponding Migration Cockpit migration object should be adjusted accordantly. BAPI_MATERIAL_SAVEREPLICA is used. Parameters EXTENSIONIN and EXTENSIONINX are used for transferring customer data. Detailed description is available on FM documentation. MARA, MARC, MARD, MBEW, MLGN, MLGT, MVKE, MARM, MAKT customer data could be transferred via extension structures. Steps below show basic concept of z-field migration.
The customer has added their own fields to tables MARA and MARC using APPEND structures.
Table | Field Name | Data Type |
MARA | ZZ_FIELD_A1 | CHAR 10 |
MARA | ZZ_FIELD_A2 | CHAR 10 |
MARC | ZZ_FIELD_C1 | CHAR 4 |
MARC | ZZ_FIELD_C2 | CHAR 3 |
The customer also requires that fields could be migrated with Migration Cockpit.
- Make sure field selection group is assigned to new fields. Please check it out in T-code OMSR. Otherwise fields data will not be transferred to database.
- Structures below should be enhanced in the same way as MARA and MARC table
Structure | Component | Component Type | Data Type | Length | Short Description |
BAPI_TE_E1MARA | ZZ_FIELD_A1 | CHAR | 10 | Field1 | |
ZZ_FIELD_A2 | CHAR | 10 | Field2 | ||
BAPI_TE_E1MARAX | ZZ_FIELD_A1 | BAPIUPDATE | CHAR | 1 | Updated information in related user data field |
ZZ_FIELD_A2 | BAPIUPDATE | CHAR | 1 | Updated information in related user data field | |
BAPI_TE_E1MARC
|
ZZ_FIELD_C1 | Field3 | |||
ZZ_FIELD_C2 | Field4 | ||||
BAPI_TE_E1MARCX | ZZ_FIELD_C1 | BAPIUPDATE | CHAR | 1 | Updated information in related user data field |
ZZ_FIELD_C2 | BAPIUPDATE | CHAR | 1 | Updated information in related user data field |
- Create new Migration Project with t-code LTMC.
Double click on Material Object and copy it to the migration project.
- Open Migration Object Material with t-code LTMOM Migration Object Modeler.
- Adjust source structure of Migration Objects. Add fields listed below to S_MARA.
Name | Data Type | Length | Decimal Places | Amount Field | Column Header | Group Text |
ZZ_FIELD_A1 | CHAR | 10 | 0 | Field1 | Additional fields | |
ZZ_FIELD_A2 | CHAR | 10 | 0 | Field2 | Additional fields |
- Add fields listed below to S_MARC source structure.
Name | Data Type | Length | Decimal Places | Amount Field | Column Header | Group Text |
ZZ_FIELD_C1 | CHAR | 4 | 0 | Field_C1 | Additional fields | |
ZZ_FIELD_C2 | CHAR | 3 | Field_C2 | Additional fields |
- Now we can activate object and download updated template. Added fields arear at the end of sheets Basic Data and Plant Data.
It’s not possible to simply map each new field due there is no dedicated elements in source structure. Example below show populated Extension* structures for MAT1 material.
T28_EXTENSIONIN Ref. Structure for BAPI Parameters EXTENSIONIN/EXTENSIONOUT | ||||
Row | Function [C(3)] | Material [C(18)] | Structure [C(30)] | Valuepart1 [(240)] |
1 | MAT1 | BAPI_TE_E1MARA | MAT1 1 2 | |
2 | MAT1 | BAPI_TE_E1MARC | MAT1 10003 4 |
T29_EXTENSIONINX Checkbox Structure for Extension In/Extension Out | ||||
Row | Function [C(3)] | Material [C(18)] | Structure [C(30)] | Valuepart1 [(240)] |
1 | MAT1 | BAPI_TE_E1MARA | MAT1 XX | |
2 | MAT1 | BAPI_TE_E1MARC | MAT1 1000XX |
Next topics describe how to adjust object accordingly.
- Change subproject event-based rule BOR_S_MARA. Put ABAP code below to the end of rule after lines
existing
* RETURN. “leave processing
ENDIF.
Add code:
data: lv_e1mara TYPE BAPI_TE_E1MARA,
lv_e1marax TYPE BAPI_TE_E1MARAX.
* check Z fields are populated
IF _wa_s_mara-zz_field_a1 IS NOT INITIAL
or _wa_s_mara-zz_field_a2 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-zz_field_a1 = _wa_s_mara-zz_field_a1.
lv_e1mara-zz_field_a1 = _wa_s_mara-zz_field_a1.
PERFORM _rule_move_op
USING
_wa_t28_extensionin-valuepart1
lv_e1mara.
mwb:r_data_write(
[t28_extensionin]
[_wa_t28_extensionin]
).
*------------------------------------------------
* we also have to provide 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-zz_field_a1 NE space.
MOVE 'X' TO lv_e1marax-zz_field_a1.
ENDIF.
IF _wa_s_mara-zz_field_a2 NE space.
MOVE 'X' TO lv_e1marax-zz_field_a2.
ENDIF.
MOVE lv_e1marax to _wa_t29_extensioninx-valuepart1.
mwb:r_data_write(
[t29_extensioninx]
[_wa_t29_extensioninx]
).
ENDIF.
- Create subproject event-based rule ZBOR_S_MARC. Put ABAP code below.
"MARC Z fields handling
data: lv_e1marc TYPE BAPI_TE_E1MARC,
lv_e1marcx TYPE BAPI_TE_E1MARCX,
lv_valuepart TYPE string.
* check if marc Z fields are populated
IF _wa_s_marc-zz_field_c1 IS NOT INITIAL
or _wa_s_marc-zz_field_c2 IS NOT INITIAL.
CLEAR: _wa_t28_extensionin,
lv_e1marc.
PERFORM _rule_move_op
USING
_wa_t28_extensionin-_parentrecno
_wa_s_marc-_recno.
PERFORM _rule_move_op
USING
_wa_t28_extensionin-material
_wa_s_marc-matnr.
PERFORM _rule_move_op
USING
_wa_t28_extensionin-structure
'BAPI_TE_E1MARC'.
lv_e1marc-material = _wa_s_marc-matnr.
lv_e1marc-plant = _wa_s_marc-werks.
lv_e1marc-zz_field_c1 = _wa_s_marc-zz_field_c1.
lv_e1marc-zz_field_c2 = _wa_s_marc-zz_field_c2.
PERFORM _rule_move_op
USING
_wa_t28_extensionin-valuepart1
lv_e1marc.
mwb:r_data_write(
[t28_extensionin]
[_wa_t28_extensionin]
).
*------------------------------------------------
* we also have to provide T29_EXTENSIONINX
*------------------------------------------------
CLEAR _wa_t29_extensioninx.
PERFORM _rule_move_op
USING
_wa_t29_extensioninx-_parentrecno
_wa_s_marc-_recno.
PERFORM _rule_move_op
USING
_wa_t29_extensioninx-material
_wa_s_marc-matnr.
PERFORM _rule_move_op
USING
_wa_t29_extensioninx-structure
'BAPI_TE_E1MARCX'.
lv_e1marcx-material = _wa_s_marc-matnr.
lv_e1marcx-plant = _wa_s_marc-werks.
IF _wa_s_marc-zz_field_c1 NE space.
MOVE 'X' TO lv_e1marcx-zz_field_c1.
ENDIF.
IF _wa_s_marc-zz_field_c2 NE space.
MOVE 'X' TO lv_e1marcx-zz_field_c2.
ENDIF.
MOVE lv_e1marcx to _wa_t29_extensioninx-valuepart1.
mwb:r_data_write(
[t29_extensioninx]
[_wa_t29_extensioninx]
).
ENDIF.
- Set up structure mapping.
Target Structure T28_EXTENSIONIN
Description Ref. Structure for BAPI Parameters EXTENSIONIN/EXTENSIONOUT
Source Structure | Description | Access Type | Mapping Type | Source Cardinality | Target Cardinality | Data Path Type |
S_MARA | Basic Data | Mapping only | Split | 1 | 0 | Not Applicable |
S_MARC | Plant Data | Mapping only | Split | 1 | 0 | Not Applicable |
Target Structure T29_EXTENSIONINX
Description Checkbox Structure for Extension In/Extension Out
Source Structure | Description | Access Type | Mapping Type | Source Cardinality | Target Cardinality | Data Path Type |
S_MARA | Basic Data | Mapping only | Split | 1 | 0 | Not Applicable |
S_MARC | Plant Data | Mapping only | Split | 1 | 0 | Not Applicable |
- Adjust field mapping
Add ZBOR_S_MARC rule to Start of Record (Material Data at Plant Level)
- Save and generate project.
- Go to LTMC T-code and migrate your data.
Thereby we have prepared Material Master Migration Cockpit object which can migrate Z fields. I hope this example will be useful for adjustment migration object in order to transfer customer specific data .
Hi,
Excellent blog, many thanks!
Just a quick fix, in the ABAP code for the rule ZBOR_S_MARC, replace in the block
lv_e1marc-zm_dualuse_mat with lv_e1marc-zz_field_c1 and lv_e1marc-zmm_alno with lv_e1marc-zz_field_c2.
At the end of this, add also a line to move lv_e1marcx to to _wa_t29_extionsinx-valuepart1.
Thanks again, cheers,
Pierre
Hi Pierre.
Thank you for valuable feedback. Code was fixed. Thanks!
Br,
Alexey.
Hi Alexey,
really glad for this blog post. I was adapting your steps for a different migration object and it helped me a lot 🙂
One question though.
In the step where you are telling to:
I see that in your screenshot there are 2 Start of Record events. But when i checked in my system there is only one, see my screenshot below. How did you manage to create there the additional event?
The reason why i am asking this is, that in my case for my migration object i have also one Start-of-Record event that has already some Post Load Validation rule PLV_BOR. And when i am assigning my new Z_rule for extensionIN, the original rule is being replaced. And i am just not sure if that is fine or not as i see two Start-of-Record events in your case.
Thx for reply.
Tom
Hello Tomas.
Thanks for comment. I did nothing to have second event or it was created accidentally. Unfortunately I do not know how create new event. I suggest to keep your PVL_BOR rule and just add ABAP code inside PVL_BOR. It would be the same as for BOR_S_MARA.
Br,
Alexey.
Hi Alexey,
firts of all thank you very much for this very useful tutorial.
I’m triyng to add some MARA custom field as well some MARC custom field as in your tutorial.
I completed many steps but I’m stucking on this issue when I try to set up the structure mapping for T28_EXTENSIONIN and T_29_EXTENSIONIN with both S_MARA and S_MARC with the same mapping type “Split” as you showed above.
System raise the following error message: “For target structure T28_EXTESIONIN, the mapping type ‘ Split ‘ occurs more thank once” -> are you sure that the mapping is correct?
Or maybe I can use the following one?
Thanks in advance,
Regards
Francesco
Hello Francesco.
I am not sure but please try to set S_MARA in the first row like on my picture.
Br,
Alexey.
Hello Francesco Tombolini,
I am also facing the same issue, can you let me know how you have resolved the same.
Thanks in advance!
Regards
Bharath