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

Problem with BAPI_SALESORDER_CHANGE function module

Former Member
0 Likes
1,047

I know lot of posts have been done about problems with this function module. However I was not able to find the answer to my problem. Hence posting a new thread

I have the following code which changes the reason rejection (if required to 'ZF') and also updates the sales order quantity.

The code works absolutely fine as long as the PGI date of the order item is either today or in the future. However if the PGI date of the order item is in the past. I get an error in the t_return table with error type 'E' saying 'PGI date is in the past hence could not update the item'.

If I try to update the same order quantity in VA02 for the item with PGI date in the past it does so without any problem.

Can someone please suggest what the problem might be. Or if there is some other way I can update the quantity. (I dont want to use BDC)

FORM change_sales_order_item USING value(r_rtb_posnrs) TYPE zpsd_ztsdrtb_ro_track

CHANGING r_return TYPE type_t_bapiret2.

DATA: v_order_header_in TYPE bapisdh1,

v_order_header_inx TYPE bapisdh1x,

t_schedule_lines TYPE bapischdl OCCURS 0 WITH HEADER LINE,

t_schedule_linesx TYPE bapischdlx OCCURS 0 WITH HEADER LINE,

v_temp_rtb_vbeln TYPE vbeln,

v_temp_rtb_posnr TYPE posnr,

wa_old_rtb_posnrs TYPE ztsdrtb_ro_track,

t_item_in TYPE bapisditm OCCURS 0 WITH HEADER LINE,

t_item_inx TYPE bapisditmx OCCURS 0 WITH HEADER LINE,

v_rtb_old_vbeln TYPE zrtbvbeln,

v_rtb_old_posnr TYPE zrtbposnr,

v_ro_old_vbeln TYPE zrovbeln,

v_ro_old_posnr TYPE zroposnr,

v_rtb_count TYPE i,

v_next_row_index TYPE i,

v_update_order_flg TYPE char1, "Update the sales order flag

v_rtb_record_counter TYPE i,

v_original_vbeln TYPE vbeln,

t_bapiret TYPE STANDARD TABLE OF bapiret2.

FIELD-SYMBOLS: <wa_r_rtb_posnrs> TYPE ztsdrtb_ro_track,

<wa_r_rtb_posnr_next> TYPE ztsdrtb_ro_track.

CONSTANTS: c_updateflag TYPE bapisditmx-updateflag VALUE 'U'.

v_order_header_inx-updateflag = 'U'.

  • Get rid of the duplicate records for the same RTB order. Just use

  • the last record quantity in the internal table

LOOP AT r_rtb_posnrs ASSIGNING <wa_r_rtb_posnrs>.

v_rtb_record_counter = v_rtb_record_counter + 1.

<wa_r_rtb_posnrs>-seqnr = v_rtb_record_counter.

ENDLOOP.

SORT r_rtb_posnrs DESCENDING BY zrtbvbeln zrtbposnr seqnr zrtbconsumedflg.

DELETE ADJACENT DUPLICATES FROM r_rtb_posnrs COMPARING zrtbvbeln zrtbposnr.

DESCRIBE TABLE r_rtb_posnrs LINES v_rtb_count.

v_rtb_record_counter = 0.

v_update_order_flg = space.

LOOP AT r_rtb_posnrs ASSIGNING <wa_r_rtb_posnrs>.

v_rtb_record_counter = v_rtb_record_counter + 1.

v_update_order_flg = space.

  • Popluate the item quantity update flags for schedule lines

t_schedule_linesx-itm_number = <wa_r_rtb_posnrs>-zrtbposnr.

t_schedule_linesx-sched_line = '0001'.

t_schedule_linesx-updateflag = c_updateflag.

t_schedule_linesx-req_qty = 'X'.

APPEND t_schedule_linesx.

CLEAR t_schedule_linesx.

*Item (Order QQuantity Field to be changed "KWMENG")

t_schedule_lines-itm_number = <wa_r_rtb_posnrs>-zrtbposnr.

t_schedule_lines-sched_line = '0001'.

t_schedule_lines-req_qty = <wa_r_rtb_posnrs>-zrtbchgqty.

APPEND t_schedule_lines.

CLEAR t_schedule_lines.

  • If fully consumed then set the rejection flag

IF <wa_r_rtb_posnrs>-zrtbconsumedflg = 'X'.

t_item_inx-itm_number = <wa_r_rtb_posnrs>-zrtbposnr.

t_item_inx-updateflag = 'X'.

t_item_inx-reason_rej = 'X'.

APPEND t_item_inx.

CLEAR t_item_inx.

t_item_in-itm_number = <wa_r_rtb_posnrs>-zrtbposnr.

t_item_in-reason_rej = 'ZF'.

APPEND t_item_in.

CLEAR t_item_in.

ELSE.

