cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Line items in BAPI_PO_CREATE

Former Member
0 Kudos

Hi Everyone,

I am trying to create a webdynpro application for Creating a Purchase Order using "BAPI_PO_CREATE". Could you help in getting the code for adding a new line item while creating a purchase order using the above BAPI. Adding a new line item means similar to that of in the Transaction "ME21N". I need a table where each row is for a line item. Let me know if my question is not clear.

Please help me resolve this issue. I would appreciate your help.

Regards,

Gopal.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If the PO is already in ERP and you are adding another line to it, you will need to use BAPI_PO_CHANGE. Pass in the first line item (with any changed data), and also the second line item (the new one), in the table parameter POITEM.

Former Member
0 Kudos

Hi Michael,

Thanks a lot for your reply. I think my explanation was not very clear.

As I explained before, I want to create a Purchase Order using "BAPI_PO_CREATE". We are able to create a purchase order for one line item. But, in order to create for Multiple line items (i.e., ordering more than one item like a keyboard, mouse, hard drive etc in one Purchase Order). This can be done in ME21 transaction by adding additional line in a table. We are looking for a similar functionality. So, what is the element in the BAPI structure that understands that the end user is trying to input multiple line items??

And how do I acheive my requirement. Please help me in this regards, I would appreciate your help.

I hope this explains my requirement in abit more detail. Let me know if you need more information.

Regards,

Gopal.

Former Member
0 Kudos

Hello Everyone,

Any Updates. Please help me to resolve this. I would appreciate your help.

Regards,

Gopal.

former_member197348
Active Contributor
0 Kudos

Hi Gopal,

You can solve it by creating and adding new elements of POITEM node. In wdDoInit() type this code,

for (i=0; i<10;i++)
{
IPrivate<viewname>.I<poitemnode> node = wdContext().node<poitemnode>();
IPrivate<viewname>.I<poitemelement> elem = node.create<poitemelement>();
node.addElement(elem);
 }

You will get 10 rows enabled. If you want more number of elements then you can also do it.

Create a button "AddRows" and in action event handler you should add the above code.

Regards,

Siva

Former Member
0 Kudos

Hi Siva,

Thanks a lot for your reply. But, how do I give the option of inputting more than one line item? Do you know what I mean? Please help me to resolve this problem, I would appreciate your help.

Regards,

Gopal.

former_member197348
Active Contributor
0 Kudos

Hi Gopal,

The code I gave you is for adding empty elements to the POITEM table.

1) If that POITEM table is directlybound to the UI table then you can enter the item details in the table. This does not require any extra coding.

2) If that POITEM table is not directlybound to the UI table then you need to create empty elements to the node which is bound to the table and enter the item details in the table. Use the following code for adding multiple elements to the POITEM table before caling BAPI.

int size = wdContext.node<tablenode>().size();
for(int i=0;i<size;i++)
{
// create POITEM element
IPrivate<viewname>.I<poitemelement> elem = node.create<poitemelement>();
//set all the required elements
elem.set<attribname>(wdContext.node<tablenode>().get<tablenode>ElementAt(i).get<attribname>());
-------------------------
-------------------------
//finally add the element to the node
wdContext().node<poitemnode>().addElement(elem);

}

Hope I have made it clear to you.

Regards,

Siva

Former Member
0 Kudos

Hi Gopal,

You already got answer in above few postings. Let me summarise you.....

1) Create a table and bind that to the line items node.

2) Create a button by name "add new line item" and under that action create a element to the table node.

That is whenever a user clicks on the button, a new row in the table will be enabled allowing the user to input values.

This can be done by the code what sivarama krushna has provided, just remove the for loop in that code.

3) Create another button to execute BAPI, So whenever the user click on this button the BAPI will be executed as the node

binded to table will hold multiple line items. These values will be given as input parameters to the BAPI.

4) To check this, after adding two or three line items. Just check the node size of Table Node with the following code.

