06-09-2008 12:10 PM
Hi,
I have a problem with BAPI_SALESORDER_CREATEFROMDAT2.
I have this error E VP 112 Inserire il committente o il destinatario
Wich is the field for the customers?
Many Thanks!!
06-09-2008 12:25 PM
Check if the customer exists for the one you are trying to create a sales order. I am using this same Bapi and it is working fine. So please re-check all the inputs to the bapi.
Thanks
06-09-2008 12:27 PM
06-09-2008 12:38 PM
You have to fill the ORDER_PARTNERS table for maintaining ship to and sold to party.
see sample code below:
REPORT zso.
TABLES: zwebsales, zvmg, knvv, zsd_payer_hadeed, zwebbillto.
DATA: BEGIN OF i_web OCCURS 0,
mandt TYPE zwebsales-mandt,
enqno TYPE zwebsales-enqno,
cust TYPE zwebsales-cust,
shipto TYPE zwebsales-shipto,
delmonth TYPE zwebsales-delmonth,
payterm TYPE zwebsales-payterm,
enqline TYPE zwebsales-enqline,
matkl LIKE v_matnr-matkl,
enqdate TYPE zwebsales-enqdate,
custpo TYPE zwebsales-custpo,
custdate TYPE zwebsales-custdate,
accman TYPE zwebsales-accman,
material TYPE zwebsales-material,
maktx LIKE v_matnr-maktx,
qty TYPE zwebsales-qty,
accstatus TYPE zwebsales-accstatus,
acctext TYPE zwebsales-acctext,
custstatus TYPE zwebsales-custstatus,
custtext TYPE zwebsales-custtext,
saleno TYPE zwebsales-saleno,
END OF i_web.
*save current line of I_WEB
DATA: l_web LIKE LINE OF i_web.
*Enquiry Lines on ZWEBSALES to update with Sales Order
RANGES: u_enqline FOR zwebsales-enqline.
DATA: indx(4) TYPE n,
matnr_num(18) TYPE n.
DATA:
sys_month(2) TYPE n,
sys_year(4) TYPE n,
sys_year_plus1(4) TYPE n,
in_month(2) TYPE n,
in_deldate(7),
so_char(10),
mess_text(120),
wk_billto LIKE zwebbillto-billto,
v_cust LIKE zwebbillto-cust,
v_shipto LIKE zwebbillto-shipto,
shipto(10) TYPE n.
********
DATA:
v_salesdocument LIKE vbak-vbeln,
v_itm_number LIKE vbap-posnr,
wa_header LIKE bapisdhd1,
itab_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
itab_items LIKE bapisditm OCCURS 0 WITH HEADER LINE,
itab_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE,
itab_schedules LIKE bapischdl OCCURS 0 WITH HEADER LINE,
itab_text LIKE bapisdtext OCCURS 0 WITH HEADER LINE,
itab_schedulex LIKE bapischdlx OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
sys_year = sy-datum(4).
sys_year_plus1 = sys_year + 1.
sys_month = sy-datum+4(2).
*get Sales Lines with no SAP Sales Order
SELECT * FROM zwebsales INTO CORRESPONDING FIELDS OF TABLE i_web
WHERE saleno EQ space.
*get the Material Group
LOOP AT i_web.
matnr_num = i_web-material.
SELECT SINGLE matkl maktx
INTO (i_web-matkl, i_web-maktx) FROM v_matnr
WHERE matnr EQ matnr_num.
MODIFY i_web.
ENDLOOP.
*sort on SoldTo, ShipTo, Delivery month, Pay Terms, Material Group
SORT i_web BY enqno
cust
shipto
delmonth
payterm
enqline. "to give Sales Lines same sequence as Enquiry
*each sorted key, up to Material Group, is a Sales Order
LOOP AT i_web.
*1st copy each line to current line
l_web = i_web.
AT NEW matkl.
AT NEW payterm.
REFRESH:
u_enqline .
clear v_text_count.
REFRESH: itab_items, itab_schedules,itab_partners.
CLEAR: wa_header, v_salesdocument.
PERFORM bdc_head.
CLEAR v_itm_number.
*index is 1 for first Sales Line
indx = 1.
ENDAT.
*load exact lines to stamp with Sales Order ID
u_enqline-sign = 'I'.
u_enqline-option = 'EQ'.
u_enqline-low = i_web-enqline.
APPEND u_enqline.
PERFORM bdc_line.
*index is 2 for 2nd and all other Sales Lines
indx = 2.
itab_text-itm_number = v_itm_number.
itab_text-text_id = '0005'.
itab_text-format_col = '*'.
IF NOT i_web-custtext+0(122) IS INITIAL.
CONCATENATE 'Customer :' i_web-custtext+0(122)
INTO itab_text-text_line.
itab_text-langu = 'E'.
APPEND itab_text.
ENDIF.
IF NOT i_web-custtext+122(78) IS INITIAL.
CLEAR itab_text-format_col.
itab_text-text_line = i_web-custtext+122(78).
itab_text-function = '009'.
APPEND itab_text.
ENDIF.
itab_text-itm_number = v_itm_number.
itab_text-text_id = '0005'.
itab_text-format_col = '*'.
IF NOT i_web-acctext+0(122) IS INITIAL.
CONCATENATE 'Acc Man : ' i_web-acctext+0(122)
INTO itab_text-text_line.
itab_text-langu = 'E'.
APPEND itab_text.
ENDIF.
IF NOT i_web-acctext+122(78) IS INITIAL.
CLEAR itab_text-format_col.
itab_text-text_line = i_web-acctext+122(78).
itab_text-function = '009'.
APPEND itab_text.
ENDIF.
AT END OF matkl.
AT END OF payterm.
PERFORM bdc_save.
ENDAT.
ENDLOOP.
&----
*& Form bdc_head
&----
text
----
--> p1 text
<-- p2 text
----
FORM bdc_head.
SELECT SINGLE * FROM zvmg WHERE matkl EQ l_web-matkl.
wa_header-doc_type = zvmg-auart.
wa_header-sales_org = zvmg-vkorg.
wa_header-distr_chan = '30'.
wa_header-division = zvmg-spart.
*Use Enquiry Date(always there from Web) when Customer PO Date is empty
*convert Date from CCYYMMDD to system format
Customer PO Date
IF l_web-custdate IS INITIAL.
wa_header-purch_date = l_web-enqdate.
ELSE.
wa_header-purch_date = l_web-custdate.
ENDIF.
*set up Pay Terms to dummy/default
IF l_web-payterm = 'L C '.
l_web-payterm = 'LC00'. "letter of Credit
ELSEIF l_web-payterm = 'B G '.
l_web-payterm = 'BG00'. "Bank Guarantee
ELSE.
l_web-payterm = 'CA00'. "Cash
ENDIF.
Customer PO Number
wa_header-purch_no_c = l_web-custpo.
Delivery Block
wa_header-dlv_block = '12'.
Terms of payment key
wa_header-pmnttrms = l_web-payterm.
Req Delv Date
in_month = i_web-delmonth.
IF in_month < sys_month.
wa_header-req_date_h = sy-datum.
wa_header-req_date_h+0(4) = sys_year_plus1.
wa_header-req_date_h+4(2) = in_month.
CONCATENATE in_month '.' sys_year_plus1 INTO in_deldate.
wa_header-req_date_h = in_deldate.
ELSEIF in_month > sys_month.
wa_header-req_date_h = sy-datum.
wa_header-req_date_h+0(4) = sys_year.
wa_header-req_date_h+4(2) = in_month.
CONCATENATE in_month '.' sys_year INTO in_deldate.
wa_header-req_date_h = in_deldate.
ELSEIF in_month = sys_month.
wa_header-req_date_h = sy-datum + 30.
wa_header-req_date_h = sy-datum .
ENDIF.
wa_header-req_date_h = sy-datum + 30.
wa_header-date_type = '3'.
Sold-to
itab_partners-partn_role = 'AG'.
itab_partners-partn_numb = l_web-cust.
APPEND itab_partners.
Ship to
itab_partners-partn_role = 'WE'.
itab_partners-partn_numb = l_web-shipto.
APPEND itab_partners.
Bill-to
CLEAR: v_cust,v_shipto,zwebbillto,zsd_payer_hadeed.
MOVE l_web-shipto TO v_shipto.
MOVE l_web-cust TO v_cust.
SELECT SINGLE * FROM zwebbillto
WHERE cust = v_cust
AND shipto = v_shipto.
IF sy-subrc = 0.
wk_billto = zwebbillto-billto.
itab_partners-partn_role = 'RE'.
itab_partners-partn_numb = wk_billto.
APPEND itab_partners.
ENDIF.
Payer
SELECT SINGLE * FROM zsd_payer_hadeed
WHERE soldto = v_cust
AND payterm = l_web-payterm.
IF sy-subrc = 0.
itab_partners-partn_role = 'RG'.
itab_partners-partn_numb = zsd_payer_hadeed-payer .
APPEND itab_partners.
ENDIF.
*show the input data
SKIP 2.
WRITE: / l_web-enqno,
l_web-cust NO-ZERO,
l_web-shipto NO-ZERO,
l_web-payterm,
l_web-matkl.
IF zsd_payer_hadeed-payer IS INITIAL.
WRITE: '***** WARNING: NO PAYER FOR TERMS-DEFAULT IS USED *****'.
ENDIF.
ENDFORM. " bdc_head
&----
*& Form bdc_line
&----
text
----
--> p1 text
<-- p2 text
----
FORM bdc_line.
v_itm_number = v_itm_number + 10.
itab_items-itm_number = v_itm_number.
itab_items-material = i_web-material.
itab_items-target_qty = i_web-qty.
APPEND itab_items.
itab_schedules-itm_number = v_itm_number.
itab_schedules-sched_line = '0001'.
*ensure delivery month is in future
in_month = i_web-delmonth.
IF in_month < sys_month.
CONCATENATE sys_month '.' sys_year INTO in_deldate.
itab_schedules-req_date = in_deldate.
itab_schedules-dlv_date = in_deldate..
ELSEIF in_month > sys_month.
CONCATENATE in_month '.' sys_year INTO in_deldate.
itab_schedules-req_date = in_deldate.
itab_schedules-dlv_date = in_deldate..
ELSEIF in_month = sys_month.
itab_schedules-req_date = sy-datum.
itab_schedules-dlv_date = sy-datum.
ENDIF.
itab_schedules-date_type = '3'.
itab_schedules-req_qty = i_web-qty.
APPEND itab_schedules.
itab_schedulex-itm_number = v_itm_number..
itab_schedulex-sched_line = '0001'.
itab_schedulex-updateflag = 'U'.
itab_schedulex-date_type = 'X'.
itab_schedulex-req_date = 'X'.
itab_schedulex-dlv_date = 'X'.
itab_schedulex-req_qty = 'X'.
APPEND itab_schedulex.
*show the input data
WRITE: /50 i_web-enqline,
i_web-material,
i_web-qty NO-ZERO,
i_web-delmonth, ' ',
i_web-maktx.
ENDFORM. " bdc_line
&----
*& Form bdc_save
&----
text
----
--> p1 text
<-- p2 text
----
FORM bdc_save.
REFRESH: itab_return.
CLEAR itab_return.
CLEAR v_salesdocument.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
SALESDOCUMENTIN =
order_header_in = wa_header
ORDER_HEADER_INX =
SENDER =
BINARY_RELATIONSHIPTYPE =
INT_NUMBER_ASSIGNMENT =
BEHAVE_WHEN_ERROR =
LOGIC_SWITCH =
TESTRUN =
CONVERT = ' '
IMPORTING
salesdocument = v_salesdocument
TABLES
return = itab_return
order_items_in = itab_items
ORDER_ITEMS_INX =
order_partners = itab_partners
order_schedules_in = itab_schedules
order_schedules_inx = itab_schedulex
ORDER_CONDITIONS_IN =
ORDER_CFGS_REF =
ORDER_CFGS_INST =
ORDER_CFGS_PART_OF =
ORDER_CFGS_VALUE =
ORDER_CFGS_BLOB =
ORDER_CFGS_VK =
ORDER_CFGS_REFINST =
ORDER_CCARD =
order_text = itab_text
ORDER_KEYS =
EXTENSIONIN =
PARTNERADDRESSES =
.
LOOP AT itab_return WHERE type = 'E'.
ENDLOOP.
IF sy-subrc <> 0 AND NOT v_salesdocument IS INITIAL.
COMMIT WORK AND WAIT.
so_char = v_salesdocument.
*update the input table
LOOP AT itab_return WHERE type = 'S' AND
id = 'V1' AND
number = '311'.
ENDLOOP.
mess_text = itab_return-message.
WRITE: / i_web-enqno, itab_return-type, mess_text.
UPDATE zwebsales SET saleno = so_char
WHERE enqno EQ i_web-enqno
AND enqline IN u_enqline.
ELSE.
Error during posting the record
LOOP AT itab_return.
mess_text = itab_return-message.
WRITE: / i_web-enqno, itab_return-type, mess_text.
ENDLOOP.
ENDIF.