cancel
Showing results for 
Search instead for 
Did you mean: 

Bapi Sales Order

FredericGirod
Active Contributor
0 Kudos

Hello,

I have a little special question, I would like to use BAPI to create Sales Order. I will use this BAPI with RFC from an other application (not WAS), this application is a Web application.

The user will start to create the order from the begining of the day, but he could modify at any time. For example add new items during the day, remove items ...

And for example, he could save this order at the end of the day.

So I can't leave the RFC connection open all the day ...

If I use a BAPI to create and after modify the Order with an other BAPI, I'm not sure that the response time will be good.

And I'm little affraid by saving the order : if the user cancel action, I will have gap in the number ranges ?

If I'm not create and order, how can I specify to the system to lock the stock ?

If anyone have already work with this kind of problem, it will be very nice to give me idea about how to solve this.

Thanks and regards

Frédéric

(I'm working in 4.7)

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Frederic,

I think the better way to solve this is first to store the user input in one Local PC file, then post the document with information from the file at end of the day. If the documents is posted in the morning, but user canceled the Sales Order at end of the day, you'll have to archive the existing Sales Order which would add to your maintenance workload.

Thanks

Luis

Former Member
0 Kudos

You may have to just insert the entries into a Z table until the user finally want to create the order. The only problem it poses is what reference number do you give to the customer while he is changing.

Srinivas

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

My suggestion is to develop your applications as needed on the frontend. User enters the data in morning, changes at lunch, and "transmits" the order at the end of the day. Do all of your user interface and data collection on the frontend, save the data in databases which reside on your web application server. Then when the user is finally ready to complete the order, then and only, then call the BAPI to create the sales order. This way, the user is changing data on the frontend application all day long, but only creating the order in the backend once.

Regards,

Rich Heilman

FredericGirod
Active Contributor
0 Kudos

Hi Srinivas,

I could manage my own range number with SNRO, but, how to lock the stock ?

For example, if I have only 10 items in my stock, and the user in the morning create an order (without end saving), I need to specify to my stock that this 10 items are for this customer.

Regards

Frédéric

Former Member
0 Kudos

Hi,

Did you try fm BAPI_SALESORDER_SIMULATE?

I am not really sure whether this will lock the stock..

but give it a try and see.

Hope this helps..

Sri

FredericGirod
Active Contributor
0 Kudos

Hi Srikanth,

has describe in the documentation the BAPI BAPI_SALESORDER_SIMULATE, only make like creation without comit. That means nothing will be modify in SAP.

Regards

Frédéric

Former Member
0 Kudos

Would you not use BAPI_SALESORDER_CREATEFROMDAT1 or

BAPI_SALESORDER_CREATEFROMDAT2 to create the sales order. Then, later in the day, from a separate call to the web application, if the user wants to change it, use BAPI_SALESORDER_GETLIST and BAPI_SALESORDER_GETSTATUS to retrieve the correct one and then use BAPI_SALESORDER_CHANGE to change it?

Rob

FredericGirod
Active Contributor
0 Kudos

Hi Rob,

if my user will finaly don't want to save the order, I will have a gap in my number range. I can't do this.

Regards

Frédéric

Former Member
0 Kudos

Use the BAPI 'BAPI_SALESORDER_CREATEFROMDAT2' for creating sales order

report zps_bapi_sales_order_create .

  • Structures for order header

data : x_order_header_in like bapisdhd1,

x_order_header_inx like bapisdhd1x.

  • Order partners

data : begin of it_order_partners occurs 0.

include structure bapiparnr.

data : end of it_order_partners.

  • Tables for order items

data : begin of it_order_items_in occurs 0.

include structure bapisditm.

data : end of it_order_items_in.

data : begin of it_order_items_inx occurs 0.

include structure bapisditmx.

data : end of it_order_items_inx.

  • Sales document number

data : r_vbeln like bapivbeln-vbeln.

*Internal Tables to capture BapiReturn messages

data: it_return like bapiret2 occurs 0 with header line,

it_return1 like bapiret2 occurs 0 with header line.

*START-OF-SELECTION.

refresh: it_order_partners,

it_order_items_in,

it_order_items_inx,

it_return.

clear: it_order_partners,

it_order_items_in,

it_order_items_inx,

it_return,

r_vbeln.

start-of-selection.

*----


  • Build partner information

*----


clear it_order_partners.

it_order_partners-partn_role = 'AG'. "Remember German codes !

it_order_partners-partn_numb = '0000100000'.

append it_order_partners.

clear it_order_partners.

*----


  • Build order header

*----


  • Update flag

x_order_header_inx-updateflag = ' '.

  • Sales document type

x_order_header_in-doc_type = 'TA'. "Remember German codes !

x_order_header_inx-doc_type = 'X'.

  • Sales organization

x_order_header_in-sales_org = '0001'.

x_order_header_inx-sales_org = 'X'.

  • Distribution channel

x_order_header_in-distr_chan = '01'.

x_order_header_inx-distr_chan = 'X'.

  • Division

x_order_header_in-division = '01'.

x_order_header_inx-division = 'X'.

  • Purchase order

x_order_header_in-purch_no_c = 'ZPSTESTBAPIPO'.

x_order_header_inx-purch_no_c = 'X'.

*----


  • Build order item(s)

*----


*

  • IT_ORDER_ITEMS_IN-ITM_NUMBER = '10'.

  • IT_ORDER_ITEMS_INX-ITM_NUMBER = 'X'.

*

it_order_items_in-material = '000000000000001969'.

it_order_items_inx-material = 'X'.

*

  • it_order_items_in-req_qty = '10.00'.

  • it_order_items_inx-req_qty = 'X'.

  • it_order_items_in-target_qty = '10.00'.

  • it_order_items_inx-target_qty = 'X'.

*

it_order_items_in-plant = '0001'.

it_order_items_inx-plant = 'X'.

it_order_items_in-pmnttrms = '0001'.

it_order_items_inx-pmnttrms = 'X'.

it_order_items_in-incoterms1 = 'FOB'.

it_order_items_inx-incoterms1 = 'X'.

it_order_items_in-incoterms2 = 'Hyd'.

it_order_items_inx-incoterms2 = 'X'.

  • it_order_items_in-target_qu = ' '.

  • it_order_items_inx-target_qu = 'X'.

*

  • it_order_items_in-sales_unit = 'KG'.

  • it_order_items_inx-sales_unit = 'X'.

*

  • it_order_items_inx-updateflag = 'I'.

*

append it_order_items_in.

clear it_order_items_in.

append it_order_items_inx.

clear it_order_items_inx.

*----


  • CALL Bapi

*----


call function 'BAPI_SALESORDER_CREATEFROMDAT2'

exporting

order_header_in = x_order_header_in

order_header_inx = x_order_header_inx

importing

salesdocument = r_vbeln

tables

return = it_return

order_items_in = it_order_items_in

order_items_inx = it_order_items_inx

order_partners = it_order_partners.

  • Check for Error

read table it_return into it_return

with key type = 'E'.

if sy-subrc eq 0.

message i001(zmap) with 'Failed!Reason-'

it_return-message.

else.

  • Commit Work

clear it_return1.

call function 'BAPI_TRANSACTION_COMMIT'

exporting

wait = 'X'

importing

return = it_return1.

endif.

*If commit is not succesful capture the error messages.

if not it_return1 is initial.

write:/ it_return1-message.

else.

write:/ r_vbeln.

endif.