‎2009 Jun 22 9:30 AM
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.
‎2009 Jun 22 9:44 AM
‎2009 Jun 22 9:45 AM
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.
‎2009 Jun 22 9:54 AM
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 ?
‎2009 Jun 22 1:09 PM
Can we use BAPI_SALESORDER_CHANGE when PO is open via transaction VA02?
‎2009 Jun 22 1:49 PM
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,
‎2009 Jun 22 1:53 PM
Hi,
TYPE: E
ID : V1
Number:045
MESSAGE: Enter the document number
‎2009 Jun 22 2:44 PM
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,
‎2009 Jun 22 2:50 PM
>
> 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 ?
‎2009 Jun 22 2:53 PM
‎2009 Jun 22 2:55 PM
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
‎2009 Jun 22 3:03 PM
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,
‎2009 Jun 22 3:26 PM
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
‎2009 Aug 01 9:34 AM
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
‎2009 Jun 23 1:40 PM
‎2009 Jul 31 10:41 PM
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
‎2009 Aug 01 8:01 AM
‎2010 Feb 08 5:58 PM
‎2010 Feb 09 11:28 AM
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
‎2010 Feb 09 11:29 AM
* 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
‎2010 Feb 09 11:34 AM
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.
‎2011 Sep 14 7:12 PM
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
‎2014 Feb 27 6:36 PM
Hi all,
I am still facing this issue
Does any one have a solution for this.
Kindly help me.
‎2015 May 28 1:28 PM
Hi Ramesh,
Please try the solution suggested by Noel Bravo. IT worked for me.
Thanks,
Anand