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

Error using BAPI_SALESORDER_CHANGE

stefan_kolev4
Participant
0 Likes
6,059

Hi,

I'm trying to change qty in the item of the document via VA02 using BAPI_SALESORDER_CHANGE.

I'm passing the required data, but in the return table I am receiving an error message "Enter document number".

Below is my code. Did I miss something ?

DATA: s_order_header_in LIKE bapisdh1.

DATA: s_order_header_inx LIKE bapisdh1x.

DATA: BEGIN OF i_order_item_in OCCURS 0.

INCLUDE STRUCTURE bapisditm.

DATA: END OF i_order_item_in.

DATA: BEGIN OF i_order_item_inx OCCURS 0.

INCLUDE STRUCTURE bapisditmx.

DATA: END OF i_order_item_inx.

DATA: BEGIN OF it_return OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA: END OF it_return.

DATA: BEGIN OF i_sched OCCURS 10.

INCLUDE STRUCTURE bapischdl.

DATA: END OF i_sched.

DATA: BEGIN OF i_schedx OCCURS 10.

INCLUDE STRUCTURE bapischdlx.

DATA: END OF i_schedx.

s_order_header_inx-updateflag = 'U'.

i_order_item_in-itm_number = vbap-posnr.

i_order_item_in-TARGET_QTY = rv45a-zzqty.

i_order_item_inx-updateflag = 'U'.

i_order_item_inx-itm_number = vbap-posnr.

i_order_item_inx-TARGET_QTY = 'X'.

APPEND: i_order_item_in, i_order_item_inx.

i_sched-itm_number = vbap-posnr.

i_sched-sched_line = '0002'.

i_sched-req_qty = rv45a-zzqty.

APPEND i_sched.

i_schedx-itm_number = vbap-posnr.

i_schedx-sched_line = '0002'.

i_schedx-updateflag = 'U'.

i_schedx-req_qty = 'X'.

APPEND i_schedx.

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = xvbap-vbeln

order_header_in = s_order_header_in

order_header_inx = s_order_header_inx

behave_when_error = 'P'

TABLES

return = it_return

order_item_in = i_order_item_in

order_item_inx = i_order_item_inx

schedule_lines = i_sched

schedule_linesx = i_schedx.

ENDIF.

23 REPLIES 23
Read only

Former Member
0 Likes
3,551

Hi,

Where are you putting value in xvbap-vbeln.

Regards

Vijai

Read only

Former Member
0 Likes
3,551

Hi,

You are getting this error because xvbap-vbeln may be passed as blank. Try to use some valid data where vbeln is not blank or make a check at this parameter since it is mandatory.

Debugging the program will help you.

Read only

0 Likes
3,551

Hi,

I checked and xvbap-vbeln is not blank. I passed the number directly for example salesdocument = '0000000237', but I received the same error. Why ?

Read only

0 Likes
3,551

Can we use BAPI_SALESORDER_CHANGE when PO is open via transaction VA02?

Read only

0 Likes
3,551

Hi,

Try to populate the data for parameter order_header_in.

Also, if possible please give the message id and message no. you receive in returns parameter.

KR Jaideep,

Read only

0 Likes
3,551

Hi,

TYPE: E

ID : V1

Number:045

MESSAGE: Enter the document number

Read only

0 Likes
3,551

Hi,

Try putting breakpoint at function module SD_SALES_DOCUMENT_READ and SD_SALES_DOCUMENT_READ_POS in side bapi and check if SALESDOCUMENT is passed with correct value in this function module.

KR Jaideep,

Read only

0 Likes
3,551

>

> Can we use BAPI_SALESORDER_CHANGE when PO is open via transaction VA02?

Are you by any chance calling the BAPI in a user exit ?

Read only

0 Likes
3,551

Yes, I tried and SALESDOCUMENT is passed ???

Read only

0 Likes
3,551

I'm using screen 8459 in order to make some calculations which should change the qty.In PAI of the screen I'm using BAPI_SALESORDER_CHANGE where I'm passing the new qty.The idea is to change the qty and schedule lines.

Stefan

Read only

0 Likes
3,551

Hi,

I think its a lock problem. You are trying to change a sales order which is already open. BAPI will lock the order before changing schedule lines quantity. Try to use BAPI in separate report with same parameters as above. If the order gets changed then its definitely a lock issue and not of data which you are passing.

KR Jaideep,

Read only

0 Likes
3,551

Why dont you instead use the user exits for Sales order procesing , there are plenty and you will also have all the variables and internal tables that you need to change. Try the user exits in program MV45AFZZ - userexit_save_document_prepare.

