Double sales order creaated : BAPI_SALESORDER_CREATEFROMDAT2
Hi All,
I use the BAPI "BAPI_SALESORDER_CREATEFROMDAT2" to create sales order, The essential data for creating Sales order is taken from flat file. The flat file might contain multiple sales order details, The issue is when executed the program (BAPI inside) is creating two sales order with same Purchase order number, which should not be the case as the system throws the error "POallready exists".
Can any one tell me why BAPI is creating two sales order with same PO number? I.e Why bapi is not validating the PO number when the PO is allready assigned to some other Sales order.
Regds,
Praveen.
Hi Praveen,
@ Pravaeen @ Vijay : True, but if the settings are ON for the validation of PO in SO, then the system throws the error stating "PO allready Exists" and it stops the process.
Normally it is a Warning/Information error, again depends on the configuration. Are you sure it is throwing the message as type "ERROR".
@ Pravaeen @ Dave & Sampath : When i tried executing the bapi through SE37 it throws the error if the PO is allready assigned to any other SO, hence when the bapi called through program should behave the same, but it isnt....
When you try through the BAPI in SE37, what is the type of the message is it error/warning/information? I am sure that BAPI would behave the same when run from your program too, it is up to you how you handle this message, if you don't want to create a SO then you have to look for this message in the return parameter (irrespective of the type that is E/W/I)
Normally when you code a BAPI, you look for a Error/Abend type message in the return parameter and do a roll back.
So if you have coded to look for only error/abend and the system is issuing a W/I then this is over looked and the SO is created.
@ Pravaeen Not all the time the program (BAPI inside) creates double order, it happens rarely. Why is it happening? Is it because of lock entry? Any idea?
You will have to look for a pattern in cases where the double order is getting created, is it for a particular no of records from the input, is it for a particular customer/material etc and then debug further.
Regards,
Chen
Similar Messages
-
Unable to create Sales order from "BAPI_SALESORDER_CREATEFROMDAT2" for Free Goods
Hi Experts,
I am facing the issue while creating the Sales order through "BAPI_SALESORDER_CREATEFROMDAT2" , all is going well in normal cases but when I process the contract with FREE GOODS line items for which free goods condition record is maintained it fails to create the Sales order. Is there any special treatment for this Free goods case. Is there any Flag to be passed from BAPI?
Regards,Hi Paaavan
You can set a break-point include "FV45PFAP_VBAP_BEARBEITEN_VORBE" that is called by both the SAP Standard and BAPI where the data is prepared and checked in the internal table XVBAP. Compare both SAP standard VA01 and your 'Z' program for what may be different in XVBAP.
I think the problem my be with regards to the business_object number that is hardcoded in the standard function module. It has given me issues before and hence I tend to use the function module SD_SALESDOCUMENT_CREATE to create sales documents with.
Regards,
Marius -
Create sales order with BAPI_SALESORDER_CREATEFROMDAT2 example
Hi, does anyone have a working example of how to create a sales order using BAPI_SALESORDER_CREATEFROMDAT2?
Thankshi Robert,
Check this code...try to map.
one order with total sum of effort
clear: l_order_header,
l_salesdocument,
l_order_partners,
l_order_items,
l_order_schdl.
refresh: it_order_items,
it_order_partners,
it_order_schdl,
it_return.
???????? get from material ...
Order header
l_order_header-doc_type = 'ZQBV'.
l_order_header-distr_chan = '10'.
l_order_header-division = '00'.
if g_qals-werk eq '1100'.
l_order_header-sales_org = '1000'.
else.
if g_qals-werk eq '3100'.
l_order_header-sales_org = '3000'.
else.
message i001(00) with text-005.
endif.
endif.
l_order_header-purch_no_c = g_qals-prueflos. " <= lot
Partner data
l_order_partners-partn_role = 'AG'.
l_order_partners-partn_numb = g_qals-kunnr.
append l_order_partners to it_order_partners.
Order items => only one
l_order_items-itm_number = 10.
l_order_items-material = g_qals-matnr.
l_order_items-target_qty = 1.
append l_order_items to it_order_items.
Schedules for quantity
l_order_schdl-itm_number = 10.
l_order_schdl-req_qty = 1. " <= only 1 !
append l_order_schdl to it_order_schdl.
Conditions for value
l_order_conditions-itm_number = 10.
l_order_conditions-cond_type = 'PR00'.
l_order_conditions-cond_value = g_effort_sum.
l_order_conditions-currency = g_effort_unit.
append l_order_conditions to it_order_conditions.
BAPI to create sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
SALESDOCUMENTIN =
ORDER_HEADER_IN = l_order_header
ORDER_HEADER_INX =
SENDER =
BINARY_RELATIONSHIPTYPE =
INT_NUMBER_ASSIGNMENT =
BEHAVE_WHEN_ERROR =
LOGIC_SWITCH =
TESTRUN =
CONVERT = ' '
IMPORTING
SALESDOCUMENT = l_salesdocument
TABLES
RETURN = it_return
ORDER_ITEMS_IN = it_order_items
ORDER_ITEMS_INX =
ORDER_PARTNERS = it_order_partners
ORDER_SCHEDULES_IN = it_order_schdl
ORDER_SCHEDULES_INX =
ORDER_CONDITIONS_IN = it_order_conditions
ORDER_CONDITIONS_INX =
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 =
ORDER_KEYS =
EXTENSIONIN =
PARTNERADDRESSES =
if not l_salesdocument is initial.
order successfully created
message i001(00) with text-001 l_salesdocument.
endif.
endif.
for more info check the below link also
Problem with BAPI_SALESORDER_CREATEFROMDAT2
Regards,
Naveen -
Clear WBS field in sales order using bapi_salesorder_createfromdat2.
Hi,
Situation is this, I have a sales order, where the WBS element in the line item is populated. I want to clear that field to blank and save the sales order.
When I try to do that using the bapi_salesorder_createfromdat2, it says that it is successful, but when I go back to the sales order and see that field is still populated and not cleared. But the same field if I clear it through VA02 it works fine.
Header level update flag is set as 'U'.
I have tried setting up 'D' 'U' and 'I' for the update flag for the line item. Still no luck.
Given below is the sample code, did anybody else also faced the same issue.
Data Section.
data : sal_t_in type standard table of BAPISDHD1,
sal_s_in like line of sal_t_in.
*data : sal_t_in type standard table of BAPISDH1,
* sal_s_in like line of sal_t_in.
data : ret_t type standard table of bapiret2,
ret_s like line of ret_t.
data : partner_t type standard table of bapiparnr,
partner_s like line of partner_t.
data : item_t type standard table of bapisditm,
item_s like line of item_t.
data : item_t_inx type standard table of BAPISDITMX,
item_s_inx like line of item_t_inx.
data : schdl_t type standard table of BAPISCHDL,
schdl_s like line of schdl_t.
data : schdl_t_inx type standard table of BAPISCHDLX,
schdl_s_inx like line of schdl_t_inx.
data : ord_view type order_view.
data : sal_t_key type standard table of sales_key,
sal_s_key like line of sal_t_key.
data : ord_t_hdr type standard table of bapisdhd,
ord_s_hdr like line of ord_t_hdr.
data : ord_t_itm type standard table of bapisdit,
ord_s_itm like line of ord_t_itm.
data : hdr_inx type BAPISDHD1X.
data : hdr2_inx type BAPISDH1X.
data : qty type DZMENG.
data : logic_switch type BAPISDLS.
data : sd_doc_out type BAPIVBELN-VBELN.
data : sd_hdr_out type BAPISDHD.
data : sd_hdr_stat type BAPISDHDST.
Logic Section.
sal_s_in-doc_type = 'ZOR'.
hdr_inx-updateflag = 'U'.
ord_view-header = 'X'.
ord_view-item = 'X'.
sal_s_key-vbeln = '0000001067'.
append sal_s_key to sal_t_key.
call function 'BAPISDORDER_GETDETAILEDLIST'
exporting
i_bapi_view = ord_view
* I_MEMORY_READ =
tables
sales_documents = sal_t_key
ORDER_HEADERS_OUT = ord_t_hdr
ORDER_ITEMS_OUT = ord_t_itm
* ORDER_SCHEDULES_OUT =
* ORDER_BUSINESS_OUT =
* ORDER_PARTNERS_OUT =
* ORDER_ADDRESS_OUT =
* ORDER_STATUSHEADERS_OUT =
* ORDER_STATUSITEMS_OUT =
* ORDER_CONDITIONS_OUT =
* ORDER_COND_HEAD =
* ORDER_COND_ITEM =
* ORDER_COND_QTY_SCALE =
* ORDER_COND_VAL_SCALE =
* ORDER_CONTRACTS_OUT =
* ORDER_TEXTHEADERS_OUT =
* ORDER_TEXTLINES_OUT =
* ORDER_FLOWS_OUT =
* ORDER_CFGS_CUREFS_OUT =
* ORDER_CFGS_CUCFGS_OUT =
* ORDER_CFGS_CUINS_OUT =
* ORDER_CFGS_CUPRTS_OUT =
* ORDER_CFGS_CUVALS_OUT =
* ORDER_CFGS_CUBLBS_OUT =
* ORDER_CFGS_CUVKS_OUT =
* ORDER_BILLINGPLANS_OUT =
* ORDER_BILLINGDATES_OUT =
* ORDER_CREDITCARDS_OUT =
* EXTENSIONOUT =
loop at ord_t_itm into ord_s_itm.
move-corresponding ord_s_itm to item_s.
call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
exporting
input = item_s-WBS_ELEM
IMPORTING
OUTPUT = item_s-WBS_ELEM
*move space to item_s-WBS_ELEM.
append item_s to item_t.
endloop.
clear item_s_inx.
item_s_inx-updateflag = 'D'.
item_s_inx-wbs_elem = 'X'.
append item_s_inx to item_t_inx.
call function 'BAPI_SALESORDER_CREATEFROMDAT2'
exporting
SALESDOCUMENTIN = '0000001067'
order_header_in = sal_s_in
ORDER_HEADER_INX = hdr_inx
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ' '
* IMPORTING
* SALESDOCUMENT =
tables
RETURN = ret_t
ORDER_ITEMS_IN = item_t
ORDER_ITEMS_INX = item_t_inx
order_partners = partner_t
* ORDER_SCHEDULES_IN =
* ORDER_SCHEDULES_INX =
* ORDER_CONDITIONS_IN =
* ORDER_CONDITIONS_INX =
* 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 =
* ORDER_KEYS =
* EXTENSIONIN =
* PARTNERADDRESSES =
call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
Result I get when I execute is
S V4 233 SALES_HEADER_IN has been processed successfully VBAKKOM
S V4 233 SALES_ITEM_IN has been processed successfully VBAPKOM 000001
S V1 311 Standard order 1067 has been saved Standard order 1067
Which means it says it save successfully..but data is not changed.
Any Ideas??
Thanks and Regards,
Mahesh.Hi,
The problem is fixed. The item inx table I was not passing the item number field, so the bapi was not knowing which line item to update.
It was a stupid overlook on my part.
Thanks and Regards,
Mahesh. -
Changing PSTYV in sales order with BAPI_SALESORDER_CREATEFROMDAT2
hi all,
I'm having this trouble...
we are creating a Sales Order from PI calling directly the BAPI_SALESORDER_CREATEFROMDAT2...
but, theres a field than I have to change... the PSTYV must be TANN when the VBAP-NETWR is 0.
I've used the MV45AFZZ program for the exit... but no in the move_field_to_vbap ('cause it doesn't work form me), I used this one:
FORM USEREXIT_SAVE_DOCUMENT_PREPARE.
data: l_tabix type i VALUE 0.
if xvbak-AUART = 'ZCO'.
loop at xvbap.
add 1 to l_tabix.
if xvbap-netwr EQ 0.
xvbap-PSTYV = 'TANN'.
modify xvbap index l_tabix TRANSPORTING pstyv .
endif.
endloop.
endif.
ENDFORM.
and with this, when the sales order is created, my PSTYV field if NETWR = 0, now is TANN.... but this is NOT the solution 'cause I can't make an Invoice... I have an incompletion LOG....
but, if I change the field manually appears a message: New pricing carried out ( Message no. V1209 ).
and with this... I fix the problem.... but, you can see than I need it automatically....
so I think, than with my exit, I'm only changing the PSTYV value, but no all the changes than this need...
thanks in advance...
Regards..Apart from that and also
ORDER_ITEMS_IN-ITEM_CATEG = " Value here
ORDER_ITEMS_INX-ITEM_CATEG = " Value here
a® -
Query in creating Sales Order with BAPI_SALESORDER_CREATEFROMDAT2?
Hi,
I am trying to create a Sales Order with the BAPI and have a contract as a reference. Do I need to explicity mention the line item details in case I need the data from Contract to be copied here. If not how do I acheive this functionality.
P.S: I am able to create the Sales Order with the reference and I can see the Sales Order in the contracts workflow but not the line items in the Sales Order.
Any suggestions?
Regards,
KarthikHello, Karthik,
By reading the documentation of BAPI
BAPI_SALESORDER_CREATEFROMDAT2
the mandatory data to be supplied to the BAPI, in order to succesfuly create the the Sales Order are:
"1. ORDER_HEADER_IN :
DOC_TYPE Sales document type
SALES_ORG Sales organization
DISTR_CHAN Distribution channel
DIVISION Division
2. ORDER_PARTNERS..:
PARTN_ROLE Partner role, SP sold-to party
PARTN_NUMB Customer number
3. ORDER_ITEMS_IN..: MATERIAL Material number"
The OSS note 93091 basically re-states the same thing.
After studying this BAPI's source code, the conclusion seems to be the one the documentation points to: <b>the BAPI can only be used to create a sales order by supplying (manually) all the necessary data.</b>
BTW: How did you manage to create the empty Sales Order with reference, you mentioned in your mail? Just by providing a reference document number? <b>And nothing more?</b>
Bye,
Bogdan -
Error when creating sales order using BAPI_SALESORDER_CREATEFROMDAT2
Hello!
I am using BAPI_SALESORDER_CREATEFROMDAT2 for creating the Sales order. But I have a problem when Iu2019m trying to create configuration. I think that parameter order_items_in-material should be generated before calling BAPI described above. I try to use order_items_in-mat_entrd, but BAPI return error message id = V1, number = 320 (No item category available (Table T184 ZAPC TEXT )).
Help me please, How I can solve this problem?<P><STRONG>FUNCTION Z_SD_GET_TEH_COST.<BR>"----<BR>" IMPORTING<BR>" REFERENCE(IS_COST_ORDER) TYPE ZWCLIF_COST_ORDER<BR>" EXPORTING<BR>" REFERENCE(EV_KBETR) TYPE KBETR<BR>"----
</STRONG></P>
<P><STRONG> DEFINE fill_prizn.<BR> IF is_cost_order-&1 IS NOT INITIAL.<BR> CLEAR: ls_cfgs_value-charc,<BR> ls_cfgs_value-value.<BR> ls_cfgs_value-charc = &2.<BR> ls_cfgs_value-value = is_cost_order-&1.<BR>* ls_cfgs_value-valcode = '1'.<BR> APPEND ls_cfgs_value TO lt_cfgs_value.<BR> ENDIF.<BR> END-OF-DEFINITION.</STRONG></P>
<P><STRONG>DATA: ls_header_in TYPE bapisdhd1,<BR> ls_header_inx TYPE bapisdhd1x,</STRONG></P>
<P><STRONG> lt_partners TYPE TABLE OF bapiparnr,<BR> ls_partners TYPE bapiparnr,</STRONG></P>
<P><STRONG> lt_items_in TYPE TABLE OF bapisditm,<BR> lt_items_inx TYPE TABLE OF bapisditmx,</STRONG></P>
<P><STRONG> ls_items_in TYPE bapisditm,<BR> ls_items_inx TYPE bapisditmx,</STRONG></P>
<P><STRONG> ls_cfgs_ref TYPE bapicucfg,<BR> lt_cfgs_ref TYPE TABLE OF bapicucfg,</STRONG></P>
<P><STRONG> lt_cfgs_value TYPE TABLE OF bapicuval,<BR> ls_cfgs_value TYPE bapicuval,</STRONG></P>
<P><STRONG> lt_schedules_in TYPE TABLE OF bapischdl,<BR> ls_schedules_in TYPE bapischdl,</STRONG></P>
<P><STRONG> lt_schedules_inx TYPE TABLE OF bapischdlx,<BR> ls_schedules_inx TYPE bapischdlx,</STRONG></P>
<P><STRONG> lt_cfgs_inst TYPE TABLE OF bapicuins,<BR> ls_cfgs_inst TYPE bapicuins,<BR> lt_cfgs_partof TYPE TABLE OF bapicuprt,<BR> ls_cfgs_partof TYPE bapicuprt,</STRONG></P>
<P><STRONG> lv_vbeln TYPE bapivbeln-vbeln,<BR> lt_return TYPE TABLE OF bapiret2.</STRONG></P>
<P><STRONG>* fill header<BR> ls_header_in-doc_type = 'ZAPC'.<BR> ls_header_in-sales_org = is_cost_order-vkorg.<BR> ls_header_in-distr_chan = is_cost_order-vtweg.<BR> ls_header_in-division = '01'.<BR> ls_header_in-sales_off = '1011'.</STRONG></P>
<P><STRONG> ls_header_inx-updateflag = 'I'.<BR> ls_header_inx-doc_type = 'X'.<BR> ls_header_inx-sales_org = 'X'.<BR> ls_header_inx-distr_chan = 'X'.<BR> ls_header_inx-division = 'X'.<BR> ls_header_inx-sales_off = 'X'.</STRONG></P>
<P><STRONG>* fill partners<BR> ls_partners-partn_role = 'AG'.<BR> ls_partners-partn_numb = '1000000031'. " фиктивный заказчик<BR> APPEND ls_partners TO lt_partners.</STRONG></P>
<P><STRONG>* ls_items_in-material = is_cost_order-matnr.<BR> ls_items_in-mat_entrd = is_cost_order-matnr.<BR> ls_items_in-target_qty = '1'.<BR> ls_items_in-itm_number = '000001'.<BR> ls_items_in-po_itm_no = '000001'.<BR> ls_items_in-item_categ = 'ZCRM'.<BR> SELECT SINGLE meins INTO ls_items_in-target_qu<BR> FROM mara<BR> WHERE matnr = is_cost_order-matnr.<BR> APPEND ls_items_in TO lt_items_in.</STRONG></P>
<P><STRONG> ls_items_inx-itm_number = '000001'.<BR> ls_items_inx-item_categ = 'X'.<BR> ls_items_inx-po_itm_no = 'X'.<BR>* ls_items_inx-material = 'X'.<BR> ls_items_inx-mat_entrd = 'X'.<BR> ls_items_inx-target_qty = 'X'.<BR> ls_items_inx-target_qu = 'X'.<BR> ls_items_inx-updateflag = 'I'.<BR> APPEND ls_items_inx TO lt_items_inx.</STRONG></P>
<P><STRONG>* fill configuration<BR> ls_cfgs_ref-posex = '000001'.<BR> ls_cfgs_ref-config_id = '000001'.<BR> ls_cfgs_ref-root_id = '00000001'.<BR> APPEND ls_cfgs_ref TO lt_cfgs_ref.</STRONG></P>
<P><STRONG> ls_cfgs_value-config_id = '000001'.<BR> ls_cfgs_value-inst_id = '00000001'.</STRONG></P>
<P><STRONG> fill_prizn kod_prod 'KOD_PROD'.<BR> fill_prizn tlot_min 'TLOT_MIN'.<BR> fill_prizn tlot_max 'TLOT_MAX'.<BR> fill_prizn shot_min 'SHOT_MIN'.<BR> fill_prizn shot_max 'SHOT_MAX'.<BR> fill_prizn dlot_min 'DLOT_MIN'.<BR> fill_prizn dlot_max 'DLOT_MAX'.<BR> fill_prizn marka 'MARKA'.<BR> fill_prizn stndrt_marka 'STNDRT_MARKA'.<BR> fill_prizn stndrt_prod 'STNDRT_PROD'.<BR> fill_prizn tprk 'TPRK'.<BR> fill_prizn grot 'GROT'.<BR> fill_prizn vityazhka 'VITYAZHKA'.<BR> fill_prizn krom 'KROM'.<BR> fill_prizn chisl_st_pokr 'CHISL_ST_POKR'.<BR> fill_prizn kls_tol_pokr 'KLS_TOL_POKR'.<BR> fill_prizn proch_izg_t_lic_max 'PROCH_IZG_T_LIC_MAX'.<BR> fill_prizn priz_zasch_pov 'PRIZ_ZASCH_POV'.<BR> fill_prizn vid_pokr 'VID_POKR'.<BR> fill_prizn mark_pokr 'MARK_POKR'.<BR> fill_prizn mat_pokr_lic 'MAT_POKR_LIC'.<BR> fill_prizn plsk 'PLSK'.<BR> fill_prizn vid_postavki 'VID_POSTAVKI'.<BR> fill_prizn dressir 'DRESSIR'.<BR> fill_prizn travl 'TRAVL'.<BR> fill_prizn fsfr_min 'FSFR_MIN'.<BR> fill_prizn fsfr_max 'FSFR_MAX'.<BR> fill_prizn krmn_min 'KRMN_MIN'.<BR> fill_prizn krmn_max 'KRMN_MAX'.<BR> fill_prizn mrgn_min 'MRGN_MIN'.<BR> fill_prizn mrgn_max 'MRGN_MAX'.<BR> fill_prizn almn_min 'ALMN_MIN'.<BR> fill_prizn almn_max 'ALMN_MAX'.<BR> fill_prizn cugl_min 'CUGL_MIN'.<BR> fill_prizn cugl_max 'CUGL_MAX'.</STRONG></P>
<P><STRONG> ls_schedules_in-itm_number = '000001'.<BR>* ls_schedules_in-req_date = sy-datum.<BR> ls_schedules_in-sched_line = '0001'.<BR> ls_schedules_in-req_qty = '1'.<BR> APPEND ls_schedules_in TO lt_schedules_in.</STRONG></P>
<P><STRONG> ls_schedules_inx-itm_number = '000001'.<BR> ls_schedules_inx-sched_line = '0001'.<BR>* ls_schedules_inx-req_date = 'X'.<BR> ls_schedules_inx-req_qty = 'X'.<BR> ls_schedules_inx-updateflag = 'I'.<BR> APPEND ls_schedules_inx TO lt_schedules_inx.</STRONG></P>
<P><STRONG> ls_cfgs_partof-parent_id = '00000001'.<BR> ls_cfgs_partof-inst_id = '00000001'.<BR> ls_cfgs_partof-class_type = '300'.<BR> ls_cfgs_partof-obj_type = 'MARA'.<BR> ls_cfgs_partof-obj_key = is_cost_order-matnr.<BR> APPEND ls_cfgs_partof TO lt_cfgs_partof.</STRONG></P>
<P><STRONG> ls_cfgs_inst-config_id = '000001'.<BR> ls_cfgs_inst-inst_id = '00000001'.<BR> ls_cfgs_inst-obj_type = 'MARA'.<BR> ls_cfgs_inst-class_type = '300'.<BR> ls_cfgs_inst-obj_key = is_cost_order-matnr.<BR> APPEND ls_cfgs_inst TO lt_cfgs_inst.</STRONG></P>
<P><STRONG> CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'<BR> EXPORTING<BR> order_header_in = ls_header_in<BR> order_header_inx = ls_header_inx<BR>* testrun =<BR> IMPORTING<BR> salesdocument = lv_vbeln<BR> TABLES<BR> return = lt_return<BR> order_items_in = lt_items_in<BR> order_items_inx = lt_items_inx<BR> order_partners = lt_partners<BR> order_schedules_in = lt_schedules_in<BR> order_schedules_inx = lt_schedules_inx<BR> order_cfgs_ref = lt_cfgs_ref<BR> order_cfgs_inst = lt_cfgs_inst<BR> order_cfgs_part_of = lt_cfgs_partof<BR> order_cfgs_value = lt_cfgs_value<BR> .</STRONG></P>
<P><STRONG> READ TABLE lt_return TRANSPORTING NO FIELDS WITH KEY type = 'E'.<BR> IF sy-subrc = 0.<BR> CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'<BR> .<BR> ELSE.<BR> CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'<BR> EXPORTING<BR> wait = 'X'<BR> .<BR> ENDIF.</STRONG></P>
<P><STRONG>ENDFUNCTION.</STRONG></P>
<P><STRONG></STRONG> </P>
<P><STRONG></STRONG> </P> -
Creating Sales Order using BAPI_SALESORDER_CREATEFROMDAT2
Hi All,
I am having problem while creating a SO using the BAPI_SALESORDER_CREATEFROMDAT2, Its returning sales documnet type is not defined. I used to get the error to speciy the ship to party or sold party earlier that has been resloved now I am getting the above specifed error.
Please help me its very urgent
Thanks,
SumaHi Suma
While populating data for Sales Order Creation, populate PARTNER table with Sold-To or Ship-To as per you business process.
Minimum two fields are to the fields for this structure:PARTN_ROLE , PARTN_NUMB
PARTN_ROLE ---> " Partner Role, which specifies the partner type i.e Sold-To, Ship-To, Bill-To ...
ARTN_NUMB ---> " Customer Number
Regards
Eswar -
Error in Creating Sales Order Using BAPI_SALESORDER_CREATEFROMDAT2
Hi Everyone,
We have a requirement to create sales order from flat file using BAPI. Everything was working well until we encounter a customer with credit control limit setup.
Using the partners table for BAPi, the sold to customer is enter at header level, and we have this requirement to add the payer at item level. This is where the error is occuring. Upon debugging, I found out that the customer has a credit limit setup at FD33, and has a record found in KNKK, which is giving the error "Credit limit customer differs from credit limit customer in header".
However, duting manual creation of sales order via VA01, this error is not encountered.
Any ideas or suggesstions on how we can move forward with SO creation using BAPI with customers where credit management is setup?
Thanks,
LouisseIf thats not working..
try BAPI_SALESORDER_CREATEFROMDAT2
If BAPI is not working. try creating a bdc for the same if there's not error on trying from VA01 -
Problem when creating a sales order using BAPI_SALESORDER_CREATEFROMDAT2
Hello All,
I am working on a requirement where i need to create a new sales order from old sales order (Not all the items of the old sales order are to be copied) i am doing this by getting the data using BAPISDORDER_GETDETAILEDLIST to get the old sales order details and send them to BAPI_SALESORDER_CREATEFROMDAT2.
My problem is that i when i send the condition also the system in addition to the conditions sent to the BAPI is also automatically proposing the condition types . So the final result is that the sales order ends up having the condition types twice .
For example VPRS AZWR are visible twice in the sales order.
Any inputs to solve the problem will be definitely rewarded.
Thanks in advance.
Regards,
Sowmya.Hello All,
I am working on a requirement where i need to create a new sales order from old sales order (Not all the items of the old sales order are to be copied) i am doing this by getting the data using BAPISDORDER_GETDETAILEDLIST to get the old sales order details and send them to BAPI_SALESORDER_CREATEFROMDAT2.
My problem is that i when i send the condition also the system in addition to the conditions sent to the BAPI is also automatically proposing the condition types . So the final result is that the sales order ends up having the condition types twice .
For example VPRS AZWR are visible twice in the sales order.
Any inputs to solve the problem will be definitely rewarded.
Thanks in advance.
Regards,
Sowmya. -
Quantity update into sales order using BAPI_SALESORDER_CREATEFROMDAT2
Hi All,
I am able to create a sales order using the BAPI "BAPI_SALESORDER_CREATEFROMDAT2".
But even after assinging the Target_quntity and the Target_quantity_units, the values are not getting updated into the Sales order, but the sales order gets created .
Did anyone of you had a similare problem, how was it solved.
cold some one please help me out on this.
RegardsHi
I had used below code (using <b>BAPI_SALESORDER_CREATEFROMDAT1</b>)..but never faced any problem.. you can try the same...
Regards,
Raj
REPORT z_sd_salesorder_create
NO STANDARD PAGE HEADING
LINE-SIZE 150
MESSAGE-ID zz.
S T R U C T U R E D E C L A R A T I O N S *
TYPES: BEGIN OF x_ppl,
ppl_order(18), " ppl Orderno
auart(4), " Sales Doc Type
vkorg(4), " Sales Organization
vtweg(2), " Distribution Channel
spart(2), " Division
div(3), " Division
kunnr(10), " Sold-to Party
date(10), " Doc Dt
matnr(18), " Item Matnr#
uom(3), " UOM
qty(15), " Qty
kschl(4), " Pricing condiiton type
kbetr(11), " Rate
END OF x_ppl.
TYPES: BEGIN OF x_file,
loc(30), " Location
div(3), " Division
ppl_order(18), " ppl Orderno
kunnr(10), " Sold-to Party
date(10), " Doc Dt
matnr(20), " Item Matnr#
qty(15), " Qty
uom(3), " UOM
kbetr(11), " Rate
discount(5), " Discount
END OF x_file.
TYPES: BEGIN OF x_output,
ppl_order(18), " ppl Orderno
mesg(130), " Mesg Success/Error
END OF x_output.
TYPES: BEGIN OF x_werks,
name2(30), " Location
werks TYPE werks_ext, " Plant
END OF x_werks.
TYPES: BEGIN OF x_info,
vkorg TYPE vkorg , " Sales org
vtweg TYPE vtweg, " Dist channel
werks TYPE werks_ext," Plant
spart TYPE spart, " Storage Loc
END OF x_info.
TYPES: BEGIN OF x_material,
ppl_prdid(20), " ppl Prd id
matnr TYPE matnr, " Material (SAP)
END OF x_material.
I N T E R N A L T A B L E D E C L A R A T I O N S *
DATA: it_file TYPE STANDARD TABLE OF x_file WITH HEADER LINE." File Data
DATA: it_data TYPE STANDARD TABLE OF x_ppl WITH HEADER LINE." ppl File
DATA: it_out TYPE STANDARD TABLE OF x_output WITH HEADER LINE. " Outcome
DATA: it_werks TYPE STANDARD TABLE OF x_werks WITH HEADER LINE. " Plant
DATA: it_info TYPE STANDARD TABLE OF x_info WITH HEADER LINE. " Othr Info
DATA: it_matnr TYPE STANDARD TABLE OF x_material WITH HEADER LINE. " Material Info
DATA: it_item TYPE STANDARD TABLE OF bapiitemin WITH HEADER LINE. "Order Itm data
DATA: it_partner TYPE STANDARD TABLE OF bapipartnr WITH HEADER LINE. "Order Partner data
V A R I A B L E S D E C L A R A T I O N S *
DATA : v_correct TYPE i,
v_error TYPE i,
v_total TYPE i,
v_return LIKE bapireturn1,
v_index LIKE sy-tabix.
*- Return values
DATA: it_orderh TYPE bapisdhead, "Order Hdr data
order TYPE bapivbeln-vbeln,
soldto TYPE bapisoldto,
shipto TYPE bapishipto,
return TYPE bapireturn1.
DATA: hdate TYPE sy-datum.
U S E R I N P U T S S C R E E N *
SELECTION-SCREEN: BEGIN OF BLOCK blk01 WITH FRAME TITLE text-t01.
PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY. " File name
SELECTION-SCREEN END OF BLOCK blk01.
S E L E C T I O N S C R E E N *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_file.
S t a r t o f S e l e c t i o n *
START-OF-SELECTION.
PERFORM get_upload.
PERFORM validate_data. " Validate the data
PERFORM data_swap. " Prepare the data for processing
IF NOT it_data[] IS INITIAL.
PERFORM get_update. " Create SalesOrders
ELSE.
MESSAGE i001(zz) WITH text-001.
STOP.
ENDIF.
E n d o f S e l e c t i o n *
END-OF-SELECTION.
IF NOT it_data[] IS INITIAL.
PERFORM get_write.
ENDIF.
*& Form get_file
Get File name
FORM get_file .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = syst-repid
mask = '*'
CHANGING
file_name = p_file
EXCEPTIONS
mask_too_long = 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.
ENDFORM. " get_file
*& Form get_upload
to upload the file
FORM get_upload .
DATA l_file TYPE string.
CLEAR: it_file, it_file[].
l_file = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_file
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSEIF sy-subrc = 0.
SORT it_file BY loc ppl_order.
ENDIF.
ENDFORM. " get_upload
*& Form get_update
Creating mapping Data in Z table
FORM get_update .
DATA: l_itemno(2) TYPE n,
l_partner TYPE parvw,
l_kunnr TYPE kunnr,
l_matnr TYPE matnr,
l_mesg TYPE string,
l_kbetr TYPE p DECIMALS 2.
DATA: l_in_qty LIKE vbap-zmeng,
l_meins LIKE mara-meins,
l_qty LIKE vbap-zmeng.
CLEAR: v_correct, v_error, v_total.
SORT it_data BY ppl_order.
LOOP AT it_data.
CLEAR v_index.
v_index = sy-tabix.
*- New SalesOrder
AT NEW ppl_order.
READ TABLE it_data INDEX v_index.
CLEAR: it_orderh, it_item, it_partner,
order, soldto, shipto, return,
it_item[], it_partner[].
v_total = v_total + 1. "Increment Total SalesOrders counter
CLEAR l_itemno.
l_itemno = '10'.
*- Covert date fields into Internal format
CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
EXPORTING
datum = it_data-date
dtype = 'DATS'
IMPORTING
idate = it_data-date.
*- Populate SalesOrder header data.
CALL FUNCTION 'CONVERSION_EXIT_AUART_INPUT'
EXPORTING
input = it_data-auart
IMPORTING
output = it_data-auart.
it_orderh-doc_type = it_data-auart.
it_orderh-sales_org = it_data-vkorg.
it_orderh-distr_chan = it_data-vtweg.
it_orderh-division = it_data-spart.
it_orderh-purch_no = 'DEPOT'.
it_orderh-price_date = it_data-date. "Doc Dt
it_orderh-req_date_h = it_data-date. "Del.Dt
it_orderh-purch_no_s = it_data-ppl_order.
*- Partner data
CLEAR: l_partner, l_kunnr.
*- Convert Partner type into internal format
l_partner = 'SP'. "SoldTo Party
CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
EXPORTING
input = l_partner
IMPORTING
output = l_partner.
*- Convert Customer into internal format
l_kunnr = it_data-kunnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_kunnr
IMPORTING
output = l_kunnr.
it_partner-partn_role = l_partner.
it_partner-partn_numb = l_kunnr.
APPEND it_partner.
CLEAR it_partner.
ENDAT.
*- Item data
it_item-itm_number = l_itemno.
*- Convert material number into internal format
CLEAR l_matnr.
l_matnr = it_data-matnr.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = l_matnr
IMPORTING
output = l_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.
it_item-material = l_matnr.
*- Call FM to get new qty based on SAP UOM
CLEAR: l_meins, l_qty, l_in_qty.
l_in_qty = it_data-qty.
CALL FUNCTION 'Z_GET_QTY_FROM_UOM'
EXPORTING
matnr = it_item-material
in_meins = it_data-uom
in_qty = l_in_qty
IMPORTING
out_meins = l_meins
quantity = l_qty.
IF sy-subrc = 0.
it_data-qty = l_qty.
it_data-uom = l_meins.
ENDIF.
it_data-qty = it_data-qty * 1000.
it_item-req_qty = it_data-qty.
it_item-sales_unit = it_data-uom.
it_item-req_date = it_data-date.
*- Pricing data
it_item-cond_type = it_data-kschl. "Pricing condition
CLEAR l_kbetr.
l_kbetr = it_data-kbetr / 10. "Price (Rate)
it_item-cond_value = l_kbetr.
APPEND it_item.
CLEAR it_item.
*- Increment Item counter.
l_itemno = l_itemno + 10.
*- At end of SalesOrder
AT END OF ppl_order.
READ TABLE it_data INDEX v_index.
*- Call the BAPI for SalesOrder creation
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
EXPORTING
order_header_in = it_orderh
IMPORTING
salesdocument = order
sold_to_party = soldto
ship_to_party = shipto
return = return
TABLES
order_items_in = it_item
order_partners = it_partner.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
v_return = return+0(1).
IF v_return = 'E'.
v_error = v_error + 1.
CLEAR l_mesg.
l_mesg = return.
CONDENSE l_mesg.
ELSE.
v_correct = v_correct + 1.
CLEAR l_mesg.
CONCATENATE 'Salesorder'(007) order 'successfully created.'(008)
INTO l_mesg SEPARATED BY space.
CONDENSE l_mesg.
ENDIF.
*- Populate the output table
CLEAR it_out.
it_out-ppl_order = it_data-ppl_order.
it_out-mesg = l_mesg.
APPEND it_out.
CLEAR it_out.
ENDAT.
ENDLOOP.
ENDFORM. " get_update
*& Form get_write
Write the results
FORM get_write .
WRITE:/ 'Total Number of Records :'(002), v_total COLOR 1.
WRITE:/ 'Total Correct Records :'(003), v_correct COLOR 3.
WRITE:/ 'Total Error Records :'(004), v_error COLOR 6.
SKIP 3.
IF NOT it_out[] IS INITIAL.
WRITE:/5 'ppl Order #'(005),
28 'Message'(006).
ENDIF.
SKIP 1.
LOOP AT it_out.
WRITE:/5 it_out-ppl_order,
28 it_out-mesg.
ENDLOOP.
ENDFORM. " get_write
*& Form validate_data
Validate the data
FORM validate_data .
DATA: l_bstkde TYPE bstkd_e.
LOOP AT it_file.
SELECT bstkd_e INTO l_bstkde
UP TO 1 ROWS
FROM vbkd
WHERE bstkd_e = it_file-ppl_order.
ENDSELECT.
IF sy-subrc = 0. " This ppl Order is already been created in SAP, so delete record
DELETE it_file.
ENDIF.
ENDLOOP.
SORT it_file BY ppl_order.
ENDFORM. " validate_data
*& Form data_swap
Prepare the data for processing
FORM data_swap .
CLEAR: it_werks, it_info, it_matnr, it_data,
it_werks[], it_info[], it_matnr[], it_data[].
IF NOT it_file[] IS INITIAL.
*- Get the plant from location
SELECT name2
werks
INTO CORRESPONDING FIELDS OF TABLE it_werks
FROM t001w FOR ALL ENTRIES IN it_file
WHERE name2 = it_file-loc.
IF sy-subrc = 0.
SORT it_werks BY name2 werks.
*- Get the Sales Org, Division and Distribution Channel
IF NOT it_werks[] IS INITIAL.
SELECT vkorg
vtweg
werks
INTO CORRESPONDING FIELDS OF TABLE it_info
FROM tvkwz FOR ALL ENTRIES IN it_werks
WHERE werks = it_werks-werks.
IF sy-subrc = 0.
LOOP AT it_info.
it_info-spart = '99'.
MODIFY it_info INDEX sy-tabix.
ENDLOOP.
SORT it_info BY vkorg vtweg werks.
ENDIF.
ENDIF.
ENDIF.
*- Get material from ppl material
SELECT ppl_prdid
matnr
FROM zppl_master
INTO TABLE it_matnr FOR ALL ENTRIES IN it_file
WHERE ppl_prdid = it_file-matnr.
IF sy-subrc = 0.
SORT it_matnr BY ppl_prdid matnr.
ENDIF.
ENDIF.
*- Update the data in it_data
LOOP AT it_file.
CLEAR it_data.
it_data-auart = 'OR'.
it_data-auart = 'OR'. " CHANGED BY Jo ON 3103005
READ TABLE it_werks WITH KEY name2 = it_file-loc BINARY SEARCH.
IF sy-subrc = 0.
READ TABLE it_info WITH KEY werks = it_werks-werks BINARY SEARCH.
IF sy-subrc = 0.
it_data-vkorg = it_info-vkorg.
it_data-vtweg = it_info-vtweg.
ENDIF.
ENDIF.
*- Material
READ TABLE it_matnr WITH KEY ppl_prdid = it_file-matnr BINARY SEARCH.
IF sy-subrc = 0.
it_data-matnr = it_matnr-matnr.
ENDIF.
it_data-ppl_order = it_file-ppl_order.
it_data-date = it_file-date.
CONCATENATE it_file-kunnr it_file-loc+1(2) INTO it_data-kunnr.
it_data-qty = it_file-qty.
it_data-uom = it_file-uom.
it_data-kbetr = it_file-kbetr.
*- Pricing condition
it_data-kschl = 'PR00'.
CASE it_file-div.
WHEN 'BRN'.
it_data-div = '04'.
WHEN 'GEN'.
it_data-div = '03'.
WHEN 'IVF'.
it_data-div = '02'.
WHEN 'OPH'.
it_data-div = '01'.
ENDCASE.
it_data-spart = it_data-div.
APPEND it_data.
CLEAR it_data.
ENDLOOP.
ENDFORM. " data_swap -
Creating sales order with BAPI_SALESORDER_CREATEFROMDAT2
Hi,
I´m creating sale orders with the function BAPI_SALESORDER_CREATEFROMDAT2. If you create sales order manually over the transaction, the system will find the right delivery date for you, if you are typing a date too early, for example.
The same I need to do the BAPI. But if I´m running the BAPI without a date, it is creating a sales order without a BAPI.
How can I get the date, SAP finds out automatically, when creating sales orders over the transaction?
Thank you!Really no advices to that?
-
Updating Sales order with BAPI_SALESORDER_CREATEFROMDAT2
Hi All ,
I am not able to Update two Zfields in vbap using FM BAPI_SALESORDER_CREATEFROMDAT2, In create mode I am able to save values into those fields .
I have checked the fields in structures
ZZVBAP (append structure of VBAP)
ZZBAPE_VBAP (append structure of BAPE_VBAP)
ZZBAPE_VBAPX (append structure of BAPE_VBAPX)
ZZVBAPKOZ (append structure of VBAPKOZ)
ZZVBAPKOZX
what could be the other reason for these zfields not saving in update mode .
Thanks
Vinay KollaYou can use implicit enhancement to include new fields to be added in BAPI. Because in BAPI, field by field mapping is there. just find FM "sd_salesdocument_create" and then find where ITEM details are to be filled.
If you still have problem, reply back,,, because I just worked in thsi BAPI for same scenario. -
Error in BAPI_SALESORDER_CREATEFROMDAT2 to create sales order
Hi all,
I'm trying to create a sales order using bapi_salesorder_createfromdat2. I have given the import parameters as per the documentation. But i'm getting the following error messages from the return parameter
number message
233 SALES_HEADER_IN has been processed successfully
233 SALES_ITEM_IN has been processed succesfully
555 The sales document is not yet complete: Edit
311 Standard Order 73 has been saved
I gave the partner role (SP) and partner number in ORDERS_PARTNERS. But i din get any message regarding its processing.
Pls can anyone guide me to create sales order using this bapi.
Thanks & Regards,
Revathi.Hi
I Think there problem in passing data to function module some important data is missing
run the functional in se37 and pass the data and see the result i have created sale order by passing the value below
header-doc_type = 'ZS4'.
header-sales_org = wa_temp1-vkorg.
header-purch_no = wa_temp1-bstnk.
header-distr_chan = wa_temp1-vtweg.
header-division = wa_temp1-spart.
header-purch_no_s = wa_temp1-bstnk.
wa_partner-partn_role = 'AG'.
wa_partner-partn_numb = wa_temp1-kunnr.
APPEND wa_partner TO it_partner.
wa_partner-partn_role = 'WE'.
wa_partner-partn_numb = wa_temp1-kunnr.
APPEND wa_partner TO it_partner.
CLEAR: wa_partner.
wa_item-material = wa_temp2-matnr.
wa_item-plant = wa_temp2-werks.
wa_item-req_qty = wa_temp2-fkimg.
wa_item-target_qty = wa_temp2-fkimg.
APPEND wa_item TO it_item.
with regards
Nilesh -
Update sales order qty through BAPI_SALESORDER_CREATEFROMDAT2
HI
Can anybody help me out. I have the requirement for creating sales order through BAPI_SALESORDER_CREATEFROMDAT2. The sales order is created but with 0 quantity.
I am using fields RNDDLV_QTY and TARGET_QTY and REQ_QTY in schedule lines & also setting the update indicator to 'X' in the corresponding itemx structures.
In fact it used to work earlier and has stopped now. I am also checking if there could be any change in configuration but don't think this should be the reason.
Can someone guide me as to which quantity fields of the BAPI are the right ones to update sales order qty?
thanksHi,
You are using the correct fields i.e. TARGET_QTY and REQ_QTY. Just check if you are passing the same Item Number in both the tables.
Hope it helps...
Lokesh
Maybe you are looking for
-
Creative Cloud has an ObjC "leak" in latest Mac release
The latest download of the Mac Creative Cloud app has a bug. After receiving the latest CC (today) my system console continues to inform me of a "leak error" at the rate of abot four per minute. For example: "10/6/14 5:18:09.479 PM com.adobe.AdobeC
-
How can I see whether songs in iCloud are also on the PC locally (so I can sync them with a Classic)?
-
My iPod classic 80GB is recognised by my computer, but not by itunes.
I cant sync my iPod so cant update the music on it and dont know what to do. I've tried all the troubleshooting suggestions and nothing has worked. I miss my iPod and dont really want to have to buy a new one. Any help would be much appreciated. Than
-
Error in primary key generation
Hello, I am using Postgresql database with jboss. I am using sequence block pattern for generating automatic primary key using source code provided by ejbdesignpattern book. but when i use transaction attribute of RequiresNew for method getValueAfter
-
Does IP block list Providers protect Public Folders
Hi, Just a quick question about IP Block List Providers in exchange 2010. We have Spamhaus setup in the list, we just moved one of our customers over to DNS based mail and they have since been receiving a great deal of spam. Does IP block list Provi