Application Development 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: 

Change sales order using BAPI_SALESORDER_CHANGE

Former Member
0 Kudos
153

Hi i want to add a new line item to the existing sales order using BAPI_SALESORDER_CHANGE

but when i am trying it is giving

'Schedule line 0001 for item 000020 does not exist ' error..

please help me..

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
80

You need to be adding a corresponding schedule line for the line item as well? Are you doing that?

You may want to post your code, we can have a look.

Regards

RIch Heilman

4 REPLIES 4

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
81

You need to be adding a corresponding schedule line for the line item as well? Are you doing that?

You may want to post your code, we can have a look.

Regards

RIch Heilman

0 Kudos
80

*********I wanted to add an new line item.***.. this is my code..********

LOOP AT gt_input3 INTO st_input3.

*Finding Max No of line Items

IF fl_set IS INITIAL.

READ TABLE gt_vbap INTO st_vbap WITH KEY vbeln = st_input3-vbeln.

IF sy-subrc EQ 0.

lv_posnr = st_vbap-posnr.

fl_set = 'X'.

ENDIF.

ENDIF.

*Populate Item details

lv_posnr = lv_posnr + 10.

lv_vbeln = st_input3-vbeln.

lv_order_header_inx-updateflag = 'U'.

st_order_item_in-itm_number = lv_posnr.

st_order_item_in-material = st_input3-matnr.

st_order_item_in-target_qty = st_input3-imv_qty.

st_order_item_in-plant = st_input3-werks.

st_order_item_in-store_loc = st_input3-lgort.

  • st_order_item_in-store_loc = st_input3-lgort.

APPEND st_order_item_in TO lt_order_item_in.

*Populate item updation Details

st_order_item_inx-itm_number = lv_posnr.

st_order_item_inx-updateflag = 'U'.

st_order_item_inx-material = 'X'.

st_order_item_inx-plant = 'X'.

st_order_item_inx-store_loc = 'X'.

st_order_item_inx-target_qty = 'X'.

APPEND st_order_item_inx TO lt_order_item_inx.

*Populate the Schedule Lines

st_schedule_lines-itm_number = lv_posnr.

st_schedule_lines-sched_line = '0001'.

st_schedule_lines-req_qty = st_input3-imv_qty.

APPEND st_schedule_lines TO lt_schedule_lines.

*Populate the update details of schedule lines

st_schedule_linesx-itm_number = lv_posnr.

st_schedule_linesx-sched_line = '0001'.

st_schedule_linesx-req_qty = 'X'.

st_schedule_linesx-updateflag = 'U'.

APPEND st_schedule_linesx TO lt_schedule_linesx.

AT END OF vbeln.

*Call BAPI Sales order change

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = lv_vbeln

order_header_inx = lv_order_header_inx

TABLES

return = lt_return

order_item_in = lt_order_item_in

order_item_inx = lt_order_item_inx

schedule_lines = lt_schedule_lines

schedule_linesx = lt_schedule_linesx.

*Save Sales Order

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

CLEAR lv_posnr.

READ TABLE lt_return INTO st_return WITH KEY type = 'E'.

st_ipfile_err3-message = st_return-message.

*Error Log

LOOP AT gt_temp3 INTO st_temp3.

IF st_ipfile_err3-message IS NOT INITIAL.

MOVE st_temp3-record TO st_ipfile_err3-record.

IF fl_set1 IS INITIAL.

APPEND st_temp_err TO gt_ipfile_err3.

fl_set1 = 'X'.

ENDIF.

APPEND st_ipfile_err3 TO gt_ipfile_err3.

ELSE.

APPEND st_temp3 TO gt_audit3.

ENDIF.

CLEAR : st_temp3,

st_temp_err,

st_ipfile_err3,

fl_set.

ENDLOOP.

REFRESH : gt_zrman,

0 Kudos
80

Hi,

As you are going to update an existing sales order, pass update flag as U to the header. i.e.

<b>ORDER_HEADER_INX-UPDATEFLAG = 'U'.</b>

But, you are adding a new line item to an existing sales order, so pass update flag as I to line item table and schedule lines table.

<b>ORDER_ITEM_INX-UPDATEFLAG = 'I'.

SCHEDULE_LINESX-UPDATEFLAG = 'I'.</b>

Reward points if the answer is helpful.

Regards,

Mukul

Former Member
0 Kudos
80

Hi,

Are you passing SCHEDULE_LINES & SCHEDULE_LINESX along with ORDER_ITEM_IN & ORDER_ITEM_INX to BAPI_SALESORDER_CHANGE ?

If not, then pass it. It will solve your problem.

If your problem persists, please paste your code here.

Regards,

Mukul