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: 

Help with BAPI_SALEORDER_CHANGE FM

former_member55105
Participant
0 Kudos

Hi All

I am trying to update a saleorder through the function module BAPI_SALEORDER_CHANGE. I am able to update the header part of the saleorder. But when it comes to the item level, I am unable to update any field (e.g., I am unable to update the REQ_QTY(Order Quantity) field of the SCHEDULE_LINES table). Will anyone plz let me know whether I need to update any other entry for this or some other logic in involved in it?

Plz do the needful.

Thanks in advance,

Vijay.

20 REPLIES 20

former_member534411
Participant
0 Kudos

Hi Vijay,

Post your code.

Regards,

Suresh

0 Kudos

Hi

To update the saleorder, I am uploading the data from the XML file and I am assigning it to the respective parameters of the func. mod.

I dont have any problem in updating the order_header_in parameter. But I am unable to update the schedule_lines parameter(this parameter contains req_qty field which i want to update).

call function 'BAPI_SALESORDER_CHANGE'

exporting

salesdocument = salesdocument

order_header_in = order_header_in

order_header_inx = order_header_inx

  • SIMULATION =

  • BEHAVE_WHEN_ERROR = ' '

  • INT_NUMBER_ASSIGNMENT = ' '

  • LOGIC_SWITCH =

tables

return = return

order_item_in = order_item_in

order_item_inx = order_item_inx

  • PARTNERS =

  • PARTNERCHANGES =

  • PARTNERADDRESSES =

  • ORDER_CFGS_REF =

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CFGS_BLOB =

  • ORDER_CFGS_VK =

  • ORDER_CFGS_REFINST =

SCHEDULE_LINES = schedule_lines

SCHEDULE_LINESX = schedule_linesx

  • ORDER_TEXT =

  • ORDER_KEYS =

  • CONDITIONS_IN =

  • CONDITIONS_INX = * EXTENSIONIN =

.

I hope this info. is sufficent, if not just revert me back.

Thanks,

Vijay.

0 Kudos

Hi Vijay,

Can you give the code to populater each field of the parameters and tables that your are passing to the FM?

Did you pass the unit of measure also??

What is the error that you are getting?

Regards,

Ravi

0 Kudos

Hi,

schedule_linesx-ITM_NUMBER = item-number.

schedule_linesx-REQ_DATE = 'X'.

Append schedule_linesx.

Did you added above logic in your code.

Regards,

Suresh

0 Kudos

schedule_linesx-ITM_NUMBER = item_number or 'X'??? I suppose it will be 'X', bcoz we are updating the index here.

0 Kudos

Hi Ravi

I am not getting any error. But after updating, when I check my saleorder in VA02 TCODE, I see that my item level information is not updated.

order_header_inx-updateflag = 'U'.

order_header_inx-sales_org = 'X'.

order_header_inx-distr_chan = 'X'.

order_header_inx-division = 'X'.

order_header_inx-sales_off = 'X'.

order_header_inx-purch_no_c = 'X'.

order_header_inx-req_date_h = 'X'.

order_header_inx-purch_date = 'X'.

append order_header_inx.

order_item_inx-updateflag = 'U'.

order_item_inx-material = 'X'.

order_item_inx-plant = 'X'.

order_item_inx-target_qu = 'X'.

order_item_inx-itm_number = 'X'.

append order_item_inx.

schedule_linesx-updateflag = 'U'.

schedule_linesx-req_qty = 'X'.

schedule_linesx-itm_number = 'X'.

append schedule_linesx.

Note: result_tab is an internal table containing the values for each field.

order_header_in-sales_org = result_tab-cvalue.

order_header_in-distr_chan = result_tab-cvalue.

order_header_in-division = result_tab-cvalue.

order_header_in-sales_off = result_tab-cvalue.

order_header_in-purch_no_c = result_tab-cvalue.

order_header_in-purch_date = result_tab-cvalue.

