‎2009 Aug 04 9:31 AM
hi , im finding difficulty in creating a po. using a sample code given below .The po is not getting created . plz suggest whether i need to provide more internal tables to bapi function module in order to create that po . or plz send a sample code for it .
thanks !
*&---------------------------------------------------------------------*
*& Report Z_PO_CREATE_BAPI
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_PO_CREATE_BAPI.
</>data:header like BAPIMEPOHEADER,</>
headerx like BAPIMEPOHEADERX,
it_item like standard table of BAPIMEPOITEM,
it_itemx like standard table of BAPIMEPOITEMX,
return like standard table of BAPIRET2,
wa_item like BAPIMEPOITEM,
wa_itemx like BAPIMEPOITEMX,
p_int type i,
p_matnr like mara-matnr,
p_pono like ekko-ebeln.
DATA: BEGIN OF BAPIRETURN OCCURS 0.
INCLUDE STRUCTURE BAPIRET2.
DATA: END OF BAPIRETURN.
constants:
c_x type c value 'X'.
header-comp_code = 'SILS'.
header-doc_type = 'DP25'.
header-creat_date = sy-datum.
header-item_intvl = '10'.
header-vendor = '0000700001'.
header-langu = sy-langu.
header-pmnttrms = '0001'.
header-purch_org = 'RUDP'.
header-pur_group = 'S02'.
header-currency = 'INR'.
headerx-comp_code = c_x.
headerx-doc_type = c_x.
headerx-creat_date = c_x.
headerx-item_intvl = c_x .
headerx-vendor = c_x.
headerx-langu = c_x.
headerx-pmnttrms = c_x .
headerx-purch_org = c_x.
headerx-pur_group = c_x.
*LOOP AT it_final2 INTO wa_final2.
p_int = p_int + 10.
wa_item-po_item = p_int.
p_matnr = 'BKT CHAWA BB'.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = p_matnr
IMPORTING
output = p_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
*IF sy-subrc = 0.
*MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*ENDIF.
wa_item-material = p_matnr.
wa_item-plant = 'TRAD'.
wa_item-quantity = 20.
wa_item-conf_ctrl = 'Z01'.
wa_item-ACKN_REQD = 'X'.
WA_ITEM-ERS = ''.
APPEND wa_item TO it_item.
wa_itemx-po_item = p_int.
wa_itemx-material = c_x.
wa_itemx-plant = c_x .
wa_itemx-stge_loc = c_x .
wa_itemx-quantity = c_x .
wa_itemx-item_cat = c_x .
wa_itemx-acctasscat = c_x .
wa_itemx-conf_ctrl = 'X'.
wa_itemx-ACKN_REQD = 'X'.
WA_ITEMX-ERS = 'X'.
APPEND wa_itemx TO it_itemx.
*ENDLOOP.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = header
poheaderx = headerx
IMPORTING
exppurchaseorder = p_pono
TABLES
return = return
poitem = it_item
poitemx = it_itemx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = BAPIRETURN.
write:/ p_pono.
‎2009 Aug 04 11:37 AM
Hi,
I have checked your code and I feel its a problem in the data your passing.
Please check the purchase org and group once again.
Also your not passing same parameters in ITEM and ITEMX table.
Please check your data and I think probelm will be solved.
Regards,
Subhashini
‎2009 Aug 04 9:38 AM
Hi,
Please search in SCN you can find lot of posts on this bapi..You will get useful information.
Regards,
Nagaraj
‎2009 Aug 04 9:39 AM
Hi,
Try single testing the function module by giving to what all you want to pass like t_header,t_item etc
and then execute with that test data.
Check the return table t_return and change accordingly.
Regards,
Subhashini
‎2009 Aug 04 9:42 AM
Hi Ujjwal,
Please find the WIKI SAMPLE Code in the following link.
[LINK|https://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModuletocreatePOusingBAPI]
Regards,
Vimal.
‎2009 Aug 04 9:46 AM
Hi,
[PO Creation Code|http://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModuletocreatePOusingBAPI]
[Link|http://wiki.sdn.sap.com/wiki/display/SCM/FunctionModuletocreatePOusingBAPI]
‎2009 Aug 04 9:48 AM
Hi,
Check the sample code for your reference
DATA: t_salesorder TYPE STANDARD TABLE OF x_salesorder
WITH HEADER LINE,
t_header TYPE bapisdhd1 OCCURS 0 WITH HEADER LINE,
t_headerx TYPE bapisdhd1x OCCURS 0 WITH HEADER LINE,
t_partner TYPE bapiparnr OCCURS 0 WITH HEADER LINE,
t_item TYPE bapisditm OCCURS 0 WITH HEADER LINE,
t_itemx TYPE bapisditmx OCCURS 0 WITH HEADER LINE,
t_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
gv_doc_no LIKE bapivbeln-vbeln,
wa_salesorder LIKE LINE OF t_salesorder,
wa_partner TYPE bapiparnr,
wa_item TYPE bapisditm,
wa_alpha LIKE LINE OF t_salesorder.
LOOP AT t_salesorder INTO wa_salesorder.
t_header-sales_org = wa_salesorder-vkorg.
t_header-distr_chan = wa_salesorder-vtweg.
t_header-division = wa_salesorder-spart.
t_header-doc_type = wa_salesorder-auart.
APPEND t_header.
t_headerx-sales_org = 'X'.
t_headerx-distr_chan = 'X'.
t_headerx-division = 'X'.
t_headerx-doc_type = 'X'.
APPEND t_headerx.
t_itemx-material = 'X'.
t_itemx-target_qty = 'X'.
APPEND t_itemx.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_salesorder-kunnr
IMPORTING
output = wa_alpha-kunnr.
wa_partner-partn_role = 'AG'.
wa_partner-partn_numb = wa_alpha-kunnr.
APPEND wa_partner TO t_partner.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_salesorder-kunnr1
IMPORTING
output = wa_alpha-kunnr1.
wa_partner-partn_role = 'WE'.
wa_partner-partn_numb = wa_alpha-kunnr1.
APPEND wa_partner TO t_partner.
wa_item-po_itm_no = wa_salesorder-bstnk.
wa_item-itm_number = wa_salesorder-posnr.
wa_item-material = wa_salesorder-matnr.
wa_item-target_qty = wa_salesorder-kwmeng.
APPEND wa_item TO t_item.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = t_header
order_header_inx = t_headerx
IMPORTING
salesdocument = gv_doc_no
TABLES
return = t_return
order_items_in = t_item[]
order_items_inx = t_itemx
order_partners = t_partner[].
WRITE:/ 'Type:', t_return-type.
WRITE:/ 'Message:', t_return-message.
WRITE:/ 'Sales Order No:', gv_doc_no.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = t_return.
ENDLOOP.
‎2009 Aug 04 11:37 AM
Hi,
I have checked your code and I feel its a problem in the data your passing.
Please check the purchase org and group once again.
Also your not passing same parameters in ITEM and ITEMX table.
Please check your data and I think probelm will be solved.
Regards,
Subhashini
‎2009 Aug 05 2:57 PM
‎2009 Aug 06 6:36 AM
Hi,
Can I know what all changes you made in the code?
Regards,
SUbhashini