Application Development 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: 

Double sales order creaated : BAPI_SALESORDER_CREATEFROMDAT2

Former Member
0 Kudos

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.

24 REPLIES 24

former_member200345
Contributor
0 Kudos

Hi Praveen,

Please note that the PO Number is just a reference field while creating the Sales Order. SAP does not validate the PO Number field. You can create multiple sales orders with the referece of the same PO Number.

If you want to validate this field in the program, validate this field (VBKD-BSTKD) before calling the BAPI.

Hope this helps.

Regards,

Vijaymadhur.

Former Member
0 Kudos

Whether or not duplicate PO numbers are allowed for a customer within a sales area, etc., is a configuration setting. Speak to your functional specialist. Sounds like what you need to investigate is why your input results in creation of two sales orders instead of one?

former_member191735
Active Contributor
0 Kudos

DaveL is right. The setting for PO is in the order type. Ask you SD .

For double sales orders: Make sure you are not looping the same record. This seems to be problem within the code i mean the way of calling BAPI. Try with one record in file and then try with multiple.

Edited by: Sampath Kumar on May 13, 2011 9:53 AM

0 Kudos

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

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

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?

Regrds,

Praveen.

Edited by: Praveen Akl on May 16, 2011 6:54 AM

Former Member
0 Kudos

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

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

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?

Regrds,

Praveen.

0 Kudos

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

Former Member
0 Kudos

Hi Chen,

The Bapi throws the message with type "E" when executed through SE37. But it is not the case when executed from background, The Bapi is not throwing the error though it has existing PO assigned.

I could have debugged ( (Background job) but this error happens very rarely.

Rgds,

Praveen.

0 Kudos

Hi Praveen,

2 questions.

1) Is ATP check happening in the same system (where SO gets created) or different system?

I did face this issue, when ATP Checks were in different system & we would see duplicate SO getting created

2) How is the BAPI being called? RFC or PI BPM ..

Plz shove details on that,

0 Kudos

The ATP check is happening in the same system(SAP)...

The BAPI is called inside a program which in turn is scheduled in background and run as a job. Rarely the BAPI creates double sales order with same PO number, so the option to debug is left out..

What i wonder is all the details for the double sales order created is same except the 'Total Weight'. One has blank values & the other with exact calculated weight.

Regds,

Praveen.

0 Kudos

Hi Praveen,

If this is a sporadic issue, then i guess like i suggested in the previous post, 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.

Note: Not sure if you have considered this already, but VBAK-BSTNK is case sensitive so "CUSTOMER PO" will be different from "CUSTOmER PO".

Regards,

Chen

0 Kudos

Hi Chen,

Debugging option is left out as this error occurs very rarely. May be as u said ill check for the Material and customer details, Let me compare it and update you.

Rgds,

Praveen.

0 Kudos

Hi ,

As the purchase order number comes in the form of a file, can you confirm whether it has leading zeroes or not.

May be some times, it is not having leading zeroes, may be validation is failing.

can you cross check.

Thanks,

Rohan

0 Kudos

Praveen, so are these Sales orders created at the same time (or around the same time)?

Former Member

@ Rohan

No leading zeros are there, Even in case if the validation is failed the program should create only one Sales order. Why is it creating double order? Still a wonder...

@ Kris

Yes, These sales orders are created in a seconds difference, Is it because of lock entry?

Regds,

Praveen.

0 Kudos

Praveen,

If such duplicates are happening at around a same time, there may not a whole lot you can do about it...One possible alternative is to figure out why your process allows such duplicates to happen... Why is your program receiving two duplicate Orders (and that too at a same time)... What is the input to your program? Could you give more details as to how your receive your orders? When are you commiting your order creation? BAPI_TRANSACTION_COMMIT immediately after each BAPI*DAT2 could also help (if the orders are created as part of same background job and if it is not issued)

There are some very bad ways to counter this ... like a custom duplicate check in Save document prepare , it won't eliminate it altogether but will ensure that checks happen at a much later time and ensure that prior sales order with same PO has already been posted..

Another alternative is a end of day report looking for duplicates for Sales Orders created today and to have the users manually reject the orders.

0 Kudos

Could be locks. are you refreshing everything upon any failure including rollback ?

It is kind of strange situation.

0 Kudos

Hi Praveen,