order_header_in-req_date_h = result_tab-cvalue.

append order_header_in.

order_item_in-material = result_tab-cvalue.

order_item_in-plant = result_tab-cvalue.

order_item_in-target_qu = result_tab-cvalue.

order_item_in-itm_number = result_tab-cvalue.

  • Appending the Order_Item_In table.

append order_item_in.

partners-partn_role = result_tab-cvalue.

partners-partn_numb = result_tab-cvalue.

append partners.

schedule_lines-itm_number = result_tab-cvalue.

schedule_lines-req_qty = result_tab-cvalue.

  • Appending the schedules_lines table.

append schedule_lines.

Then I am calling the bapi_saleorder_change func. mod. for updating.

Revet me back asap.

Thanks,

Vijay.

0 Kudos
* Schedule lines
  IT_SCHEDULE_LINES-ITM_NUMBER  = '000010'.
  IT_SCHEDULE_LINES-SCHED_LINE  = '0001'.
  CONCATENATE X_FILE-REQDT+4(4)
              X_FILE-REQDT+0(4)
        INTO  IT_SCHEDULE_LINES-REQ_DATE.
  IT_SCHEDULE_LINES-REQ_QTY    = X_FILE-QTY.
  APPEND IT_SCHEDULE_LINES.
  CLEAR IT_SCHEDULE_LINES.

  IT_SCHEDULE_LINESX-ITM_NUMBER  = '000010'.
  IT_SCHEDULE_LINESX-SCHED_LINE  = '0001'.
  IT_SCHEDULE_LINESX-REQ_DATE    = 'X'.
  IT_SCHEDULE_LINESX-REQ_QTY    = 'X'.
  IT_SCHEDULE_LINESX-UPDATEFLAG  = 'U'.
  APPEND IT_SCHEDULE_LINESX.
  CLEAR IT_SCHEDULE_LINESX.

Regards

vijay

0 Kudos

>schedule_linesx-updateflag = 'U'.

>schedule_linesx-req_qty = 'X'.

<b>schedule_linesx-itm_number = 'X'.</b><<<<<--- wrong...

Check it with my code.

Regards

vijay

0 Kudos

Hi Vijay

I changed it to schedule_linesx-itm_number = '000010'. But now I am getting the message type as

'Sales document 0000008317 was not changed

219 E'.

Just let me know, wht shud i do now?

0 Kudos
* Requirement header
  V_VBELN = X_FILE-NUMBER.

*Requested Delivery Date and updata indicator
  CONCATENATE X_FILE-REQDT+4(4)
              X_FILE-REQDT+0(4)
        INTO  X_ORDER_HEADER_IN-REQ_DATE_H.

*  X_ORDER_HEADER_IN-REQ_DATE_H  = X_FILE-REQDT.
  X_ORDER_HEADER_INX-UPDATEFLAG = 'U'.
  X_ORDER_HEADER_INX-REQ_DATE_H = 'X'.

*-Line Item
  IT_ORDER_ITEM_IN-ITM_NUMBER = '000010'.
*-Quantity and Update indicator
  IT_ORDER_ITEM_IN-TARGET_QTY = X_FILE-QTY.
  IF NOT   X_FILE-QTY IS INITIAL.
    IT_ORDER_ITEM_IN-SALES_UNIT = X_FILE-UOM.
  ENDIF.

  APPEND IT_ORDER_ITEM_IN.
  CLEAR IT_ORDER_ITEM_IN.



  IT_ORDER_ITEM_INX-ITM_NUMBER = '000010'.
  IT_ORDER_ITEM_INX-UPDATEFLAG = 'U'.
  IT_ORDER_ITEM_INX-TARGET_QTY = 'X'.
* Start STC0003
  IF NOT X_FILE-UOM IS INITIAL.
    IT_ORDER_ITEM_INX-SALES_UNIT = 'X'.
  ENDIF.