t_item_inx-itm_number = <wa_r_rtb_posnrs>-zrtbposnr.

t_item_inx-updateflag = 'X'.

t_item_inx-reason_rej = 'X'.

APPEND t_item_inx.

CLEAR t_item_inx.

t_item_in-itm_number = <wa_r_rtb_posnrs>-zrtbposnr.

t_item_in-reason_rej = ' '.

APPEND t_item_in.

CLEAR t_item_in.

ENDIF.

  • If you have reached the last line of the RTB intern table update the sales order

*Index pointing to the next row

v_next_row_index = v_rtb_record_counter + 1.

IF v_rtb_record_counter = v_rtb_count.

v_update_order_flg = 'X'.

ELSEIF v_rtb_record_counter < v_rtb_count.

  • Get the next row data

READ TABLE r_rtb_posnrs INDEX v_next_row_index ASSIGNING <wa_r_rtb_posnr_next>.

IF sy-subrc = 0.

IF <wa_r_rtb_posnrs>-zrtbvbeln <> <wa_r_rtb_posnr_next>-zrtbvbeln.

v_update_order_flg = 'X'.

ENDIF.

ENDIF.

ELSE.

v_update_order_flg = space.

ENDIF.

  • update the rtb orders with quantities and the rejection flag (if required)

IF v_update_order_flg = 'X'.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE' STARTING NEW TASK 'SOUPDATE'

PERFORMING callbk_bapi_salesorder_change ON END OF TASK

EXPORTING

salesdocument = <wa_r_rtb_posnrs>-zrtbvbeln

order_header_in = v_order_header_in

order_header_inx = v_order_header_inx

TABLES

return = t_return

schedule_lines = t_schedule_lines

schedule_linesx = t_schedule_linesx

order_item_in = t_item_in

order_item_inx = t_item_inx.

WAIT UNTIL t_return[] IS NOT INITIAL.

READ TABLE t_return INTO wa_return WITH KEY type = 'E'.

IF sy-subrc <> 0.

ELSE.

r_return[] = t_return[].

MESSAGE ID 'ZSD' TYPE 'E' NUMBER 613.

  • RAISE errorinorderupdate.

ENDIF.

REFRESH t_schedule_linesx.

REFRESH t_schedule_lines.

REFRESH t_item_in.

REFRESH t_item_inx.

REFRESH t_return.

ENDIF.

ENDLOOP.

  • CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • IMPORTING

  • return = t_bapiret.

ENDFORM. "Change_Sales_Order

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
919

see the following example and try to do this:

i_hdrx-updateflag = 'U'.

*"----


*" Fill required SCHEDULE_LINES data.

*"----


i_sched-itm_number = p_posnr.

i_sched-sched_line = p_etenr.

i_sched-req_qty = p_reqqty.

i_schedx-updateflag = 'U'.

i_schedx-itm_number = p_posnr.

i_schedx-sched_line = p_etenr.

i_schedx-req_qty = 'X'.

APPEND i_sched.

APPEND i_schedx.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = p_vbeln

order_header_in = i_hdr

order_header_inx = i_hdrx

TABLES

return = i_ret

schedule_lines = i_sched

schedule_linesx = i_schedx.

6 REPLIES 6
Read only

Former Member
0 Likes
919

did you try debugging and see where and how the message is getting triggered

Read only

0 Likes
919

Its a standard SAP error message so I dont see how it will help

Read only

0 Likes
919

why? you need to find why that message is getting triggered first. there is no issue which you cant solve using debugging if you know how to debug in SAP

Read only

0 Likes
919

As I mentioned if I change the order quantity manually from VA02 it lets me do so without any issues. So the problem must be in the way I m calling the function module. So I want to focus on that part instead of spending hours together on finding where the error is coming from and then finally realizing there isnt much I can do about it. I do know very well how to debug in SAP but I think it should be done only if other simpler options fail.

Read only

former_member723628
Active Participant
0 Likes
919

Srikrishna,

Try to change the order quantity without setting up the rejection flag for an item with PGI date in past. If it works you can handle the rejection separately.

Hope this helps you.

Regards,

Gajendra

Read only

Former Member
0 Likes
920

see the following example and try to do this:

i_hdrx-updateflag = 'U'.

*"----


*" Fill required SCHEDULE_LINES data.

*"----


i_sched-itm_number = p_posnr.

i_sched-sched_line = p_etenr.

i_sched-req_qty = p_reqqty.

i_schedx-updateflag = 'U'.

i_schedx-itm_number = p_posnr.

i_schedx-sched_line = p_etenr.

i_schedx-req_qty = 'X'.

APPEND i_sched.

APPEND i_schedx.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = p_vbeln

order_header_in = i_hdr

order_header_inx = i_hdrx

TABLES

return = i_ret

schedule_lines = i_sched

schedule_linesx = i_schedx.