最近研究了一下,一般物料创建后内外码都是一样的,但是我想内外码变成不一样的,外码用自己的,内码是SAP系统的
MM01创建的时候,发现有个旧物料号,我想可以用这个来做文章
SE18找到 BADI_MATN1这个增强BADI,创建想对应的增强实施
新建一个表
新建一个结构
新建一个表类型
创建完增强实施后, 会自动生成一个类,双击这个类
增加一个属性
然后在增强的方法里面写相对应的程序
MATN1_INPUT_001 跟 MATN1_INPUT_002 是输入外码的时候自动转内码查询
MATN1_OUTPUT_001 跟 MATN1_OUTPUT_002 是用外部号赋值
DATA: ls_mm001 TYPE ztmm001.
CLEAR ls_mm001.
IF matnr IS NOT INITIAL.
SELECT SINGLE matnr INTO CORRESPONDING FIELDS OF ls_mm001
FROM mara
WHERE bismt = matnr.
IF ls_mm001-matnr IS NOT INITIAL.
matnr = ls_mm001-matnr.
RAISE ignore_rest.
ENDIF.
ENDIF.
DATA: ls_mm001 TYPE ztmm001.
CLEAR ls_mm001.
IF matnr IS NOT INITIAL.
SELECT SINGLE matnr INTO CORRESPONDING FIELDS OF ls_mm001
FROM mara
WHERE bismt = matnr_orig.
IF ls_mm001-matnr IS NOT INITIAL.
matnr = ls_mm001-matnr.
ENDIF.
ENDIF.
DATA: ls_mm001 TYPE zsmatnr_extr.
CLEAR ls_mm001.
IF matnr IS NOT INITIAL.
READ TABLE zcl_im_badi_matn1=>at_matnr
INTO ls_mm001
WITH KEY matnr = matnr
BINARY SEARCH.
IF ls_mm001-matnrext IS INITIAL.
ls_mm001-matnr = matnr.
SELECT SINGLE bismt AS matnrext INTO CORRESPONDING FIELDS OF ls_mm001
FROM mara
WHERE matnr = ls_mm001-matnr.
IF ls_mm001-matnrext IS NOT INITIAL.
APPEND ls_mm001 TO zcl_im_badi_matn1=>at_matnr .
SORT zcl_im_badi_matn1=>at_matnr BY matnr.
matnr = ls_mm001-matnrext.
RAISE ignore_rest.
ENDIF.
ELSE.
matnr = ls_mm001-matnrext.
RAISE ignore_rest.
ENDIF.
ENDIF.
DATA: ls_mm001 TYPE zsmatnr_extr.
CLEAR ls_mm001.
IF matnr IS NOT INITIAL.
READ TABLE zcl_im_badi_matn1=>at_matnr
INTO ls_mm001
WITH KEY matnr = matnr_orig
BINARY SEARCH.
IF ls_mm001-matnrext IS INITIAL.
SELECT SINGLE bismt AS matnrext INTO CORRESPONDING FIELDS OF ls_mm001
FROM mara
WHERE matnr = matnr_orig.
IF ls_mm001-matnrext IS NOT INITIAL.
matnr = ls_mm001-matnrext.
ls_mm001-matnr = matnr_orig.
APPEND ls_mm001 TO zcl_im_badi_matn1=>at_matnr .
SORT zcl_im_badi_matn1=>at_matnr BY matnr.
ENDIF.
ELSE.
matnr = ls_mm001-matnrext.
ENDIF.
ENDIF.
然后去创建物料,内外码就不一样了