使用ME_INFORECORD_MAINTAIN_MULTI函数进行采购信息记录及条件记录的创建以及更新,单独进行条件价格信息的创建及变更可以参照下面我的另一个帖子:
2024.08.01更新,记录一位朋友遇到的问题,S4CORE 105版本的一个BUG,S4CORE 106版本以上没有这个问题,朋友最终找到了标准的note来解决,分享一下帮大家避雷。
症状:创建采购信息记录时INFNR流水码会+2导致更新异常,异常信息如下,ME 807。
问题代码位置:
左侧为106版本,右侧为105版本,差异代码程序名:LMEIIF01,Form名:buchen
解决note:
根据Note:3312881中的修正方案,实施Note:3022031即可解决。
**********************************************************************
* 创建者: HAND05
* 接口描述:采购信息记录维护接口
* 创建日期:2022.04.15
**********************************************************************
FUNCTION ZIF_OA2RFC_MM_0004.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IT_INFORECORD) TYPE ZTMM_0004_ME11_I
*" EXPORTING
*" VALUE(EV_TYPE) TYPE BAPI_MTYPE
*" VALUE(EV_MESSAGE) TYPE BAPI_MSG
*" VALUE(ET_RETURN) TYPE ZTMM_0004_RETURN_E
*"----------------------------------------------------------------------
* 逻辑处理参数
DATA:
LV_MEINS TYPE MEINS,
LS_INFORECORD TYPE ZSMM_0004_ME11_I,
LS_RETURN_E TYPE ZSMM_0004_RETURN_E,
LV_MESSAGE TYPE BAPI_MSG.
* BAPI创建参数
DATA:
LT_EINA TYPE MEWIEINA_MIG_T, "一般数据
LS_EINA TYPE MEWIEINA_MIG, "一般数据
LT_EINAX TYPE MEWIEINAX_T,
LS_EINAX TYPE MEWIEINAX_TY,
LT_EINE TYPE MEWIEINE_T, "采购组织数据
LS_EINE TYPE MEWIEINE_TY, "采购组织数据
LT_EINEX TYPE MEWIEINEX_T,
LS_EINEX TYPE MEWIEINEX_TY,
LT_COND_VALIDITY TYPE MEWIVALIDITY_TT, "条件有效期
LS_COND_VALIDITY TYPE MEWIVALIDITY_TY, "条件有效期
LT_CONDITION TYPE MEWICONDITION_TT, "条件明细
LS_CONDITION TYPE MEWICONDITION_TY, "条件明细
LT_EINA_E TYPE MEWIEINA_MIG_T, "创建返回-一般数据
LT_EINE_E TYPE MEWIEINE_T, "创建返回-采购组织数据
LT_RETURN TYPE FS4MIG_T_BAPIRET2. "创建返回消息
* 获取物料单位
SELECT A~MATNR, "物料号
B~WERKS, "工厂
A~MEINS, "基本单位
A~BSTME, "采购单位
B~PLIFZ "计划交货时间(天)
INTO TABLE @DATA(LT_MARA)
FROM MARA AS A
INNER JOIN MARC AS B
ON A~MATNR = B~MATNR
FOR ALL ENTRIES IN @IT_INFORECORD
WHERE A~MATNR = @IT_INFORECORD-MATNR
AND B~WERKS = @IT_INFORECORD-WERKS.
* 获取历史采购信息记录
SELECT A~INFNR,
A~MATNR, "物料
A~LIFNR, "供应商
B~EKORG, "采购组织
B~ESOKZ, "信息类别
B~WERKS "工厂
INTO TABLE @DATA(LT_INFOREC_OLD)
FROM EINA AS A
INNER JOIN EINE AS B
ON A~INFNR = B~INFNR
FOR ALL ENTRIES IN @IT_INFORECORD
WHERE A~MATNR = @IT_INFORECORD-MATNR
AND A~LIFNR = @IT_INFORECORD-LIFNR
AND B~EKORG = @IT_INFORECORD-EKORG
AND B~ESOKZ = @IT_INFORECORD-ESOKZ
AND B~WERKS = @IT_INFORECORD-WERKS.
* 获取历史条件价格信息
SELECT A~LIFNR, "供应商
A~MATNR, "物料
A~EKORG, "采购组织
A~WERKS, "工厂
A~ESOKZ, "信息类型
A~DATAB, "有效期自
A~DATBI, "有效期至
A~KNUMH, "条件记录编号
B~KOPOS "条件序列号
INTO TABLE @DATA(LT_A017)
FROM A017 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
FOR ALL ENTRIES IN @IT_INFORECORD
WHERE A~MATNR = @IT_INFORECORD-MATNR
AND A~LIFNR = @IT_INFORECORD-LIFNR
AND A~EKORG = @IT_INFORECORD-EKORG
AND A~ESOKZ = @IT_INFORECORD-ESOKZ
AND A~WERKS = @IT_INFORECORD-WERKS
AND A~DATAB = @IT_INFORECORD-DATAB
AND A~DATBI = @IT_INFORECORD-DATBI.
SORT LT_MARA BY MATNR ASCENDING
WERKS ASCENDING.
SORT LT_INFOREC_OLD BY MATNR ASCENDING
LIFNR ASCENDING
EKORG ASCENDING
ESOKZ ASCENDING
WERKS ASCENDING.
SORT LT_A017 BY LIFNR ASCENDING
MATNR ASCENDING
EKORG ASCENDING
WERKS ASCENDING
ESOKZ ASCENDING
DATAB ASCENDING
DATBI ASCENDING.
LOOP AT IT_INFORECORD INTO LS_INFORECORD.
READ TABLE LT_MARA INTO DATA(LS_MARA)
WITH KEY MATNR = LS_INFORECORD-MATNR
BINARY SEARCH.
IF SY-SUBRC = 0.
IF LS_MARA-BSTME IS NOT INITIAL.
LV_MEINS = LS_MARA-BSTME.
ELSE.
LV_MEINS = LS_MARA-MEINS.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
INPUT = LS_INFORECORD-BPRME
LANGUAGE = SY-LANGU
IMPORTING
OUTPUT = LS_INFORECORD-BPRME
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2.
IF LS_INFORECORD-BPRME <> LV_MEINS.
EV_TYPE = 'E'.
LS_RETURN_E-TYPE = 'E'.
* 物料&1的价格单位为&2,请修正导入数据单位!
MESSAGE E013(ZMSG01) WITH LS_INFORECORD-MATNR
LV_MEINS
INTO LV_MESSAGE.
LS_RETURN_E-MESSAGE = LV_MESSAGE.
ENDIF.
IF LS_INFORECORD-WERKS IS NOT INITIAL.
READ TABLE LT_MARA INTO LS_MARA
WITH KEY MATNR = LS_INFORECORD-MATNR
WERKS = LS_INFORECORD-WERKS
BINARY SEARCH.
IF SY-SUBRC = 0.
IF LS_MARA-PLIFZ IS INITIAL.
EV_TYPE = 'E'.
LS_RETURN_E-TYPE = 'E'.
* 物料&1计划交货时间未维护,请联系资材部!
MESSAGE E015(ZMSG01) WITH LS_INFORECORD-MATNR
INTO LV_MESSAGE.
LS_RETURN_E-MESSAGE = LS_RETURN_E-MESSAGE && LV_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
* 判断是否存在历史采购信息记录
READ TABLE LT_INFOREC_OLD INTO DATA(LS_INFOREC_OLD)
WITH KEY MATNR = LS_INFORECORD-MATNR
LIFNR = LS_INFORECORD-LIFNR
EKORG = LS_INFORECORD-EKORG
ESOKZ = LS_INFORECORD-ESOKZ
WERKS = LS_INFORECORD-WERKS
BINARY SEARCH.
* 存在记录
IF SY-SUBRC = 0.
IF LS_INFORECORD-ZSTATUS = 'V' OR "V:校验
LS_INFORECORD-ZSTATUS = 'C'. "C:创建
EV_TYPE = 'E'.
LS_RETURN_E-TYPE = 'E'.
* 采购信息记录已存在!
MESSAGE E207(ZMSG01) INTO LV_MESSAGE.
LS_RETURN_E-MESSAGE = LS_RETURN_E-MESSAGE && LV_MESSAGE.
ENDIF.
ELSE.
IF LS_INFORECORD-ZSTATUS = 'U'. "U:更新
EV_TYPE = 'E'.
LS_RETURN_E-TYPE = 'E'.
* 采购信息记录不存在!
MESSAGE E208(ZMSG01) INTO LV_MESSAGE.
LS_RETURN_E-MESSAGE = LS_RETURN_E-MESSAGE && LV_MESSAGE.
ENDIF.
ENDIF.
IF EV_TYPE <> 'E'.
READ TABLE LT_A017 INTO DATA(LS_A017)
WITH KEY LIFNR = LS_INFORECORD-LIFNR
MATNR = LS_INFORECORD-MATNR
EKORG = LS_INFORECORD-EKORG
WERKS = LS_INFORECORD-WERKS
ESOKZ = LS_INFORECORD-ESOKZ
DATAB = LS_INFORECORD-DATAB
DATBI = LS_INFORECORD-DATBI
BINARY SEARCH.
* 更新-基本数据
LS_EINA-INFO_REC = LS_INFOREC_OLD-INFNR. "采购信息记录编号
LS_EINAX-INFO_RECN = LS_INFOREC_OLD-INFNR. "采购信息记录编号
* 更新-采购数据
LS_EINE-INFO_REC = LS_INFOREC_OLD-INFNR. "采购信息记录编号
LS_EINEX-INFO_RECN = LS_INFOREC_OLD-INFNR. "采购信息记录编号
* 更新-条件价格有效期
LS_COND_VALIDITY-INFO_REC = LS_INFOREC_OLD-INFNR. "采购信息记录编号
LS_COND_VALIDITY-SERIAL_ID = LS_A017-KNUMH. "条件记录编号
* 更新-条件价格信息
LS_CONDITION-INFO_REC = LS_INFOREC_OLD-INFNR. "采购信息记录编号
LS_CONDITION-SERIAL_ID = LS_A017-KNUMH. "条件记录编号
LS_CONDITION-COND_COUNT = LS_A017-KOPOS. "条件序列号
* 条件价格信息更新标识
IF LS_A017-KNUMH IS NOT INITIAL.
LS_CONDITION-CHANGE_ID = 'U'.
ENDIF.
* 创建&更新-基本数据
LS_EINA-MATERIAL = LS_INFORECORD-MATNR. "物料号
LS_EINA-VENDOR = |{ LS_INFORECORD-LIFNR ALPHA = IN }|. "供应商
APPEND LS_EINA TO LT_EINA.
LS_EINAX-MATERIAL = 'X'.
LS_EINAX-VENDOR = 'X'.
APPEND LS_EINAX TO LT_EINAX.
* 创建&更新-采购数据
LS_EINE-EINE_INDX = '01'. "顺序编号
LS_EINE-PURCH_ORG = LS_INFORECORD-EKORG. "采购组织
LS_EINE-PLND_DELRY = LS_MARA-PLIFZ. "计划交货时间(天)
LS_EINE-INFO_TYPE = LS_INFORECORD-ESOKZ. "采购信息记录分类
LS_EINE-PLANT = LS_INFORECORD-WERKS. "工厂
LS_EINE-ORDERPR_UN = LS_INFORECORD-BPRME. "订单价格单位(采购)
LS_EINE-PRICE_UNIT = LS_INFORECORD-PEINH. "价格单位
LS_EINE-CURRENCY = LS_INFORECORD-WAERS. "货币码
LS_EINE-TAX_CODE = LS_INFORECORD-MWSKZ. "销售/购买税代码
APPEND LS_EINE TO LT_EINE.
LS_EINEX-EINE_INDX = '01'.
LS_EINEX-PURCH_ORG = 'X'.
LS_EINEX-PLND_DELRY = 'X'.
LS_EINEX-INFO_TYPE = 'X'.
LS_EINEX-PLANT = 'X'.
LS_EINEX-ORDERPR_UN = 'X'.
LS_EINEX-PRICE_UNIT = 'X'.
LS_EINEX-CURRENCY = 'X'.
LS_EINEX-TAX_CODE = 'X'.
APPEND LS_EINEX TO LT_EINEX.
* 创建&更新-条件有效期
IF LS_INFORECORD-DATAB IS INITIAL.
EV_TYPE = 'E'.
LS_RETURN_E-TYPE = 'E'.
* 有效期起始时间不能为空!
MESSAGE E120(ZMSG01) INTO LV_MESSAGE.
LS_RETURN_E-MESSAGE = LS_RETURN_E-MESSAGE && LV_MESSAGE.
ENDIF.
IF LS_INFORECORD-DATBI IS INITIAL.
LS_INFORECORD-DATBI = '99991231'.
ENDIF.
LS_COND_VALIDITY-EINE_INDX = '01'. "顺序编号
LS_COND_VALIDITY-PLANT = LS_INFORECORD-WERKS. "工厂
LS_COND_VALIDITY-VALID_FROM = LS_INFORECORD-DATAB. "有效期从
LS_COND_VALIDITY-VALID_TO = LS_INFORECORD-DATBI. "有效期至
APPEND LS_COND_VALIDITY TO LT_COND_VALIDITY.
* 创建&更新-条件明细
LS_CONDITION-EINE_INDX = '01'. "顺序编号
LS_CONDITION-COND_TYPE = 'PB00'. "条件类型
LS_CONDITION-COND_VALUE = LS_INFORECORD-PBXX. "净价
LS_CONDITION-CURRENCY = LS_INFORECORD-WAERS."货币码
LS_CONDITION-COND_P_UNT = LS_INFORECORD-PEINH."条件定价单位
LS_CONDITION-COND_UNIT = LS_INFORECORD-BPRME."条件单位
APPEND LS_CONDITION TO LT_CONDITION.
* 采购信息记录创建&更新
IF EV_TYPE <> 'E'.
CALL FUNCTION 'ME_INFORECORD_MAINTAIN_MULTI'
IMPORTING
ET_EINA = LT_EINA_E
ET_EINE = LT_EINE_E
TABLES
T_EINA = LT_EINA
T_EINAX = LT_EINAX
T_EINE = LT_EINE
T_EINEX = LT_EINEX
COND_VALIDITY = LT_COND_VALIDITY
CONDITION = LT_CONDITION
RETURN = LT_RETURN.
LOOP AT LT_RETURN INTO DATA(LS_RETURN) WHERE TYPE CA 'EAX'.
EV_TYPE = 'E'.
IF LS_RETURN_E-MESSAGE IS INITIAL.
LS_RETURN_E-MESSAGE = LS_RETURN-MESSAGE.
ELSE.
LS_RETURN_E-MESSAGE = LS_RETURN_E-MESSAGE &&
';' &&
LS_RETURN-MESSAGE.
ENDIF.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LS_RETURN_E-TYPE = 'E'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
READ TABLE LT_EINA_E INTO DATA(LS_EINA_E) INDEX 1.
LS_RETURN_E-TYPE = 'S'.
LS_RETURN_E-INFNR = LS_EINA_E-INFO_REC."采购信息号
* 采购信息记录&1维护成功!
MESSAGE S014(ZMSG01) WITH LS_EINA_E-INFO_REC
INTO LS_RETURN_E-MESSAGE.
ENDIF.
ENDIF.
ENDIF.
LS_RETURN_E-ZOAITEM = LS_INFORECORD-ZOAITEM."OA行项目编码
APPEND LS_RETURN_E TO ET_RETURN.
ENDIF.
CLEAR:
LT_EINA_E,
LT_EINE_E,
LS_EINA,
LT_EINA,
LS_EINAX,
LT_EINAX,
LS_EINE,
LT_EINE,
LS_EINEX,
LT_EINEX,
LS_COND_VALIDITY,
LT_COND_VALIDITY,
LS_CONDITION,
LT_CONDITION,
LT_RETURN,
LS_RETURN_E,
LV_MESSAGE,
LS_INFOREC_OLD,
LS_A017.
ENDLOOP.
IF EV_TYPE = 'E'.
EV_MESSAGE = '本次创建包含错误条目!'.
ELSE.
EV_TYPE = 'S'.
EV_MESSAGE = '本次创建全部成功!'.
ENDIF.
ENDFUNCTION.
3070467 - ME_INFORECORD_MAINTAIN_MULTI: Template for creating info record