SAP ERP doesn’t directly capture the country of origin during a MIGO goods receipt for a newly created batch. However, you can achieve this through implementing a User Exit.
Additional batch data, such as the country of origin, region of origin, and freely available date fields, can be changed only in user exits. To create a new batch for the goods movement, use the exit EXIT_SAPMM07M_003.
MCHA-HERKL is not automatically updated based on the purchase order during a goods receipt. You must use user exit EXIT_SAPMM07M_003
The user-exit EXIT_SAPMM07M_003 is in
Enhancement: “MBCFC003” – Maintenance of batch master data for goods movements”
(Use transaction: CMOD to activate the exit and assign enhancement).
Question: Why is the user exit EXIT_SAPMM07M_003 processed for some batches but not for others?
Answer: The user exit EXIT_SAPMM07M_003 is processed only if the batch is newly created by the goods movement. This may have different consequences depending on the batch definition level.
To determine the country of origin (CoO) you can use proper setup of segmentation field. Documentation here:
SAP docs on segmentation functionality:
Segmentation (LO_SEGMENTATION) is a new SAP ERP component, integrated into:
- LO Material Master
- SD Sales
- MM Purchasing
SGT_CATS – ABAP table: Segmentation Structure Fields Table
SGT_CSEGSCON – ABAP table with segmentation rules defined
SGT_VALS – ABAP table with Segmentation-Valid Combinations
ABAP code to read material segmentation customizing and split the segmentation value into segments:
REPORT ztest3. DATA: lv_csgr TYPE mara-sgt_csgr, lt_CATS TYPE TABLE OF sgt_cats, lv_seg type SGT_SCAT value '12300001 DE001', lv_val type char20 . SELECT SINGLE sgt_csgr FROM mara INTO lv_csgr WHERE matnr = 'MAT8_15'. *-----Read table SGT_CATS CALL FUNCTION 'SGTV_CATS_READ' EXPORTING iv_csgr = lv_csgr iv_appl = 'S' TABLES e_cats_tab = lt_cats EXCEPTIONS invalid_key = 1 not_found = 2 OTHERS = 3. IF sy-subrc <> 0. WRITE: / 'internal_error'. EXIT. ENDIF. SORT lt_cats BY sgt_cnrc. LOOP AT lt_cats ASSIGNING FIELD-SYMBOL(<fs>). SKIP 1. WRITE: / 'SGT_CSGR', <fs>-sgt_csgr . " Segmentation Structure = GRPE WRITE: / 'SGT_APPL', <fs>-sgt_appl . " Segmentation Type = S - Supply WRITE: / 'SGT_CNRC', <fs>-sgt_cnrc . " Consecutive Number of Segmentation Field = 021 - WRITE: / 'ATINN', <fs>-atinn . " Characteristic for Segmentation Structure = ZZ01 WRITE: / 'SGT_FNAM', <fs>-sgt_fnam . " Name for Segmentation Structure Field = ZZ01 WRITE: / 'SGT_RANK', <fs>-sgt_rank . "Rank of Segmentation Field (in Rule Combination) position/rank = 002 WRITE: / 'SGT_FOFF', <fs>-sgt_foff . "Offset of Field in Segment, offset = 011 (external length offset) WRITE: / 'SGT_FLEN', <fs>-sgt_flen . "Length of a Field in Segmentation, length = 002 WRITE: / 'SGT_INVA', <fs>-sgt_inva . WRITE: / 'SGT_REFT', <fs>-sgt_reft . WRITE: / 'SGT_REFF', <fs>-sgt_reff . WRITE: / 'SGT_REIT', <fs>-sgt_reit . WRITE: / 'SGT_REIF', <fs>-sgt_reif . WRITE: / 'SGT_BWEF', <fs>-sgt_bwef . WRITE: / 'SGT_BWTMARK', <fs>-sgt_bwtmark . WRITE: / 'SGT_CHEF', <fs>-sgt_chef . WRITE: / 'SGT_EANF', <fs>-sgt_eanf . lv_val = lv_seg+<fs>-sgt_foff(<fs>-sgt_flen). " get segment value write: / lv_seg, <fs>-sgt_rank, ' -> ', lv_val. ENDLOOP.
Other useful classes for Segmentation functionality in recent SAP ERP S4 HANA:
Class: CL_SGT_DETERMINE
Method: DETERMINE_REQ_SEGMENT
cl_sgt_default_determination=>get_default_segment
CL_SGT_MATERIAL_MASTER
CL_SGT_UTIL
Method: CHECK_SEGMENT_USED
User-exit to set country of origin in batch (MCHA-HERKL) via user-exit:
FUNCTION EXIT_SAPMM07M_003. *"---------------------------------------------------------------------- *"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_MATNR) LIKE MARA-MATNR *" VALUE(I_CHARG) LIKE MCH1-CHARG *" VALUE(I_WERKS) LIKE MCHA-WERKS OPTIONAL *" VALUE(I_MSEG) LIKE MSEG STRUCTURE MSEG *" VALUE(I_VM07M) LIKE VM07M STRUCTURE VM07M *" VALUE(I_DM07M) LIKE DM07M STRUCTURE DM07M *" VALUE(I_MKPF) LIKE MKPF STRUCTURE MKPF *" CHANGING *" VALUE(BATCH_MASTER_DATA) LIKE MBCFC003 *" STRUCTURE MBCFC003 *"---------------------------------------------------------------------- INCLUDE ZXMBCU03. ENDFUNCTION.
and you put your ABAP code in the activated user-exit’s INCLUDE as follow (simple example! You can write more complex logic using the above reading of Segmentation customizing and not like below fixed offset and position!):
if i_mseg-sgt_scat is not INITIAL. BATCH_MASTER_DATA-herkl = I_MSEG-SGT_SCAT+10(2). endif.