regards,

Advait

Read only

0 Likes
3,551

Hi Stefan,

This solution is logically incorrect.

You cannot use BAPI_SALESORDER_CHANGE to change the same sales order in which your are working.

Do not make use of the BAPI.

Whatever quantity you want to change; make the changes in exit MV45AFZZ in form userexit_save_document_prepare.

Modify the required quantity in the internal table XVBAP.

Regards,

Ankur Parab

Edited by: Ankur Parab on Aug 1, 2009 2:05 PM

Read only

Former Member
0 Likes
3,551
Read only

0 Likes
3,551

Hi,

This is because the Sales order which you try to change will already be locked/enqued by the system and when tried to export the SO number in

BAPI_SALESORDER_CHANGE ->

SD_SALESDOCUMENT_CHANGE->

SD_SALES_DOCUMENT_READ->

PERFORM BELEG_LESEN(SAPMV45A) include subroutine, it will not find.

Try keeping a break point in the function module SD_SALES_DOCUMENT_READ at statement

VBAK-VBELN = DOCUMENT_NUMBER.

PERFORM BELEG_LESEN(SAPMV45A)

and see if the SO doc value that is assigned to VBAK-VBELN in the function module is passed into the perform without clearing its value.

If it is clearing out, then there is enqueue on the SO number already set by the standard VA02 program.

So cannot be changed without unlocking it.

But in the form USEREXIT_SAVE_DOCUMENT_PREPARE if you try to unlock this might lead to incosistencies, so be careful.

Try if u can unlock the SO and then change using the BAPI and then enqueue again, but take care it should not lead to any inconsistency.

Sai

Read only

Former Member
Read only

Former Member
0 Likes
3,551

Stefan,

Did you find any solution to this problem?

Read only

Former Member
0 Likes
3,551

Check the following example


REPORT zsalesorder_change .
* Data declarations.
DATA:i_bapi_view LIKE order_view.
DATA:sales_documents LIKE sales_key OCCURS 0 WITH HEADER LINE.
*ORDER_OUT
DATA:order_items_out LIKE bapisdit OCCURS 0 WITH HEADER LINE.
DATA:order_headers_out LIKE bapisdhd OCCURS 0 WITH HEADER LINE.
DATA:order_header_inx LIKE bapisdh1x.
***ORDER_IN
DATA:order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE.
DATA:order_header_in LIKE bapisdh1 OCCURS 0 WITH HEADER LINE.
DATA:order_item_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE.
DATA:schedule_lines LIKE bapischdl OCCURS 0 WITH HEADER LINE.
DATA:schedule_linesx LIKE bapischdlx OCCURS 0 WITH HEADER LINE.
DATA: i_hdr TYPE bapisdh1.
DATA: itab_item          LIKE bapisditem  OCCURS 0 WITH HEADER LINE.
DATA: itab_ch          LIKE itab_item  OCCURS 0 WITH HEADER LINE.
DATA: s_order_header_in LIKE bapisdh1.
DATA: s_order_header_inx LIKE bapisdh1x.
DATA: BEGIN OF i_order_item_in OCCURS 0.
        INCLUDE STRUCTURE bapisditm.
DATA: END   OF i_order_item_in.
DATA: BEGIN OF i_order_item_inx OCCURS 0.
        INCLUDE STRUCTURE bapisditmx.
DATA: END   OF i_order_item_inx.
DATA: BEGIN OF it_return OCCURS 0.
        INCLUDE STRUCTURE bapiret2.
DATA: END OF it_return.
DATA: BEGIN OF i_sched OCCURS 10.
        INCLUDE STRUCTURE bapischdl.
DATA: END OF i_sched.
DATA: BEGIN OF i_schedx OCCURS 10.
        INCLUDE STRUCTURE bapischdlx.
DATA: END OF i_schedx.
DATA : zmsg(50) TYPE c.

continue...............

Edited by: Krupaji on Feb 9, 2010 12:28 PM

Read only

Former Member
0 Likes
3,551

* Parameters
SELECTION-SCREEN : BEGIN OF BLOCK order WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS: p_vbeln TYPE vbap-vbeln OBLIGATORY,
            pval TYPE vbap-bwtar .
SELECTION-SCREEN : END OF BLOCK order.

order_header_in-sd_doc_cat  = 'C'.
order_header_inx-updateflag = 'U'.
i_bapi_view-header = 'X'.
i_bapi_view-item = 'X'.
sales_documents-vbeln = p_vbeln.
APPEND sales_documents.

