*&---------------------------------------------------------------------* *& Report ZBAPI_WB21 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZBAPI_CONTRACT_CREATE. DATA: L_FLAG TYPE C, CNS_YES TYPE C. DATA:L_EBELN TYPE BAPIMEOUTHEADER-NUMBER, "#EC NEEDED LS_EKKO TYPE EKKO, EXTENSIONIN LIKE BAPIPAREX OCCURS 0 WITH HEADER LINE, LT_EXTENSIONOUT TYPE BAPIPAREX_T, LT_RETURN TYPE BAPIRET2_T, LS_RETURN TYPE BAPIRET2, LS_HEADER TYPE BAPIMEOUTHEADER, LS_HEADERX TYPE BAPIMEOUTHEADERX, LS_ITEM TYPE BAPIMEOUTITEM, LT_ITEM TYPE BAPIMEOUT_T_ITEM, LS_ITEMX TYPE BAPIMEOUTITEMX, LT_ITEMX TYPE BAPIMEOUT_T_ITEMX. *--------------------------------------------------------------------* * Header赋值 *--------------------------------------------------------------------* CLEAR: LS_HEADER,LS_HEADERX,L_FLAG. REFRESH: LT_RETURN, LT_ITEM, LT_ITEMX. *READ TABLE gt_out INTO gwa_out INDEX 1. * *IF gwa_out-ebeln IS NOT INITIAL. * g_action = cns_modify. *ELSE. * g_action = cns_create. *ENDIF. CNS_YES = 'X'. *LS_HEADER-NUMBER = '4600000005'."gwa_out-ebeln. "采购凭证号 LS_HEADER-VENDOR = '0000400007'."gwa_out-lifnr. "供应商 LS_HEADER-DOC_TYPE = 'MK'."gwa_out-bsart. "协议类型 LS_HEADER-COMP_CODE = '8000'."gwa_out-bukrs. "公司代码 LS_HEADER-DOC_DATE = SY-DATUM."gwa_out-bedat. "协议日期 *ls_header-vper_start = sy-datum."gwa_out-kdatb. "协议起始日期 *ls_header-vper_end = sy-datum."gwa_out-kdate. "协议截至日期 LS_HEADER-PURCH_ORG = '8000'."gwa_out-ekorg. "采购组织 LS_HEADER-PUR_GROUP = '007'."gwa_out-ekgrp. "采购组 *ls_header-acum_value = ."gwa_out-ktwrt. "目标值 LS_HEADER-CURRENCY = 'USD'."gwa_out-waers. "货币 LS_HEADER-LANGU = SY-LANGU. LS_HEADER-VPER_START = SY-DATUM. LS_HEADER-VPER_END = SY-DATUM. *LS_HEADERX-NUMBER = CNS_YES. "合同号 LS_HEADERX-VENDOR = CNS_YES. "供应商 LS_HEADERX-DOC_TYPE = CNS_YES. "协议类型 LS_HEADERX-COMP_CODE = CNS_YES. "公司代码 LS_HEADERX-DOC_DATE = CNS_YES. "协议日期 LS_HEADERX-VPER_START = CNS_YES. "协议起始日期 LS_HEADERX-VPER_END = CNS_YES. "协议截至日期 LS_HEADERX-PURCH_ORG = CNS_YES. "采购组织 LS_HEADERX-PUR_GROUP = CNS_YES. "采购组 *ls_headerx-acum_value = cns_yes. "目标值 LS_HEADERX-CURRENCY = CNS_YES. "货币 LS_HEADERX-LANGU = CNS_YES. LS_HEADERX-VPER_START = CNS_YES. LS_HEADERX-VPER_END = CNS_YES. *--------------------------------------------------------------------* * Header 自定义字段赋值 *--------------------------------------------------------------------* DATA: LS_BAPI_TE_MEOUTHEADERX LIKE BAPI_TE_MEOUTHEADERX, LS_BAPI_TE_MEOUTHEADER LIKE BAPI_TE_MEOUTHEADER. *CLEAR extensionin. *ls_bapi_te_meoutheader-number = gwa_out-ebeln. *ls_bapi_te_meoutheader-zhtnum = gwa_out-zhtnum. "外部合同号 *ls_bapi_te_meoutheader-zlotno = gwa_out-zlotno. "LOT包号 *ls_bapi_te_meoutheader-zcgblx = gwa_out-zcgblx. "采购包类型 *ls_bapi_te_meoutheader-zhtbz = gwa_out-zhtbz. "采购立项号 *ls_bapi_te_meoutheader-zcgnum = gwa_out-zcgnum. "采购任务 *extensionin-structure = 'BAPI_TE_MEOUTHEADER'. *CALL METHOD cl_abap_container_utilities=>fill_container_c * EXPORTING * im_value = ls_bapi_te_meoutheader * IMPORTING * ex_container = extensionin-valuepart1 * EXCEPTIONS * illegal_parameter_type = 1 * OTHERS = 2. *APPEND extensionin. * *CLEAR extensionin. *ls_bapi_te_meoutheaderx-number = gwa_out-ebeln. *ls_bapi_te_meoutheaderx-zhtnum = cns_yes. "外部合同号 *ls_bapi_te_meoutheaderx-zlotno = cns_yes. "LOT包号 *ls_bapi_te_meoutheaderx-zcgblx = cns_yes. "采购包类型 *ls_bapi_te_meoutheaderx-zhtbz = cns_yes. "采购立项号 *ls_bapi_te_meoutheaderx-zcgnum = cns_yes. "采购任务 *extensionin-structure = 'BAPI_TE_MEOUTHEADERX'. *CALL METHOD cl_abap_container_utilities=>fill_container_c * EXPORTING * im_value = ls_bapi_te_meoutheaderx * IMPORTING * ex_container = extensionin-valuepart1 * EXCEPTIONS * illegal_parameter_type = 1 * OTHERS = 2. ** EXTENSIONIN-VALUEPART1 = LS_BAPI_TE_MEOUTHEADERX. *APPEND extensionin. *--------------------------------------------------------------------* * Item赋值 *--------------------------------------------------------------------* CLEAR: LS_ITEM,LS_ITEMX,LT_ITEM[],LT_ITEMX[]. *LOOP AT gt_out INTO gwa_out. CLEAR: LS_ITEM, LS_ITEMX. LS_ITEM-ITEM_NO = 10."gwa_out-ebelp. "行号 LS_ITEM-MATERIAL = '3TE50G1803J2'." "物料 LS_ITEM-SHORT_TEXT = 'C.彩电.HU50N3030UWR.P/S..美国'."gwa_out-txz01. "端文本 * ls_item-matl_group = ."gwa_out-matkl. "物料组 LS_ITEM-MATL_GROUP = 'G14001'."gwa_out-werks. "工厂 LS_ITEM-PLANT = '8000'."gwa_out-werks. "工厂 LS_ITEM-STGE_LOC = 'Q012'."gwa_out-werks. "工厂 LS_ITEM-TARGET_QTY = 10."gwa_out-ktmng. "目标数量 LS_ITEM-PO_UNIT = 'PC'."gwa_out-meins. * ls_item-po_unit_iso = ."gwa_out-meins. LS_ITEM-NET_PRICE = 400."gwa_out-netpr. "净价 * ls_item-price_unit = ."gwa_out-peinh. "价格单位 * ls_item-orderpr_un = ."gwa_out-meins. "订单价格单位(采购) * ls_item-orderpr_un_iso = ."gwa_out-meins. "订单价格单位(采购) * ls_item-acctasscat = 'U'. "科目分配类别 * ls_item-item_cat = 0. "项目类别 *LS_ITEM-EMATERIAL = '9TD47G11033'. APPEND LS_ITEM TO LT_ITEM. LS_ITEMX-ITEM_NO = '10'."gwa_out-ebelp. "行号 LS_ITEMX-ITEM_NOX = CNS_YES. "行号 LS_ITEMX-MATERIAL = CNS_YES. "端文本 LS_ITEMX-SHORT_TEXT = CNS_YES. "端文本 * ls_itemx-matl_group = cns_yes. "物料组 LS_ITEMX-MATL_GROUP = CNS_YES. "工厂 LS_ITEMX-PLANT = CNS_YES. "工厂 LS_ITEMX-STGE_LOC = CNS_YES. "工厂 LS_ITEMX-TARGET_QTY = CNS_YES. "目标数量 LS_ITEMX-PO_UNIT = CNS_YES. * ls_itemx-po_unit_iso = cns_yes. LS_ITEMX-NET_PRICE = CNS_YES. "净价 * ls_itemx-price_unit = cns_yes. "价格单位 * ls_itemx-orderpr_un = cns_yes. * ls_itemx-orderpr_un_iso = cns_yes. * ls_itemx-acctasscat = cns_yes. "科目分配类别 * ls_itemx-item_cat = cns_yes. "项目类别 *LS_ITEMX-EMATERIAL = CNS_YES. APPEND LS_ITEMX TO LT_ITEMX. *ENDLOOP. *--------------------------------------------------------------------* * Create contract *--------------------------------------------------------------------* IF SY-SUBRC = 0. "无合同号,新建 CALL FUNCTION 'BAPI_CONTRACT_CREATE' EXPORTING HEADER = LS_HEADER HEADERX = LS_HEADERX * TESTRUN = PA_TEST IMPORTING PURCHASINGDOCUMENT = L_EBELN TABLES RETURN = LT_RETURN ITEM = LT_ITEM ITEMX = LT_ITEMX EXTENSIONIN = EXTENSIONIN. ELSE. " 有合同号,修改 L_EBELN = LS_HEADER-NUMBER. CALL FUNCTION 'BAPI_CONTRACT_CHANGE' EXPORTING PURCHASINGDOCUMENT = L_EBELN HEADER = LS_HEADER HEADERX = LS_HEADERX * TESTRUN = PA_TEST IMPORTING EXP_HEADER = LS_HEADER TABLES RETURN = LT_RETURN ITEM = LT_ITEM ITEMX = LT_ITEMX EXTENSIONIN = EXTENSIONIN. ENDIF. L_FLAG = 'S'. LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = 'E' OR TYPE = 'A'. L_FLAG = 'E'. EXIT. ENDLOOP. IF L_FLAG EQ 'S'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF. *IF l_flag EQ 'S'. * IF g_action EQ cns_create. * MESSAGE s836 WITH l_ebeln. * ELSE. * MESSAGE s837 WITH l_ebeln. * ENDIF. *ELSE. * IF g_action EQ cns_create. * MESSAGE s838 WITH l_ebeln. * ELSE. * MESSAGE s839 WITH l_ebeln. * ENDIF. *ENDIF. IF NOT LT_RETURN IS INITIAL. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_STRUCTURE_NAME = 'BAPIRET2' TABLES T_OUTTAB = LT_RETURN EXCEPTIONS OTHERS = 0. ENDIF.
如果报错E BAPI 1 No instance of object type PurchasingContract has been created. External reference: # 1 PurchasingContract # 1 HEADER 0
说明可能是参数没有填完全,仔细检查一遍。
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/18689.html