* End STC0003

  APPEND IT_ORDER_ITEM_INX.
  CLEAR IT_ORDER_ITEM_INX.

* Schedule lines
  IT_SCHEDULE_LINES-ITM_NUMBER  = '000010'.
  IT_SCHEDULE_LINES-SCHED_LINE  = '0001'.
  CONCATENATE X_FILE-REQDT+4(4)
              X_FILE-REQDT+0(4)
        INTO  IT_SCHEDULE_LINES-REQ_DATE.
  IT_SCHEDULE_LINES-REQ_QTY    = X_FILE-QTY.
  APPEND IT_SCHEDULE_LINES.
  CLEAR IT_SCHEDULE_LINES.

  IT_SCHEDULE_LINESX-ITM_NUMBER  = '000010'.
  IT_SCHEDULE_LINESX-SCHED_LINE  = '0001'.
  IT_SCHEDULE_LINESX-REQ_DATE    = 'X'.
  IT_SCHEDULE_LINESX-REQ_QTY    = 'X'.
  IT_SCHEDULE_LINESX-UPDATEFLAG  = 'U'.
  APPEND IT_SCHEDULE_LINESX.
  CLEAR IT_SCHEDULE_LINESX.

  CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
      SALESDOCUMENT               = V_VBELN
      ORDER_HEADER_IN             = X_ORDER_HEADER_IN
      ORDER_HEADER_INX            = X_ORDER_HEADER_INX
*     SIMULATION                  =
*     BEHAVE_WHEN_ERROR           = ' '
*     INT_NUMBER_ASSIGNMENT       = ' '
*     LOGIC_SWITCH                =
    TABLES
      RETURN                      = IT_RETURN1
      ORDER_ITEM_IN               = IT_ORDER_ITEM_IN
      ORDER_ITEM_INX              = IT_ORDER_ITEM_INX
      SCHEDULE_LINES              = IT_SCHEDULE_LINES
      SCHEDULE_LINESX             = IT_SCHEDULE_LINESX
      .

this is what i did and it is working for me.., can you make your code in order so that it is easy to see what you are doing..

Regards

vijay

0 Kudos

Hi Vijay

Suppose I have more than 1 item in a salesorder. Then will the SCHEDULE_LINES-SCHED_LINE(Schedule Lines) field differ for each item in tht saleorder?

Plz revert me back asap.

Regards,

Vijay.

0 Kudos

then you need to append the items.it depends up on your requirement. it will differ for each item.

Regards

vijay

0 Kudos

Hi Vijay

How can I append a new item to an existing saleorder using the function module BAPI_SALEORDER_CHANGE?

Your early response is highly appreciated.

Thanks in advance,

Vijay.

0 Kudos

Hi Vijay,

you have item table parameter, if you have many items append all items.

and for this item you have to set the update flag.

say some thing like this..

*-Line Item

IT_ORDER_ITEM_IN-ITM_NUMBER = '000010'.

*-Quantity and Update indicator

IT_ORDER_ITEM_IN-TARGET_QTY = X_FILE-QTY.

IF NOT X_FILE-QTY IS INITIAL.

IT_ORDER_ITEM_IN-SALES_UNIT = X_FILE-UOM.

ENDIF.

APPEND IT_ORDER_ITEM_IN.

CLEAR IT_ORDER_ITEM_IN.

IT_ORDER_ITEM_INX-ITM_NUMBER = '000010'.

IT_ORDER_ITEM_INX-UPDATEFLAG = 'U'.

IT_ORDER_ITEM_INX-TARGET_QTY = 'X'.

IF NOT X_FILE-UOM IS INITIAL.

IT_ORDER_ITEM_INX-SALES_UNIT = 'X'.

ENDIF.

APPEND IT_ORDER_ITEM_INX.

CLEAR IT_ORDER_ITEM_INX.

similarly for other items..also you have to do the same..

...but only item number and quantity changes.

Regards

vijay

0 Kudos

Hi Vijay

