本文主要是介绍ME11/ME12采购信息记录及条件记录创建及更新BAPI:ME_INFORECORD_MAINTAIN_MULTI,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用ME_INFORECORD_MAINTAIN_MULTI函数进行采购信息记录及条件记录的创建以及更新,单独进行条件价格信息的创建及变更可以参照下面我的另一个帖子:
MEK1/VK11创建条件记录BAPIhttps://blog.csdn.net/DeveloperMrMeng/article/details/118896458?spm=1001.2014.3001.5501
**********************************************************************
* 创建者: 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 AINNER JOIN MARC AS BON A~MATNR = B~MATNRFOR ALL ENTRIES IN @IT_INFORECORDWHERE A~MATNR = @IT_INFORECORD-MATNRAND 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 AINNER JOIN EINE AS BON A~INFNR = B~INFNRFOR ALL ENTRIES IN @IT_INFORECORDWHERE A~MATNR = @IT_INFORECORD-MATNRAND A~LIFNR = @IT_INFORECORD-LIFNRAND B~EKORG = @IT_INFORECORD-EKORGAND B~ESOKZ = @IT_INFORECORD-ESOKZAND 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 AINNER JOIN KONP AS BON A~KNUMH = B~KNUMHFOR ALL ENTRIES IN @IT_INFORECORDWHERE A~MATNR = @IT_INFORECORD-MATNRAND A~LIFNR = @IT_INFORECORD-LIFNRAND A~EKORG = @IT_INFORECORD-EKORGAND A~ESOKZ = @IT_INFORECORD-ESOKZAND A~WERKS = @IT_INFORECORD-WERKSAND A~DATAB = @IT_INFORECORD-DATABAND A~DATBI = @IT_INFORECORD-DATBI.SORT LT_MARA BY MATNR ASCENDINGWERKS ASCENDING.SORT LT_INFOREC_OLD BY MATNR ASCENDINGLIFNR ASCENDINGEKORG ASCENDINGESOKZ ASCENDINGWERKS ASCENDING.SORT LT_A017 BY LIFNR ASCENDINGMATNR ASCENDINGEKORG ASCENDINGWERKS ASCENDINGESOKZ ASCENDINGDATAB ASCENDINGDATBI ASCENDING.LOOP AT IT_INFORECORD INTO LS_INFORECORD.READ TABLE LT_MARA INTO DATA(LS_MARA)WITH KEY MATNR = LS_INFORECORD-MATNRBINARY 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'EXPORTINGINPUT = LS_INFORECORD-BPRMELANGUAGE = SY-LANGUIMPORTINGOUTPUT = LS_INFORECORD-BPRMEEXCEPTIONSUNIT_NOT_FOUND = 1OTHERS = 2.IF LS_INFORECORD-BPRME <> LV_MEINS.EV_TYPE = 'E'.LS_RETURN_E-TYPE = 'E'.
* 物料&1的价格单位为&2,请修正导入数据单位!MESSAGE E013(ZMSG01) WITH LS_INFORECORD-MATNRLV_MEINSINTO LV_MESSAGE.LS_RETURN_E-MESSAGE = LV_MESSAGE.ENDIF.IF LS_INFORECORD-WERKS IS NOT INITIAL.READ TABLE LT_MARA INTO LS_MARAWITH KEY MATNR = LS_INFORECORD-MATNRWERKS = LS_INFORECORD-WERKSBINARY 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-MATNRINTO 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-MATNRLIFNR = LS_INFORECORD-LIFNREKORG = LS_INFORECORD-EKORGESOKZ = LS_INFORECORD-ESOKZWERKS = LS_INFORECORD-WERKSBINARY 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-LIFNRMATNR = LS_INFORECORD-MATNREKORG = LS_INFORECORD-EKORGWERKS = LS_INFORECORD-WERKSESOKZ = LS_INFORECORD-ESOKZDATAB = LS_INFORECORD-DATABDATBI = LS_INFORECORD-DATBIBINARY 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'IMPORTINGET_EINA = LT_EINA_EET_EINE = LT_EINE_ETABLEST_EINA = LT_EINAT_EINAX = LT_EINAXT_EINE = LT_EINET_EINEX = LT_EINEXCOND_VALIDITY = LT_COND_VALIDITYCONDITION = LT_CONDITIONRETURN = 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_RECINTO 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
这篇关于ME11/ME12采购信息记录及条件记录创建及更新BAPI:ME_INFORECORD_MAINTAIN_MULTI的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!