09-29-2008 11:32 AM
Hi SAP Technical Guru,
i have to create Purchase Order through screen(module porgramming) using bapi_po_create1 after pressing standard save button . but it not creating PO.
i have given part of my code below. i am not able to create PO by pressing save button. please suggest me whree i went wrong.
WHEN 'SAVE'.
IF sy-subrc EQ 0.
wa_header-ekorg = ekko-ekorg.
wa_header-purch_org = ekko-ekorg.
wa_header-pur_group = ekko-ekgrp.
wa_header-comp_code = ekko-bukrs.
wa_header-currency = ekko-waers.
wa_header-pmnttrms = ekko-zterm.
wa_header-incoterms1 = ekko-inco1.
wa_header-incoterms2 = ekko-inco2.
wa_header-vendor = ekko-lifnr.
APPEND wa_header TO it_header.
bapimepoheader-bedat = ekko-bedat.
wa_headerx-purch_org = 'X'.
wa_headerx-pur_group = 'X'.
wa_headerx-comp_code = 'X'.
wa_headerx-comp_code = 'X'.
wa_headerx-currency = 'X'.
wa_headerx-pmnttrms = 'X'.
wa_headerx-incoterms1 = 'X'.
wa_headerx-incoterms2 = 'X'.
wa_headerx-vendor = 'X'.
APPEND wa_headerx TO it_headerx.
ENDIF.
IF it_item[] IS NOT INITIAL.
LOOP AT it_item INTO wa_item.
wa_item-po_item = ekpo-ebelp.
wa_item-material = ekpo-matnr.
wa_item-item_cat = ekpo-pstyp.
wa_item-quantity = ekpo-menge.
wa_item-po_unit = ekpo-meins.
wa_item-delivery_date = ekpo-aedat.
wa_item-net_price = ekpo-netpr.
wa_item-plant = ekpo-werks.
wa_item-stge_loc = ekpo-lgort.
wa_item-preq_no = ekpo-banfn.
wa_item-preq_item = ekpo-bnfpo.
APPEND wa_item TO it_item.
CLEAR wa_item.
*scheduled data
wa_sch-delivery_date = ekpo-aedat.
APPEND wa_sch TO it_sch.
CLEAR wa_sch.
wa_itemx-po_item = 'X'.
wa_itemx-material = 'X'.
wa_itemx-item_cat = 'X'.
wa_itemx-quantity = 'X'.
wa_itemx-po_unit = 'X'.
*wa_item-
wa_itemx-net_price = 'X'.
wa_itemx-plant = 'X'.
wa_itemx-stge_loc = 'X'.
wa_itemx-preq_no = 'X'.
wa_itemx-preq_item = 'X'.
APPEND wa_itemx TO it_itemx.
CLEAR wa_itemx.
*scheduledx data
wa_schx-delivery_date = 'X'.
APPEND wa_schx TO it_schx.
CLEAR wa_schx.
APPEND
ENDLOOP.
ENDIF.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = wa_header
poheaderx = wa_headerx
POADDRVENDOR =
TESTRUN =
MEMORY_UNCOMPLETE =
MEMORY_COMPLETE =
POEXPIMPHEADER =
POEXPIMPHEADERX =
VERSIONS =
NO_MESSAGING =
NO_MESSAGE_REQ =
NO_AUTHORITY =
NO_PRICE_FROM_PO =
IMPORTING
EXPPURCHASEORDER =
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
return = it_return
poitem = it_item
poitemx = it_itemx
POADDRDELIVERY =
poschedule = it_sch
poschedulex = it_schx
POACCOUNT =
POACCOUNTPROFITSEGMENT =
POACCOUNTX =
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS =
POCONTRACTLIMITS =
POSERVICES =
POSRVACCESSVALUES =
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM =
POEXPIMPITEMX =
POTEXTHEADER =
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
POCOMPONENTS =
POCOMPONENTSX =
POSHIPPING =
POSHIPPINGX =
POSHIPPINGEXP =
.
*
IF sy-subrc EQ 0.
*
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
RETURN =
.
ELSE.
DELETE i_return WHERE type = 'S'.
DELETE i_return WHERE type = 'I'.
DELETE i_return WHERE type = 'W'.
WRITE:/ 'Following Errors occured in PO Creation:'.
SKIP.
WRITE 😕 wa_header.
LOOP AT it_return WHERE type = 'E' OR type = 'S'.
WRITE:/ it_return-message.
ENDLOOP.
MESSAGE i101 WITH 'Data Not Saved Logic Missing'.
SET SCREEN 100.
LEAVE SCREEN .
CALL SCREEN 100.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDIF.
regards,
09-29-2008 11:35 AM
09-29-2008 11:43 AM
hi thanks,
after saving the screen its get clearing nothing message giving.
regards,
09-29-2008 11:36 AM
hi,
1. bapi_po_create
2.U can use BAPI_PO_CREATE1.
Here is the sample code.
DATA : l_ponumber LIKE ekpo-ebeln,
l_msgty TYPE c,
l_msgid(2) TYPE c,
l_msgno(3) TYPE c,
l_msgtx(100) TYPE c,
l_errflag TYPE c.
DATA : BEGIN OF tl_bapireturn OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA : END OF tl_bapireturn.
*C-- Data declarations for type of subc / serial nos
data: begin of lt_disub_sertab occurs 0,
ebelp like ekpo-ebelp, " PO Item #
sernr like e1rmsno-sernr, " PO Item Serial #
end of lt_disub_sertab.
data: begin of lt_disub_poitem occurs 0,
ebelp like ekpo-ebelp, " PO Item #
serru like ekpo-serru, " Sub contracting Type
anzsn like ekpo-anzsn, " No. of Ser # (= Item Qty)
disub_sobkz like ekpo-disub_sobkz,
disub_pspnr like ekpo-disub_pspnr,
disub_kunnr like ekpo-disub_kunnr,
disub_vbeln like ekpo-disub_vbeln,
disub_posnr like ekpo-disub_posnr,
disub_owner like ekpo-disub_owner,
end of lt_disub_poitem.
*C-- End of data declarations for type of subc / serial nos
CLEAR: l_ponumber.
CLEAR: tl_bapireturn.
REFRESH: tl_bapireturn.
*C-- Handling Type of SubC / Serial Nos
clear lt_disub_poitem.
refresh lt_disub_poitem.
loop at t_po_item
where po_number = t_po_header-po_number.
lt_disub_poitem-ebelp = t_po_item-po_item.
lt_disub_poitem-serru = '1'.
lt_disub_poitem-anzsn = t_po_item-quantity.
append lt_disub_poitem.
clear lt_disub_poitem.
endloop.
Serial Numbers
clear lt_disub_sertab.
refresh lt_disub_sertab.
loop at t_po_itemseril
where po_number = t_po_header-po_number.
lt_disub_sertab-ebelp = t_po_itemseril-po_item.
lt_disub_sertab-sernr = t_po_itemseril-serno.
append lt_disub_sertab.
clear lt_disub_sertab.
endloop.
Export Internal tables to Memory.
export: lt_disub_poitem to memory id 'disub_item',
lt_disub_sertab to memory id 'disub_sertab'.
*C-- End of handling Type of SubC / Serial Nos
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = t_bapi_poheader
POHEADERX = t_bapi_poheaderx
POADDRVENDOR = t_bapi_poaddrvendor
TESTRUN = p_trun
MEMORY_UNCOMPLETE =
MEMORY_COMPLETE =
POEXPIMPHEADER = t_bapi_poexpimpheader
POEXPIMPHEADERX = t_bapi_poexpimpheaderx
VERSIONS =
NO_MESSAGING =
NO_MESSAGE_REQ =
NO_AUTHORITY =
NO_PRICE_FROM_PO =
IMPORTING
EXPPURCHASEORDER = l_ponumber
EXPHEADER =
EXPPOEXPIMPHEADER =
TABLES
RETURN = tl_bapireturn
POITEM = t_bapi_poitem
POITEMX = t_bapi_poitemx
POADDRDELIVERY =
POSCHEDULE = t_bapi_poschedule
POSCHEDULEX = t_bapi_poschedulex
POACCOUNT = t_bapi_poaccount
POACCOUNTPROFITSEGMENT =
POACCOUNTX = t_bapi_poaccountx
POCONDHEADER =
POCONDHEADERX =
POCOND =
POCONDX =
POLIMITS = t_bapi_polimits
POCONTRACTLIMITS =
POSERVICES =
POSRVACCESSVALUES =
POSERVICESTEXT =
EXTENSIONIN =
EXTENSIONOUT =
POEXPIMPITEM = t_bapi_poexpimpitem
POEXPIMPITEMX = t_bapi_poexpimpitemx
POTEXTHEADER = t_bapi_potextheader
POTEXTITEM =
ALLVERSIONS =
POPARTNER =
NFMETALLITMS =
.
IF p_trun IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
ENDIF.
*C-- Write messages
WRITE: / 'PO Number: '(012), t_po_header-po_number.
CLEAR l_errflag.
LOOP AT tl_bapireturn.
CLEAR: l_msgty, l_msgid, l_msgno, l_msgtx.
l_msgty = tl_bapireturn-type.
l_msgid = tl_bapireturn-id.
l_msgno = tl_bapireturn-number.
l_msgtx = tl_bapireturn-message.
WRITE: / l_msgty, l_msgid, l_msgno, l_msgtx.
IF l_msgty EQ 'E'.
l_errflag = 'X'.
ENDIF. " l_msgty EQ 'E'
ENDLOOP.
3. i am not sure but you can try with
BAPI_STOREORDER_CREATE Creates Documents (PR, PO, Delivery or Sales order) From Store Orders
4. BAPI Links
http://www.sapbapi.com/bapi-list/
Regards,
Deepthi.