ABAP:ME11批量创建采购信息记录
BAPI:ME_INFORECORD_MAINTAIN_MULTI
这个BAPI用于创建采购信息记录比较好用,如果要批量修改,特别是涉及到采购信息记录条件价格的修改,建议使用BDC,使用BAPI可能会遇到日期拆分问题
*&---------------------------------------------------------------------* *& Form frm_generate_infnr *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_generate_infnr . 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. "创建返回消息 DATA:ls_key_fields TYPE komg, lt_copy_records TYPE TABLE OF komv, ls_copy_records TYPE komv, lt_copy_staffel TYPE TABLE OF condscale, ls_copy_staffel TYPE condscale, lt_knumh_comp TYPE TABLE OF knumh_comp, ls_knumh_comp TYPE knumh_comp, ls_komk TYPE komk, ls_komp TYPE komp, lv_record TYPE konh-knumh. "获取物料单位 SELECT SINGLE meins,bstme FROM mara INTO @DATA(ls_mara) WHERE matnr EQ @gs_data-matnr. "获取历史采购信息记录 SELECT SINGLE a~infnr, a~matnr, "物料 a~lifnr, "供应商 b~ekorg, "采购组织 b~esokz, "信息类别 b~werks "工厂 INTO @DATA(ls_inforec_old) FROM eina AS a INNER JOIN eine AS b ON a~infnr = b~infnr WHERE a~matnr = @gs_data-matnr AND a~lifnr = @gs_data-lifnr AND b~ekorg = @gs_data-ekorg AND b~esokz = @gs_data-esokz AND b~werks = @gs_data-werks. IF sy-subrc EQ 0. gs_data-status = icon_red_light. gs_data-message = '已存在采购信息记录,请确认'. gs_data-infnr = ls_inforec_old-infnr. RETURN. ENDIF. "创建-基本数据 ls_eina-material = gs_data-matnr. "物料 ls_eina-vendor = gs_data-lifnr."供应商 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 = gs_data-ekorg."采购组织 ls_eine-pur_group = gs_data-ekgrp."采购组 ls_eine-plnd_delry = gs_data-aplfz."计划交货时间(天) ls_eine-info_type = gs_data-esokz."采购信息记录分类 ls_eine-plant = gs_data-werks."工厂 IF ls_mara-bstme IS NOT INITIAL. ls_eine-orderpr_un = ls_mara-bstme."订单价格单位(采购) ELSE. ls_eine-orderpr_un = ls_mara-meins."订单价格单位(采购) ENDIF. ls_eine-price_unit = gs_data-peinh."价格单位 ls_eine-currency = gs_data-waers."货币吗 ls_eine-tax_code = gs_data-mwskz."税码 ls_eine-gr_basediv = gs_data-webre."基于收货的发票校验 ls_eine-nrm_po_qty = gs_data-norbm."标准采购订单数量 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'. ls_einex-gr_basediv = 'X'. ls_einex-nrm_po_qty = 'X'. APPEND ls_einex TO lt_einex. ls_cond_validity-eine_indx = '01'. "顺序编号 ls_cond_validity-plant = gs_data-werks."工厂 ls_cond_validity-valid_from = gs_data-datab."有效期从 ls_cond_validity-valid_to = gs_data-datbi."有效期至 APPEND ls_cond_validity TO lt_cond_validity. "创建&更新-条件明细 ls_condition-eine_indx = '01'."顺序编号 ls_condition-cond_type = 'PB00'."条件类型 ls_condition-cond_value = gs_data-netpr."净价 ls_condition-currency = gs_data-waers."货币码 ls_condition-cond_p_unt = gs_data-peinh."条件定价单位 IF ls_mara-bstme IS NOT INITIAL. ls_condition-cond_unit = ls_mara-bstme."条件单位 ELSE. ls_condition-cond_unit = ls_mara-meins."条件单位 ENDIF. APPEND ls_condition TO lt_condition. 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'. IF gs_data-message IS INITIAL. gs_data-message = ls_return-message. ELSE. gs_data-message = |{ gs_data-message },{ ls_return-message }|. ENDIF. CLEAR:ls_return. ENDLOOP. IF sy-subrc EQ 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. gs_data-status = icon_red_light. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. READ TABLE lt_eina_e INTO DATA(ls_eina_e) INDEX 1. gs_data-infnr = ls_eina_e-info_rec."采购信息号 ENDIF. ENDFORM.