Hi friends.
I have started working in SAP, 1.5 month back.
I am getting an error in BAPI_PO_CREATE1 as follows :
* PO header data still faulty
*No instance of object type PurchaseOrder has been created. External reference:
Code is as follows :
DATA c_x TYPE c VALUE 'X'. DATA: w_zmm_mcm_mdm TYPE ty_zmm_mcm_mdm, w_ekpo TYPE ty_ekpo, w_ekko TYPE ty_ekko, w_lqua TYPE ty_lqua, *For bapi to create PO "pocontractlimits LIKE bapiesucc, w_header LIKE bapimepoheader, w_headerx LIKE bapimepoheaderx, w_item LIKE bapimepoitem, w_itemx LIKE bapimepoitemx. DATA: it_zmm_mcm_mdm TYPE STANDARD TABLE OF ty_zmm_mcm_mdm, it_ekpo TYPE STANDARD TABLE OF ty_ekpo, it_ekko TYPE STANDARD TABLE OF ty_ekko, it_lqua TYPE STANDARD TABLE OF ty_lqua, it_aux TYPE STANDARD TABLE OF ty_zmm_mcm_mdm, *For bapi to create PO. it_account TYPE STANDARD TABLE OF bapimepoaccount, it_accountx TYPE STANDARD TABLE OF bapimepoaccountx, it_item TYPE STANDARD TABLE OF bapimepoitem, it_itemx TYPE STANDARD TABLE OF bapimepoitemx, it_return_po TYPE STANDARD TABLE OF bapiret2. *POPULATE HEADER DATA FOR PO w_header-comp_code = w_ekko-bukrs."Company Code w_header-doc_type = 'NB'."Purchasing Document Type w_header-creat_date = sy-datum."Date on Which Record Was Created w_header-created_by = sy-uname."Name of Person who Created the Object w_header-langu = sy-langu."Language Key w_header-doc_date = sy-datum."Purchasing Document Date w_header-purch_org = w_ekko-ekorg."Purchasing Organization w_header-pur_group = w_ekko-ekgrp."Purchasing Group w_header-telephone = w_ekko-telf1."Vendor's Telephone Number w_header-vat_cntry = w_ekko-stceg_l."Country of Sales Tax ID Number w_header-currency = w_ekko-waers."Currency Key w_header-langu_iso = w_ekko-spras."ISO code for language key w_header-suppl_plnt = w_ekko-reswk."Supplying (Issuing) Plant in Stock Transport Order w_header-DELETE_IND = w_ekko-LOEKZ. w_header-STATUS = w_ekko-statu. w_header-item_intvl = w_ekko-pincr. **POPULATE HEADER FLAG. w_headerx-comp_code = c_x. w_headerx-doc_type = c_x. w_headerx-creat_date = c_x. w_headerx-created_by = c_x. w_headerx-langu = c_x. w_headerx-doc_date = c_x. w_headerx-purch_org = c_x. w_headerx-pur_group = c_x. w_headerx-telephone = c_x. w_headerx-vat_cntry = c_x. w_headerx-currency = c_x. w_headerx-langu_iso = c_x. w_headerx-suppl_plnt = c_x. w_header-DELETE_IND = c_x. w_header-STATUS = c_x. w_header-item_intvl = c_x. READ TABLE it_ekpo INTO w_ekpo WITH KEY ebeln = w_ekko-ebeln. IF sy-subrc EQ 0. * POPULATE ITEM DATA. w_item-po_item = w_ekpo-ebelp."2: Item Number of Purchasing Document w_item-delete_ind = c_x."w_ekpo-loekz."3: Deletion Indicator in Purchasing Document w_item-short_text = w_ekpo-txz01."Short Text w_item-material = p_mate ."4: Material Number w_item-plant = v_to_werks."w_ekpo-werks."5: Plant w_item-stge_loc = p_loca ."6: Storage location w_item-info_rec = w_ekpo-infnr."7: Number of Purchasing Info Record w_item-quantity = w_ekpo-menge."8: Purchase Order Quantity "w_item-po_unit = w_ekpo-meins."9: Purchase Order Unit of Measure w_item-price_unit = w_ekpo-peinh."11: Price unit w_item-unlimited_dlv = ''."w_ekpo-uebtk."12: Indicator: Unlimited Overdelivery Allowed w_item-customer = w_ekpo-kunnr."Customer w_item-conf_ctrl = w_ekpo-bstae."13: Confirmation Control Key w_item-ret_item = c_x. "Rerurn Item w_item-net_price = w_ekpo-netpr."Net Price APPEND w_item TO it_item. * POPULATE ITEM FLAG TABLE w_itemx-po_item = w_ekpo-ebelp. w_itemx-delete_ind = c_x. w_itemx-short_text = c_x. w_itemx-material = c_x. w_itemx-plant = c_x. w_itemx-stge_loc = c_x. w_itemx-info_rec = c_x. w_itemx-quantity = c_x. "w_itemx-po_unit = c_x. w_itemx-price_unit = c_x. w_itemx-unlimited_dlv = c_x. w_itemx-customer = c_x. w_itemx-conf_ctrl = c_x. w_itemx-ret_item = c_x. w_itemx-net_price = c_x. APPEND w_itemx TO it_itemx. CLEAR: w_itemx, w_item. ENDIF. CALL FUNCTION 'BAPI_PO_CREATE1' EXPORTING poheader = w_header poheaderx = w_headerx IMPORTING exppurchaseorder = v_purch_order TABLES return = it_return_po poitem = it_item poitemx = it_itemx. IF it_return_po IS INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = c_x. WRITE: 'Purchase order: ', v_purch_order. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF.