cancel
Showing results for 
Search instead for 
Did you mean: 

Error while adding and deleting line items

Former Member
0 Kudos

Hi all,

I have a Webdynpro application in which Im am trying to update a sales order.

I am using the bapi 'BAPI_SALESORDER_CHANGE'. In my WD application, I am executing the Bapi everytime the user clicks on 'Add' and 'Delete' buttons, after passing the relevant data to the backend. (One line item at a time)

Adding works fine until I delete a line. Once I delete a line item I get an error which says 'Item XXXXX cannot be changed' and after that 'Add' does not work. And this item POSNR displayed in the error message, is not the one I am passing through the WD code.

I am displaying the 'Posnr' values being sent to the Bapi and they are all correct. Im not sure, but seems like some kind of a "cache" problem. The posnr value that the bapi is taking is that of the previous operation.

However, if I run the application freshly, and try deleting the same line item, it gets deleted properly for the first time. Then the problem occurs from the second time onwards.

This is the method for deleting:

-


input.setL_Salesdocument(wdContext.nodeLi_Sales_Orders().currentLi_Sales_OrdersElement().getSd_Doc());

Bapisdh1X input_headerx = new Bapisdh1X();

input_headerx.setUpdateflag("U");

input.setL_Order_Header_Inx(input_headerx);

wdComponentAPI.getMessageManager().reportSuccess(toString());

Bapisditm item = new Bapisditm();

item.setItm_Number(wdContext.nodeLi_Order_Item().currentLi_Order_ItemElement().getPosnr().toString());

input.addLi_Order_Item_In(item);

Bapisditmx itemx = new Bapisditmx();

itemx.setItm_Number(wdContext.nodeLi_Order_Item().currentLi_Order_ItemElement().getPosnr().toString());

itemx.setUpdateflag("D");

input.addLi_Order_Item_Inx(itemx);

try

