Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI issue with Pruchase order

Former Member
0 Likes
1,447

I am creating SO using BAPI_SALESORDER_CREATEFROMDAT2.

I am filling

ORDER_HEADER_IN ( Doc type, sales org, dist, div, purc date, pmnts,purchorder)

and ORDER_PARTNERS (role and partner number) For both ship to and sold to.

When i run this bapi.. no sales order is created and also it gives no error msg.

It says Purchase order already exists 10056048(some number)..though i am mentioning the Purchase order as 'DummyPO'.

Can you please help me with this.

Everyhelpful ans will be rewarded

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,390

Did you use BAPI_TRANSACTION_COMMIT. This BAPI should be called immedieately after BAPI_SALESORDER_CREATEFROMDAT2 when the RETURN table does not contain error entries

13 REPLIES 13
Read only

Former Member
0 Likes
1,391

Did you use BAPI_TRANSACTION_COMMIT. This BAPI should be called immedieately after BAPI_SALESORDER_CREATEFROMDAT2 when the RETURN table does not contain error entries

Read only

0 Likes
1,390

Hi Naveen yes i do commit.. but at first place this bapi should return a sales order number right?

Read only

Former Member
0 Likes
1,390

Hello Kantheri,

CHeck this sample code for creatind SO.


See if this helps.

* 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. 

Regards,

Vasanth

Read only

0 Likes
1,390

Hi Vasanth, this what i am exactly doing..

only difference is i am giving item number as 1, 2, 3 instead of 10 20 30...

and i have not specified item-target_qty.

Will this make difference?

Read only

Former Member
0 Likes
1,390

Sorry, the warnin msg says that Purchase order number already exists in some other SO..

But still it shoudl create the new Sales order right?

Also i am providing

order_items_in (item number, material)

order_schedules_in (item number, reqd qty, req date)

order_conditions_in (blank)

order_text(item numb, text id, langu, text line)

Read only

0 Likes
1,390

Use 'BAPI_TRANSACTION_COMMIT' as below.

LOOP AT I_MAIN WHERE SOL_DOCNO = I_TAB-SOL_DOCNO.

IF I_MAIN-GI_TXN_TYPE = 'RMGI'.

itab-move_type = '291'.

ENDIF.

itab-mvt_ind = ' '.

itab-plant = I_MAIN-WERKS.

itab-material = I_MAIN-MATNR.

itab-entry_qnt = I_MAIN-ERFMG.

  • itab-stge_loc = 'OMR1'.

  • itab-move_stloc = pcitab-recv_loc.

itab-stge_loc = I_MAIN-LGOBE.

itab-ENTRY_UOM = I_MAIN-ERFME.

IF I_MAIN-WERKS = 'OMR'.

itab-TR_PART_BA = '11'.

ELSEIF I_MAIN-WERKS = 'OMR'.

itab-TR_PART_BA = '12'.

ENDIF.

append itab.

ENDLOOP.

if not itab[] is initial.

call function 'BAPI_GOODSMVT_CREATE'

exporting

goodsmvt_header = gmhead

goodsmvt_code = gmcode

  • * TESTRUN = ' '

IMPORTING

goodsmvt_headret = mthead

  • * MATERIALDOCUMENT =

  • MATDOCUMENTYEAR =

tables

goodsmvt_item = itab

  • GOODSMVT_SERIALNUMBER =

return = errmsg.

clear errflag.

loop at errmsg.

if errmsg-type eq 'E'.

write:/'Error in function', errmsg-message.

errflag = 'X'.

else.

write:/ errmsg-message.

endif.

move errmsg-message to i_msg1.

append i_msg1.

endloop.

if errflag is initial.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

  • commit work and wait.

if sy-subrc ne 0.

write:/ 'Error in updating'.

exit.

else.

write:/ mthead-mat_doc, mthead-doc_year.

ZMM_GI_WIP-GI_NO = I_TAB-SOL_DOCNO.

ZMM_GI_WIP-GI_DATE = I_TAB-SOL_DOCDT.

INSERT ZMM_GI_WIP.

COMMIT WORK.

I_TAB-FLAG = 'C'.

MODIFY I_TAB INDEX COUNT.

CONCATENATE mthead-mat_doc mthead-doc_year

into i_msg1.

append i_msg1.

  • perform upd_sta.

endif.

endif.

endif.

ENDIF.

wait up to 20 seconds.

ENDLOOP.

Read only

0 Likes
1,390

I am using commit but before the sales order number returned by the bapi is blank....without any error msg..

Read only

0 Likes
1,390

Could it be a bug in SAP?

Read only

Former Member
0 Likes
1,390

Hi,

Here your problem is with configuration but not with your code.Becasue some of the clients will configure (or by using user-exit) such way one sales order with one purchase order number.i.e if the sales order exits with the same P.O number then

it will give error.Simply you can contact to any functional guy they will help to

you to know how the configuration .

Thanks,

shyla

Read only

0 Likes
1,390

Hi Shyla, thanks for the reply...

But i dont think that is the pbm..

because if i give only header and partner details the Sales order is created with warning..

but when i try to give other details like item, schedule and condition..then warning (no error) and no Sales order is returned.. but i think Sales order might be created in the system..

Any idea about this/

Read only

0 Likes
1,390

This is messages i Get..Sales order saved it says..but where is the number? its not there in the salesdocument number too.

S |SALES_HEADER_IN has been processed successfully <

S |SALES_ITEM_IN has been processed successfully <

W |Purchase order number in document number: 10054056 already exists <

W |Purchase order number in document number: 10054056 already exists <

S |Sales Order(VMS) has been saved <

___________________________________________________________________________

Read only

0 Likes
1,390

Hi there,

I found out the solution.

It was because the materials were semifinished goods.

When you run a bapi to create sales order with semifinished goods, it acts weirdly..it doesnot return a sales order, neither it prompts for this error/warning.

Very strange..Hope this helps you too.

Read only

Former Member
0 Likes
1,390

Thanks for your valuable inputs