Integer in = new Integer(wdContext.nodeA().Size());

String siz = in.toString();

wdComponentAPI.getMessageManager().reportSuccess(siz);

Hope this will defenitely help you, revert me if you have any doubts.

Regards

Raghu.

Former Member
0 Kudos

Hi Raghu,

Thanks a lot for your reply. When you say "Tablenode" is that "POITEM Node"? I'll try to follow this process and will update about the progress. Thanks a lot for your help.

Regards,

Gopal.

Former Member
0 Kudos

Hi Raghu,

I have just tested the application and I think it is fine up to some extent. Because, when I click on "Add new Line Item" it is just copying the values from the first row. Which we really dont want to copy. Do you know what I mean? How do I eleminate the copying of the first row to the second row?

Regards,

Gopal.

Former Member
0 Kudos

Hi,

How can it copy the elements of first row to second row?

I told to create a button for adding new rows, in that button action you create new element for that PO node like

Ipriateview.IPOele ele = wdContext.nodePO().CreatePOelement();

wdContext.nodePO().addelement(ele);

Probably you are using bind(ele) change this as the code in bold above.

revert me for any other questions.

Regards

Raghu

Former Member
0 Kudos

Hi Everyone,

Sorry for re-opening this question again. I have got further requirement relating to this question. So, I thought of re-opening this question instead of posting a new thread.

Is there any way that we can Bind the table that I created to two nodes? Because, in my table I need to bind attributes from two different nodes. But, I am not able to bind the table to two nodes. Could you please help me in resolving this issue. I would appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

Hi Gopal,

Its not possible.At runtime u can change the binding dynamically.

Regards,

srikanth

Edited by: Srikanth Thatipally on Jul 27, 2009 12:54 PM

Former Member
0 Kudos

Hello,

Thanks a lot for your reply. I "dont think" it is not possible to Bind two context nodes to one table UI Element. Because, I have found a thread which details about the similar problem. But, I am not able to apply that method in my case as I am a bit confused. The thread is as follows.

Regards,

Gopal.

former_member197348
Active Contributor
0 Kudos

Hi Gopal,

Can you please explain the scenario why you require two nodes in one table?

Why don't you make the two nodes into one?

If the attributes are different in both nodes then you can create a node with all the attributes and copy the data into the new node.

If the all attributes' names are in both the nodes then create node and copy the nodes one after the other.

If the nodes have parent and child relationship then you can show them in one table if and only if the child node is non-singleton and its cardinality is x..1

Regards,

Siva

Former Member
0 Kudos

Hi Siva,

Thanks a lot for your reply. The reason why I need two nodes binded to one table is, because in the BAPI_PO_CREATE, the node po_items doesn't have the attribute "Quantity". The "Quantity" attribute is present in "po_schedules" model node. So, when I am trying to create a new line item in the table by binding it to the "po_items" node, in the same row of the table I want to allow the user to enter the "Quantity" of the Line item. Do you understand what I mean?

For this requirement, I need to bind the "Quantity" attribute of "po_schedules" item to the Table that is binded to "po_items". I think this makes my requirement clear. If you need more clarification, please let me know. I would appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

Hi Gopal,

Did you try with inserting a additional column to the table and mapping the table cell editor to the attribute of other node.

As you are trying to insert the values to the BAPI it may suffice your requirement.

Regards

Raghu

Former Member
0 Kudos

Hi Raghu,

Yes I tried this way already. The problem is,when I add a new line item, it will add the "Qunatity" column but it is only accepting one value at a time. For example:- If I enter "Quantity" as 15 for Line Item "1" and "Quantity" as 25 for Line Item "2". The Quantity field in the Line Item "1" is defaulting to "25"(i.e., the value from Line Item "2"). Do you understand what I mean? So, didn't help me really. Please help me to resolve this issue. I would appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

Hi Siva,