***GET LIST OF SALESORDER

CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
  EXPORTING
    i_bapi_view       = i_bapi_view
  TABLES
    sales_documents   = sales_documents
    order_headers_out = order_headers_out
    order_items_out   = order_items_out.
LOOP AT order_items_out .
  MOVE-CORRESPONDING order_items_out TO order_item_in.
  order_item_in-val_type = pval.
  APPEND order_item_in.
ENDLOOP.

*  IF SAVEFLAG = 'IN'  AND wa_bapisdstat-dlv_stat_h <> 'C' .

LOOP AT order_item_in .
  MOVE-CORRESPONDING order_item_in TO itab_ch.
  APPEND itab_ch.
ENDLOOP.

Edited by: Krupaji on Feb 9, 2010 12:30 PM

Edited by: Krupaji on Feb 9, 2010 12:33 PM

Read only

Former Member
0 Likes
3,551

LOOP AT itab_ch .
*   Header update indicator
  s_order_header_inx-updateflag = 'U'.

*  IF itab_ch-itm_number = zitem_num1.
*   Line items
  i_order_item_in-itm_number = itab_ch-itm_number .
  i_order_item_in-material =   itab_ch-material.
  i_order_item_in-target_qty = itab_ch-target_qty.
  i_order_item_in-sales_unit = itab_ch-sales_unit.
  i_order_item_in-val_type = itab_ch-val_type.

  i_order_item_inx-updateflag = 'I'.

  i_order_item_inx-itm_number = itab_ch-itm_number .
  i_order_item_inx-material = itab_ch-material.
  i_order_item_inx-target_qty = 'X'.
  i_order_item_inx-sales_unit = itab_ch-sales_unit.
  i_order_item_inx-val_type =  'X'.

  APPEND: i_order_item_in, i_order_item_inx.

**  Fill schedule lines
  i_sched-itm_number = itab_ch-itm_number .
  i_sched-sched_line = '0001'.
  i_sched-req_qty    = itab_ch-target_qty.
  APPEND i_sched.

*   Fill schedule line flags
  i_schedx-itm_number  = itab_ch-itm_number .
  i_schedx-sched_line = '0001'.
  i_schedx-updateflag  = 'I'.
  i_schedx-req_qty     = 'X'.
  APPEND i_schedx.
ENDLOOP.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
  EXPORTING
    salesdocument     = p_vbeln
    order_header_in   = s_order_header_in
    order_header_inx  = s_order_header_inx
    behave_when_error = 'P'
  TABLES
    return            = it_return
    order_item_in     = i_order_item_in
    order_item_inx    = i_order_item_inx
    schedule_lines    = i_sched
    schedule_linesx   = i_schedx.


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait = 'X'.

LOOP AT it_return.
  WRITE / it_return-message.
ENDLOOP.
Read only

Former Member
0 Likes
3,551

Hi, I want the same thing happened to modify the order processing a message class for the BAPI BAPI_SALESORDER_CHANGE VA02. The solution was to create a function and call it Z: starting new task in group lv_task lv_group destination. Within the whole process Z and before calling the BAPI do this:

  • Try to track document process block

SY-SUBRC = 1.

while SY-SUBRC ne 0.

call function 'ENQUEUE_EVVBAKE'

Exporting

mode_vbak = 'E'

= sy-Mandt Mandt

VBELN = ls_salesdocument

x_vbeln = ''

_scope = '2 '

_wait = 'X'

_collect = ''

exceptions

foreign_lock = 1

system_failure = 2

others = 3.

endwhile.

  • When locking is achieved because the user came out of the screen

  • Unlock the document

call function 'DEQUEUE_EVVBAKE'

Exporting

mode_vbak = 'E'

= sy-Mandt Mandt

VBELN = ls_salesdocument

x_vbeln = ''

_scope = '3 '

_synchron = ''

_collect = ''.

  • With the unlocked document processed with the BAPI

call function 'BAPI_SALESORDER_CHANGE'

With this, the implementation is awaiting the release of the document (when the user exits the screen that gave vent to the kind of message) and processed with the BAPI. Works perfect. I hope they serve.

Atte. Noel Bravo

Read only

Former Member
0 Likes
3,551

Hi all,

I am still facing this issue

Does any one have a solution for this.

Kindly help me.

Read only

0 Likes
3,551

Hi Ramesh,

Please try the solution suggested by Noel Bravo. IT worked for me.

Thanks,

Anand