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

Order change BAPI Question

Former Member
0 Likes
1,682

Hi I have a requirement where in we have a web application communicates with SAP through a BAPI call and makes changes to the orders.

The Web application should synchrounously call BAPI and retrieve the order details.On seeing the Order details the CSR will change the order as needed and save, which should be replicated in SAP.Until the CSR is changing the order and saving it the order should be locked and should not be available for access to any other users...How can I achieve this..?

Can any one please outline the details.

Thanks in advance!

10 REPLIES 10
Read only

Former Member
0 Likes
1,334

make use of FM 'BAPI_SALESORDER_CHANGE'

Read only

0 Likes
1,334

can BAPI SALES ORDER CHANGE get the details and also change the order..at one instance..?

Read only

Former Member
0 Likes
1,334

HI,,

You can use BAPISDORDER_GETDETAILEDLIST to get all the details related to a given SO.


 IT_SALES_KEY-VBELN = I_VBELN.
  APPEND IT_SALES_KEY.

*Fill in the structures you want to fetch data for.
  WA_ORDER_VIEW-HEADER     = 'X'.
  WA_ORDER_VIEW-ITEM       = 'X'.
  WA_ORDER_VIEW-SDSCHEDULE = 'X'.
  WA_ORDER_VIEW-BUSINESS   = 'X'.
  WA_ORDER_VIEW-PARTNER    = 'X'.
  WA_ORDER_VIEW-ADDRESS    = 'X'.
  WA_ORDER_VIEW-TEXT       = 'X'. 
  WA_ORDER_VIEW-STATUS_H   = 'X'.  WA_ORDER_VIEW-STATUS_I   = 'X'.  

*--Step 3
*Call the BAPI to get the details
  CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
    EXPORTING
      I_BAPI_VIEW             = WA_ORDER_VIEW
    TABLES
      SALES_DOCUMENTS         = IT_SALES_KEY
      ORDER_HEADERS_OUT       = IT_ORDER_HEADERS_OUT
      ORDER_ITEMS_OUT         = IT_ORDER_ITEMS_OUT
      ORDER_SCHEDULES_OUT     = IT_ORDER_SCHEDULES_OUT
      ORDER_BUSINESS_OUT      = IT_ORDER_BUSINESS_OUT
      ORDER_PARTNERS_OUT      = IT_ORDER_PARTNERS_OUT
      ORDER_ADDRESS_OUT       = IT_ORDER_ADDRESS_OUT
      ORDER_STATUSHEADERS_OUT = IT_ORDER_STATHEADERS_OUT 

ORDER_STATUSITEMS_OUT   = IT_STATUSITEMS_OUT 

ORDER_TEXTHEADERS_OUT   = IT_TEXTHEADERS_OUT

IT_TEXTLINES_OUT     = IT_ORDER_TEXTLINES_OUT 

EXTENSIONOUT          = IT_BAPIREX.
.

This will give alll the related data for the given SO

Now to change the SO you can use BAPI_SALESORDER_CHANGE.

Sample Code



  l_vbeln = salesorder.
  i_bapisdhd1x-updateflag  = 'U'.

*--Map the Header Data
  MOVE-CORRESPONDING l_header TO i_bapisdhd1.

*--Item data

"Here you need to loop at item data and insert the BAPI inteface tables.
"Note that you need to fill both Item and Schedule data to update the Item data
*Item table
    it_bapisditmx-itm_number =  l_item-itm_number.
    it_bapisditmx-updateflag =  'U'.
*Item X
    it_bapischdlx-itm_number = it_bapisditm-itm_number.
    it_bapischdlx-sched_line = '0001'.
    it_bapischdlx-req_qty    = 'X'.
*Schedule
    it_bapischdl-itm_number = it_bapisditm-itm_number.
    it_bapischdl-req_qty = l_item-target_qty.
    it_bapischdl-sched_line = '0001'.
*Schedule X
    it_bapischdlx-itm_number = it_bapisditm-itm_number.
    it_bapischdlx-req_qty = 'X'.
    it_bapischdlx-sched_line = 'X'.

    APPEND :it_bapisditm,it_bapischdl,it_bapisditmx, it_bapischdlx.

*--Call SO change BAPI
  CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
      salesdocument    = l_vbeln
      order_header_in  = i_bapisdhd1
      order_header_inx = i_bapisdhd1x
    TABLES
      return           = it_retchnge
      order_item_in    = it_bapisditm
      order_item_inx   = it_bapisditmx
      partnerchanges   = it_partnerchanges
      schedule_lines   = it_bapischdl
      schedule_linesx  = it_bapischdlx
      order_text       = it_bapisdtext
      extensionin      = it_bapiparex.

"DO not forget to COMMIT work if the RETURN table does have Errors/Abort using ''BAPI_TRANSACTION_COMMIT''

Also you will have to call the BAPI separately, once to show the details.. and the next time .. to update these ...

Hope this helps.

Gary

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 9, 2008 5:29 PM

Read only

0 Likes
1,334

Thanks Guys,

I need SALES ORDER only...I can use GET DETAILS BAPI to retrieve the data and ORDER change BAPI to change the order but my concern is while CSR is viewing the sales order data..(it might take few mins)..how can I lock the particular sales order(to make it unavailable for other users)until the change is done or during a period of time..?

Read only

0 Likes
1,334

HI,

One way to do this is :

One RFC which will 'Enqueue' the SO (Lock the SO ) and called just after fetch (if you know that user will be working on after fetch)

and then...

after the user is ready to Confirm his changes you can call the 'Dequeue' FM and subsequently the CHANGE RFC/BAPI.

Another way : (If the SO to be updated only via Web)

Once you fetch the SO, mark a flag that No other user should be able to update the SO and clear it once change BAPI/RFC is triggered.

Hope this helps.

Gary

Read only

0 Likes
1,334

Gary,Thanks for the suggestions. Is this the module ENQUEUE_EVVBAKE which needs to be used to Enqueue..?If so DO you have any sample Code..I tried using the module and it didnt lock that particaular Sales Order..How it needs to be done..?

Read only

0 Likes
1,334

HI,

I use the following and it works great for me !!

"To Enqueue.
        CALL FUNCTION 'ENQUEUE_EVVBAKE'
          EXPORTING
            mode_vbak      = 'E'
            mandt          = sy-mandt
            vbeln          = l_vbeln
          EXCEPTIONS
            foreign_lock   = 1
            system_failure = 2
            OTHERS         = 3.
        IF sy-subrc EQ 0.
          EXIT.
        ENDIF.

"To Dequeue
      CALL FUNCTION 'DEQUEUE_EVVBAKE'
        EXPORTING
          mode_vbak = 'E'
          mandt     = sy-mandt
          vbeln     = l_vbeln.

Hope this helps.

Gary.

Read only

0 Likes
1,334

Hi ,

I have a problem...Iam calling 'ENQUEUE_EVVBAKE' through a BAPI which gets the sales order details..Its a synchronous bapi so when the execution of the BAPi is completed the sales order is unlocked...My requirement is until I call the Salesorder change BAPI the sales order should be remaining unlocked...is there any way to achieve this...please help..

Thanks in advance!

Larry

Read only

0 Likes
1,334

HI,

If someone in R/3 is using the SO-(VA02) then it will difficult for the user to update it via the WEB and the Change BAPI will return a message -'Order locked by Username'.

On the other hand if the users are always going to work from the web then it should not be a problem to work with the same SO#.

What you can do is....

1.Call the 'Create' action in the Web and trigger the create BAPI.

On successful execution of the BAPI call the Enqueue RFC.

This will ensure that the SO is locked for use in SAP and even if some other user wants to update, he/she will get an error message.

2. Now the user wants to update some values in the web and save these details

Call the 'Update' action and trigger the Dequeue RFC so that the SO is unlocked in SAP and after this call the Change BAPI.

On successful completion of update in SAP, call the Enqueue RFC again to lock the SO.

Hope this helps.

Gary.

Read only

Former Member
0 Likes
1,334

Hi,

Can you clear me which order you want to get Order menas

Each order is having different bapis Purchase order, Sales order etc...

BAPI_PLANNEDORDER_CHANGE - Change planned order

BAPI_SALESORDER_CHANGE - Sales order: Change Sales Order

BAPI_STANDING_ORDER_CHANGE - BAPI: Changes a Standing Order

BAPI_ACC_PURCHASE_ORDER_POST - Post Purchase Order

etc...

Thanks

Ganesh