The following is the code with which I am trying out. I am adding a second new item.

data: salesdocument like bapivbeln occurs 0 with header line,

order_header_in like bapisdh1 occurs 0 with header line,

order_header_inx like bapisdh1x occurs 0 with header line,

order_item_in like bapisditm occurs 0 with header line,

order_item_inx like bapisditmx occurs 0 with header line,

partners like bapiparnr occurs 0 with header line,

schedule_lines like bapischdl occurs 0 with header line,

schedule_linesx like bapischdlx occurs 0 with header line,

  • conditions_in like bapicond occurs 0 with header line,

  • conditions_inx like bapicondx occurs 0 with header line,

return like bapiret2 occurs 0 with header line.

order_header_inx-updateflag = 'U'.

order_header_inx-sales_org = 'X'.

order_header_inx-distr_chan = 'X'.

order_header_inx-division = 'X'.

order_header_inx-sales_off = 'X'.

order_header_inx-purch_no_c = 'X'.

order_header_inx-req_date_h = 'X'.

order_header_inx-purch_date = 'X'.

append order_header_inx.

order_item_inx-updateflag = 'U'.

order_item_inx-material = 'X'.

order_item_inx-plant = 'X'.

order_item_inx-itm_number = '000020'.

append order_item_inx.

schedule_linesx-updateflag = 'U'.

schedule_linesx-req_qty = 'X'.

schedule_linesx-itm_number = '000020'.

SCHEDULE_LINESx-SCHED_LINE = '0001'.

append schedule_linesx.

order_item_in-itm_number = '000020'.

order_item_in-material = '000000000000000877'.

order_item_in-plant = 'JNJ1'.

append order_item_in.

schedule_lines-req_qty = 44.

append schedule_lines.

call function 'BAPI_SALESORDER_CHANGE'

exporting

salesdocument = salesdocument

order_header_in = order_header_in

order_header_inx = order_header_inx

  • SIMULATION =

  • BEHAVE_WHEN_ERROR = ' '

  • INT_NUMBER_ASSIGNMENT = ' '

  • LOGIC_SWITCH =

tables

return = return

order_item_in = order_item_in

order_item_inx = order_item_inx

  • PARTNERS =

  • PARTNERCHANGES =

  • PARTNERADDRESSES =

  • ORDER_CFGS_REF =

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CFGS_BLOB =

  • ORDER_CFGS_VK =

  • ORDER_CFGS_REFINST =

SCHEDULE_LINES = schedule_lines

SCHEDULE_LINESX = schedule_linesx

  • ORDER_TEXT =

  • ORDER_KEYS =

  • CONDITIONS_IN = conditions_in

  • CONDITIONS_INX = conditions_inx

  • EXTENSIONIN =

.

if sy-subrc ne 0.

write: return-message,return-number,return-type.

else.

write: return-message,return-number,return-type.

call function 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

endif.

O/P:

Sales document 0000008317 was not changed

219 E

Plz respond me asap.

Thanks,

Vijay.

0 Kudos

Hi,

order_header_in where you populating?

i am not able to see any where in your code....?

Regards

vijay

0 Kudos

Hi

Here is the missing code. I have included it but missed to include it.

order_header_in-sales_org = 'JNJ1'.

order_header_in-distr_chan = '02'.

order_header_in-division = 'J1'.

order_header_in-sales_off = 'JNJ1'.

order_header_in-purch_no_c = 'XMLFileUpload2'.

order_header_in-purch_date = '20060101'.

order_header_in-req_date_h = '20060201'.

append order_header_in.

But the output is same.

Regards,

Vijay.

0 Kudos

hi,

try with some other order.

Regards

vijay

former_member181962
Active Contributor
0 Kudos

Hi Vijay,

did you pass a 'X' to the SCHEDULE_LINESX-REQ_QTY?

Regards,

Ravi

0 Kudos

Yup I did that. I have updated the scheule_linesx parameter.