second and third line item is NOT updating using `bapi_salesorder_change`

4.5k views Asked by At

My requirement is change sales order item details.
For this i am using BAPI_SALESOPDER_CHANGE.

  1. For one line item it is working fine.
  2. Sales order which contains two line items, for line item 10 its updating quantity but for 20 line item it updates with random vale.
  3. SO which contains three items it shows exception.

My code is here:

 DATA: SALESDOCUMENT        TYPE           BAPIVBELN-VBELN.  
 DATA: LT_ORDER_HEADER_INX  TYPE TABLE OF  BAPISDH1X,  
        LS_ORDER_HEADER_INX  TYPE           BAPISDH1X.

DATA: LT_ORDER_ITEM_IN     TYPE TABLE OF   BAPISDITM,  
       LS_ORDER_ITEM_IN    TYPE           BAPISDITM.

DATA: LT_ORDER_ITEM_INX    TYPE TABLE OF   BAPISDITMX,     

       LS_ORDER_ITEM_INX    TYPE            BAPISDITMX.
DATA: LT_SCHEDULE_LINES    TYPE TABLE OF   BAPISCHDL,            
      LS_SCHEDULE_LINES    TYPE            BAPISCHDL.   
DATA: LT_SCHEDULE_LINESX   TYPE TABLE OF   BAPISCHDLX,   
      LS_SCHEDULE_LINESX   TYPE            BAPISCHDLX.

DATA: LT_RETURN            TYPE TABLE OF   BAPIRET2,    
      LS_RETURN            TYPE            BAPIRET2.

PARAMETERS: p_sonum        TYPE            BAPIVBELN-VBELN.   
  LS_ORDER_HEADER_INX-UPDATEFLAG = 'U'.    
LS_ORDER_ITEM_IN-ITM_NUMBER = 10.    
LS_ORDER_ITEM_IN-TARGET_QTY = 22.    
APPEND LS_ORDER_ITEM_IN TO LT_ORDER_ITEM_IN.    
clear: LS_ORDER_ITEM_IN.    

LS_ORDER_ITEM_IN-ITM_NUMBER = 20.    
LS_ORDER_ITEM_IN-TARGET_QTY = 33.      
APPEND LS_ORDER_ITEM_IN TO LT_ORDER_ITEM_IN.     
clear: LS_ORDER_ITEM_IN.   

LS_ORDER_ITEM_IN-ITM_NUMBER = 30.     
LS_ORDER_ITEM_IN-TARGET_QTY = 44.      
 APPEND LS_ORDER_ITEM_IN TO LT_ORDER_ITEM_IN.     
clear: LS_ORDER_ITEM_IN.     

LS_ORDER_ITEM_INX-ITM_NUMBER = 10.    
LS_ORDER_ITEM_INX-UPDATEFLAG = 'U'.     
 LS_ORDER_ITEM_INX-TARGET_QTY = 'X'.     
APPEND LS_ORDER_ITEM_INX TO LT_ORDER_ITEM_INX.      
clear:LS_ORDER_ITEM_INX.      

LS_ORDER_ITEM_INX-ITM_NUMBER = 20.    
LS_ORDER_ITEM_INX-UPDATEFLAG = 'U'.    
LS_ORDER_ITEM_INX-TARGET_QTY = 'X'.   
APPEND LS_ORDER_ITEM_INX TO LT_ORDER_ITEM_INX.    
clear:LS_ORDER_ITEM_INX.   

LS_ORDER_ITEM_INX-ITM_NUMBER = 30.    
LS_ORDER_ITEM_INX-UPDATEFLAG = 'U'.    
LS_ORDER_ITEM_INX-TARGET_QTY = 'X'.    
APPEND LS_ORDER_ITEM_INX TO LT_ORDER_ITEM_INX.   
clear:LS_ORDER_ITEM_INX.   

LS_SCHEDULE_LINES-ITM_NUMBER  = 10.   
LS_SCHEDULE_LINES-SCHED_LINE  = 1.    
LS_SCHEDULE_LINES-REQ_QTY     = 22.    
APPEND LS_SCHEDULE_LINES  TO LT_SCHEDULE_LINES.    
clear:LS_SCHEDULE_LINES.

LS_SCHEDULE_LINES-ITM_NUMBER  = 20.   
LS_SCHEDULE_LINES-SCHED_LINE  = 2.    
LS_SCHEDULE_LINES-REQ_QTY     = 33.    
APPEND LS_SCHEDULE_LINES  TO LT_SCHEDULE_LINES.    
clear:LS_SCHEDULE_LINES.     

LS_SCHEDULE_LINES-ITM_NUMBER  = 30.     
LS_SCHEDULE_LINES-SCHED_LINE  = 3.      
LS_SCHEDULE_LINES-REQ_QTY     = 44.    
APPEND LS_SCHEDULE_LINES  TO LT_SCHEDULE_LINES.     
clear:LS_SCHEDULE_LINES.      

LS_SCHEDULE_LINESX-ITM_NUMBER  = 10.    
LS_SCHEDULE_LINESX-SCHED_LINE  = 1.   
LS_SCHEDULE_LINESX-UPDATEFLAG  = 'U'.   
LS_SCHEDULE_LINESX-REQ_QTY     = 'X'.    
APPEND LS_SCHEDULE_LINESX TO LT_SCHEDULE_LINESX.   
CLEAR: LS_SCHEDULE_LINESX.     

LS_SCHEDULE_LINESX-ITM_NUMBER  = 20.   
LS_SCHEDULE_LINESX-SCHED_LINE  = 2.   
LS_SCHEDULE_LINESX-UPDATEFLAG  = 'U'.    
LS_SCHEDULE_LINESX-REQ_QTY     = 'X'.    
APPEND LS_SCHEDULE_LINESX TO LT_SCHEDULE_LINESX.   
CLEAR: LS_SCHEDULE_LINESX.    

LS_SCHEDULE_LINESX-ITM_NUMBER  = 30.    
LS_SCHEDULE_LINESX-SCHED_LINE  = 3.   
LS_SCHEDULE_LINESX-UPDATEFLAG  = 'U'.     
LS_SCHEDULE_LINESX-REQ_QTY     = 'X'.     
APPEND LS_SCHEDULE_LINESX TO LT_SCHEDULE_LINESX.    
CLEAR: LS_SCHEDULE_LINESX.      

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'     
  EXPORTING       
    salesdocument               = p_sonum     
    order_header_inx            = LS_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 .        


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'       
 EXPORTING     
   WAIT          =  'X'
3

There are 3 answers

0
NewGuyInJava On

In addition to adding leading zeros, I think the line item numbers are 1,2,3 not 10,20,30 try running the code with single number increments. And also post the result of lt_return if it does not work.

2
Ivaylo On

Please make sure, that the line item numbers you are passing to the BAPI are with leading zeros.

0
Gert Beukema On

The schedule lines are tied to the order lines so they should start renumbering per order item.

So, in your example all lines like

LS_SCHEDULE_LINES-SCHED_LINE  = ???.

and

LS_SCHEDULE_LINESX-SCHED_LINE  = ???.

should be

LS_SCHEDULE_LINES-SCHED_LINE  = 1.

and

LS_SCHEDULE_LINESX-SCHED_LINE  = 1.