As you said previously, how do I make the two nodes into one. Because, when I am trying to create a custom model node and copy and paste the required attributes from the two different nodes. I am getting an error message saying the custom Model node is not binded to any model (i.e BAPI context). So, could you please explain me how to make one node from the attributes of two different nodes. Please help me to resolve this issue. I would appreciate your help.

Regards,

Gopal.

former_member197348
Active Contributor
0 Kudos

Hi Gopal,

Create value node with the same attribute names and type as that of po_items node and one more extra attribute for quantity.

Use

WDCopyService.copyElements(wdContext.node<modelnode>, wdContext.node<valuenode>);

to copy elements from Po_items node to your created value node. Then you can use WDCopyService for loop to copy values to quantity attribute.

regards,

Siva

Former Member
0 Kudos

Hi Siva,

Thanks a lot for your help. I'll try this and will let you know if it works.

Regards,

Gopal.

Former Member
0 Kudos

Hi Siva,

How do I copy the "Quantity" element in to the new "Value Node"? Because, the new "Value node" is already copied with the "po_Items" model node. So, If I do it the following way, do you think it is right?


WDCopyService.copyElements(wdContext.nodePo_Items(),wdContext.nodePo_Item1());
WDCopyService.copyElements(wdContext.nodePo_Item_Schedules(), wdContext.nodePo_Item1());

Also, where should I give this Code? Should I give this in the Component Controller or the View Controller.

Please let me know about this. I would appreciate your help.

Regards,

Gopal.

Edited by: Gopal on Jul 28, 2009 12:25 PM

Former Member
0 Kudos

Hi,

WdCopyService is hellpfull whenever you need to copy entire attributes of one node to the other.

If you want some attributes to filled from one node and the other attributes be filled by other node, then you need to add elements to the new node using a for loop like

NODEA

-


a

b

NODEB

-


c

d

e

and your new Node should be

NODEC

-


a

b

c

d

e

f

first check which node has more elements like

if(wdContext.NODEA().size() > wdContext.NODEB().size()

int x = wdContext.NODEA().size();

else

int x = wdContext.NODEB().size();

for(int i=0; i < x ; i++)

{

//create a element for NODEC

ele.setA()........and so on

wdContext().nodeC().addElement(ele);

}

by this you will NODEC filled with the above structure mentioned.

Regards

Raghu

Former Member
0 Kudos

Hi Raghu,

Thanks a lot for your reply. I tried your method. Now, I have got a different problem. I managed to combine the two model nodes "A" and "B" into one Value node "C". Now, I binded my table to Value node "C". I have also created two tables and binded them to node A and node B. Now, once the user inputs the values in to the table of Node "C" before executing the BAPI, I should copy the values of the table "C" to the tables of Node "A" and Node "B".

So, for copying the values from one table to another, I followed the following code.


IPrivate<Name>View.ISourceValueNode iSourceValueNode= wdContext.nodeSourceValueNode();
IPrivate<Name>View.ISourceValueElement iSourceValueElement;

IPrivate<Name>View.ITargetRFC Element iTargetRFCElement;

for(int i=0;i<wdContext.nodeTargetRFC().size();i++){

iTargetRFCElement = wdContext.nodeTargetRFC().getTargetRFCElementAt(i);
iSourceValueElement = iSourceValueNode.createSourceValueNodeElement();

iSourceValueElement.set<attribute name>(iTargetRFCElement.get<Attribute name>());

iSourceValueNode.addElement(iSourceValueElement);
iSourceValueNode.moveNext();
}

But, the values are copying in to the second rows of tables "A" and "B" and leaving the first row as Blank. How can I avoid this? Do you understand what I mean?

My explanation might a bit confusing. Let me know if you need more clarification. Thanks a lot for your help and support.

Regards,

Gopal.

Former Member
0 Kudos

HI,

Remove the following code and try

iSourceValueNode.moveNext();

or try the following code it is more simple

for(int i=0;i<target.size();i++)

{

IPrivate<<node>>.ISourcenodeElement ele = wdContext.node<<sourcenode>>().createSourcenodeElement();

ele.setAttribute(wdContext.nodeTarget().getTargetnodeElementAt(i).getAttribute());

wdContext.nodeSource().addElement(ele);

}

Regards

Raghu

Former Member
0 Kudos

Hi Raghu,

I am having a similar problem. I hope the Webdynpro expert here can help since I am very new to Webdynpro.

I need to create Multiple INPUT Line item and then call a BAPI to post. I created a table and Binded w/ the 'Item' Node. Created a button "Add New Line".

It gives me an Error of "Assertion Violated" error. I think I am having some Code Error. Please tell me where/how to add code to add additional line to the item section?

Thanks all,

Marie

Answers (6)

Answers (6)

Former Member
0 Kudos

HI,

implement a code simlar to

int i=1;

IPrivateSamappView.ISNode node = wdContext.nodeS();

IPrivateSamappView.ISElement elem = node.createSElement();

node.addElement(i,elem);

i=i+1;

under action of the button

in your code..

Regards,

satya

Former Member
0 Kudos

Hi gopal,

1) Create element to POITEM node.