{

wdContext.currentZ_Change_Sales_Order_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

and this is for Add

-


input.setL_Salesdocument(wdContext.nodeLi_Sales_Orders().currentLi_Sales_OrdersElement().getSd_Doc());

Bapisdh1X input_headerx = new Bapisdh1X();

input_headerx.setUpdateflag("U");

input.setL_Order_Header_Inx(input_headerx);

wdComponentAPI.getMessageManager().reportSuccess(posnr+"");

Bapisditm item = new Bapisditm();

item.setItm_Number(<b>posnr</b>+"");

item.setMaterial(wdContext.nodeLi_Order_Item().currentLi_Order_ItemElement().getMatnr());

input.addLi_Order_Item_In(item);

Bapisditmx itemx = new Bapisditmx();

itemx.setItm_Number(<b>posnr</b>+"");

itemx.setUpdateflag("I");

itemx.setMaterial(true);

input.addLi_Order_Item_Inx(itemx);

Bapischdl schdl = new Bapischdl();

schdl.setItm_Number(<b>posnr</b>+"");

schdl.setReq_Qty(wdContext.nodeLi_Order_Item().currentLi_Order_ItemElement().getKwmeng());

input.addLi_Schedule_Lines(schdl);

Bapischdlx schdlx = new Bapischdlx();

schdlx.setItm_Number(<b>posnr</b>+"");

schdlx.setReq_Qty(true);

input.addLi_Schedule_Linesx(schdlx);

try

{

wdContext.currentZ_Change_Sales_Order_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

The posnr (in bold) value is being calculated manually.

Can someone tell me where I am going wrong?

Thanks and Regards,

Reena

Accepted Solutions (1)

Accepted Solutions (1)

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Reena,

Are you intializing the variable to null and then getting variable value from coresponding context element in each action event.

Like this:

input_headerx = null;

input_headerx = wdContext.nodeList().currentListElement().getHeaderx();

input.setL_Order_Header_Inx(input_headerx);

Regards, Suresh KB

Former Member
0 Kudos

Hi Suresh,

Thank you for the reply.

I have not done any initialiazation. I tried your code now but without this line :

input_headerx = wdContext.nodeList().currentListElement().getHeaderx();

But got a null pointer exception.

I dont understand what the above line does. I am unable to use it with my code. I trying the following, but there is no completion available.

input_headerx = wdContext.nodeL_Order_Header_Inx.currentL_Order_Header_InxElement.get

Can you please be more specific as to which variable I need to initialize?

Thanks and Regards,

Reena

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Reena,

You mentioned in the above that previous value come for second action so i asked whether you intializing the variable and getting the value before going for second action.

Regards, Suresh KB

Former Member
0 Kudos

Hi Suresh,

You were right. I had not created a new instance of my structure before moving to my second action. So it was using the values initialised in my first action.

Here is my code and it works perfectly now.

public void executesave1( )

{

//@@begin executesave1()

Z_Change_Sales_Order_Input input = new Z_Change_Sales_Order_Input();

wdContext.nodeZ_Change_Sales_Order_Input().bind(input);

// Update the Document number

input.setL_Salesdocument(wdContext.nodeLi_Sales_Orders().currentLi_Sales_OrdersElement().getSd_Doc());

// Update the Header Details - PONumber and Requested Delivery Date

Bapisdh1 input_header = new Bapisdh1();

input_header.setReq_Date_H(wdContext.currentContextElement().getReq_Del_Date());

input_header.setPurch_No_C(wdContext.currentContextElement().getPO_Number());

input.setL_Order_Header_In(input_header);

Bapisdh1X input_headerx = new Bapisdh1X();

input_headerx.setUpdateflag("U");

input_headerx.setReq_Date_H(true);

input_headerx.setPurch_No_C(true);

input.setL_Order_Header_Inx(input_headerx);

for (int i = deletelist.size()-1 ; i>=0 ; i--)

{

Bapisditm item = new Bapisditm();

item.setItm_Number(deletelist.get(i).toString());

input.addLi_Order_Item_In(item);

Bapisditmx itemx = new Bapisditmx();

itemx.setItm_Number(deletelist.get(i).toString());

itemx.setUpdateflag("D");

input.addLi_Order_Item_Inx(itemx);

}

try

{

wdContext.currentZ_Change_Sales_Order_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

}

public void executesave2( )

{

//@@begin executesave2()

// I had missed these lines, and had included it in end between the "@@Begin Others" and "@@end"

<b>

Z_Change_Sales_Order_Input input = new Z_Change_Sales_Order_Input();

wdContext.nodeZ_Change_Sales_Order_Input().bind(input);</b>

// Update the Document number

input.setL_Salesdocument(wdContext.nodeLi_Sales_Orders().currentLi_Sales_OrdersElement().getSd_Doc());

Bapisdh1X input_headerx = new Bapisdh1X();

input_headerx.setUpdateflag("U");

input.setL_Order_Header_Inx(input_headerx);

for (int i=wdContext.nodeLi_Order_Item().size()-1; i>=0 ; i--)

{

Bapisditm item = new Bapisditm();

item.setItm_Number(wdContext.nodeLi_Order_Item().getLi_Order_ItemElementAt(i).getPosnr().toString());

item.setMaterial(wdContext.nodeLi_Order_Item().currentLi_Order_ItemElement().getMatnr());

input.addLi_Order_Item_In(item);

Bapisditmx itemx = new Bapisditmx();

itemx.setItm_Number(wdContext.nodeLi_Order_Item().getLi_Order_ItemElementAt(i).getPosnr().toString());

itemx.setUpdateflag("I");

itemx.setMaterial(true);

input.addLi_Order_Item_Inx(itemx);

Bapischdl schdl = new Bapischdl();

schdl.setItm_Number(wdContext.nodeLi_Order_Item().getLi_Order_ItemElementAt(i).getPosnr().toString());

schdl.setSched_Line("0001");

schdl.setReq_Qty(wdContext.nodeLi_Order_Item().getLi_Order_ItemElementAt(i).getKwmeng());

input.addLi_Schedule_Lines(schdl);

Bapischdlx schdlx = new Bapischdlx();

schdlx.setItm_Number(wdContext.nodeLi_Order_Item().getLi_Order_ItemElementAt(i).getPosnr().toString());

schdlx.setSched_Line("0001");

schdlx.setReq_Qty(true);

input.addLi_Schedule_Linesx(schdlx);

}

try

{

wdContext.currentZ_Change_Sales_Order_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

//@@end

}

Thanks and Regards,

Reena

Answers (0)