I am not sure on how this could be a lock issue(or rather lack of it), anyways...you have mentioned in your earlier replies that you have a flat file which is read by a background program...is my interpretation of the integration correct or do you have any other components in between.

If my interpretation is correct, try the below options, i assume that the flow in your background program is as below,

1) You read the file(which has multiple orders) into an ITAB

2) Loop at the ITAB and call the BAPI for each order on the file.

If i am correct till here, then What i think could be happening here is that(assuming there are multiple/duplicate records for the same PO immediately one after the other) while the BAPI has processed the records for a given PO and the UPDATE still hasn't hit the DB, the second record with same PO is processed for validation and since it doesn't find an entry in the DB this proceeds without any error.

To overcome the above

1) Use set local update task local before calling the BAPI - Data for the priority updates will be stored locally in the ABAP memory and not in VBLOG.

2) While calling BAPI_TRANSACTION_COMMIT pass "X" to the wait parameter, this will make sure that update is synchronous.

You can look at the input file for duplicate records for a given PO, let me know if your integration between the flat file and SAP is any different.

Regards,

Chen

0 Kudos

Hi Chen,

Sorry for the late response, We encountered the same problem again. There is no duplicate entries (PO) in the flat file.

The overcome solution suggested by you might work. But before that i wanted to get a clarification, This custom program uses ENQUEUE function thrice with parameter _scope = 3. One is called before the SO bapi call and one after the bapi call and finally after some validations ( The ENQUEUE is called inside the loop).

As per my knowledge if the _scope is 3 in the ENQUEUE function the lock belongs to the dialouge owner or the update owner. So my question is does it create two LUW and updates the database table twice? is it the cause of double order creation?

Regrds,

Praveen.

0 Kudos

Hi Praveen,

This custom program uses ENQUEUE function thrice with parameter _scope = 3. One is called before the SO bapi call and one after the bapi call and finally after some validations ( The ENQUEUE is called inside the loop).

What is being en queued?

As per my knowledge if the _scope is 3 in the ENQUEUE function the lock belongs to the dialouge owner or the update owner. So my question is does it create two LUW and updates the database table twice? is it the cause of double order creation?

As per documentation for Scope 3 - The lock belongs to both owners (owner_1 and owner_2). In other words, it combines the behavior of both. This lock is canceled when the last of the two owners has released it.

and anyways i don't think that this could be the cause for duplicate orders getting created.

Also, could you provide more info on your integration scenario - end to end. Is the PO number coming in from the flat file?

Regards,

Chen

0 Kudos

Hi Chen,

They have created a lock for the program. "CALL FUNCTION 'ENQUEUE_EZRSEE050'" here the ZRSEE050 is the program name.

The process goes like this.

1. Data is picked from the flat file (Application server) and put in a internal table.

2. Loop the internal table.

3. Call the SO bapi inside the Loop.

4. ENQUEUE is done for the program thrice inside the loop.

5. Put the success & failed data in a file at application server. (defined path) (Inside the loop).

Yes the PO is fetched from the flat file and i am sure there is no duplication in the file.

BR,

Praveen.

0 Kudos

Hi Praveen,

Pardon my ignorance, but what does this program ZRSEE050 do and why is it being locked?

Well, the process seems straight forward except for the above point, could you post the code, no need to post the complete code...you can ignore the lines where simple data transfer is being done, add comments like populating data for items, partners etc. Post the relevant part where you are locking etc

Also, i stumbled upon the OSS note 1024902, go through this once and see if your code is compliant as per the suggestions in it.

Regards,

Chen

Edited by: Chen K V on Jun 10, 2011 12:40 PM

Edited by: Chen K V on Jun 10, 2011 4:16 PM

0 Kudos

Hi Chen,

Really thanks for the effort taken. Let me check on the OSS note 1024902. I shall get back to you with the update soon.

BR,

Praveen.

0 Kudos

Hi Praveen,

I think what Chen wrote is right.

Since you are getting error if you call BAPI through SE37 and you are not getting error if you call through program,

It represent that problem is in commit work. SO takes some time to reflect data into respective tables, if the two orders are being created continuesly you must pass 'X' to wait and also put WAIT for some Secs..

Even check for error mess in return table if exist do not call commit work.

Thanks,

Anmol.

Former Member
0 Kudos

Can any body help me on this????