2) use setxxxxxxxxxxx() to set the values.

3) add this element to POITEM node.

4) execute the bapi

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi gopal,

second item details also u bind to same context attributes that will not override.

finally u call that bapi that time all the details will go to bapi (including sencond line items).

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi Sunaina,

Thanks for your reply. I tried the way you said but, it doesn't work that way. It is not taking the two line items. It is just overwriting the the second item with the data of the first item. What is the flag in the BAPI that tells it that the user wants to enter more than 1 line items. Do you understand my problem.

Regards,

Gopal.

Former Member
0 Kudos

Hi gopal,

Ur explanation is correct.

already u did for single item details na so u create one button for multiple line items. when the user clicks that button u enter second item details. after that u create one submit button, in that submit button u call "BAPI_PO_CREATE" bapi.

Regards,

Sunaina Reddy t

Former Member
0 Kudos

Hi Sunaina,

Thanks a lot for your reply. So, how do I bind the second Item values to the context of the BAPI? How does the BAPI know that the user is entering multiple line items? Did you get me?

Regards,

Gopal.

former_member192434
Active Contributor
0 Kudos

Hi Gopal,

If i remember correctly there not much to do while creating PO application, simply you have to call the BAPI and pass the mendotry parameter to it ..

Note: if it ask for some input data is missing then you have pass all the input value to it manually thr WDA coding.

Thanks

Former Member
0 Kudos

Hi Anup,

Thanks a lot for your reply. You are right. I have created the Purchase order Application with all the basic Input and Output parameters and it is all working fine apart from the requirement of adding Multiple Line Items. As I explained in my previous post, we need to give the end users an option to add multiple line items. So, when they want to order two different items from the same Vendor, they enter the first Item and then for the second Item they click on a button and that adds a new Row in the table where they enter the Item details in the second row of the Items table. Let me know if my explanation is not very clear or if you need more clarification of my requirement. I would appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

HI,

try this.

As u said u have a button which upon clicking will create a new row.

under the action method of the button,

IPrivateView<yourview>.IprivateNode<yournode> node = wdContext().node<yournode>();

IPrivateView<Yourview>.IPrivateElement<yourelem> elem = node.create<yournode>Element();

node.add(elem);

Regards,

Satya.

Former Member
0 Kudos

Hi,

U can check line item details in "EKPO" table.

U can check header details in "EKKO" table.

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi Sunaina,

Thanks alot for your reply. Can you explain me how do I implement the process of adding Multiple Line Items to a Purchase Order.

My requirement is that "When a user wants to add an additional Line Item to a purchase order, then they click a button and they get another row added to the Table". Do you know how to acheive this. I would appreciate your help.

Regards,

Gopal.