cancel
Showing results for 
Search instead for 
Did you mean: 

How do you add rows to table ???

Former Member
0 Kudos

Hi

I have an application, which displays data on click of button. The data is returned from a BAPI. I'm able to get the data and display it on table. I've made all the fields as Input Field Type. And I make append them and save it again in R/3 Server.

Now I want to add this table a complete new row. and then save it backend. How do we do this?? as the fields other than which returns the data are not editable...

Thanks in advance

Srikant

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Srikant,

From what I understand, your requirement is to display a set of table values from a BAPI/RFC, to which you can add your own set of values as well as edit the existing ones and then save the entire set back to R/3 through another BAPI/RFC. If this is your requirement, the replies already given would help you out. Anyway, what I am writing below is a consolidated form of the previous replies here, but I have tried to put it in a very simple way:

When you bind a table UI to a node, each row of the table corresponds to each element of the node. So initially, if you have no elements in the node, no <b>data</b> will be displayed in the table. But still whatever rowCount you have specified for the table, that many no: of <b>blank, non-editable</b> rows will be displayed. But, if you set the rowcount to -1, only those rows which has data ( by data, i just mean, the rows which have been intialized, the data can still be set to no value will be shown & obviously, this will be same as the no: of elements of the node. And when the celleditors of a table are some editable fields like input field, by default they will be in editable form for the rows with data, unless you specify it as readonly either through table property or through the inputfield property.

In your case, now you need to implement the add & edit functionalities. As I told, by default, the rows with data will be editable. So edit functionality is meaningless unless you set the UI element as readonly by default. You can either set the table as readonly by binding it to a context boolean attribute and then toggling it's value on the edit button click. In this case, the entire table will be editable once you click on the edit button. In case you want to make only the current row as editable, create a boolean attribute inside the table node and bind the readonly property of the inputfield to this attribute. If the node bound to the table is a model node, you need to create a non-singleton child node and then create the boolean attribute inside that node. Then you can toggle the value of this attribute on button click. If your requirement is something like this, we can discuss this in detail.

About the add functionality, the replies already given tells you exactly how to do that. The only thing you need to do is to create a new element for the node. Then a new editable row will be created for you, unless you have set the readonly property of the table as 'true'. As many have put it here, the code for creating a new element is :

IPrivate<View_name>.I<node_name>Element elmt = wdContext.create<node_name>Element();

elmt.set<Attribute1 name>("");

.

.

elmt.set<AttributeN name>("");

wdContext.node<node_name>().addElement(elmt);

If you are creating the node from the component or custom controller, replace the 'IPrivate' by 'IPublic' and <View name> by <controller name>.

If you still have problems with this, please do let us know the exact problems that you face.

Best Regards,

Nibu.

Former Member
0 Kudos

Hi Nibu,

Thanks for the effort summarising the whole of the discussion. I'm trying to implement this.

Firstly, I would to thank you for reply to my post.

Secondly, The requirement of edit is like as you mentioned. I have model node and I have to edit current row. I think if I understand i probably have to use the supply functions. Still can you tell me how to go about this?

Presently I have messed up with code and as a result I'm getting ArrayOutOfBoundsException. The reason being as I run my application automatically the first row gets higlighted. I don't know how to solve this issue. As i have changed every property and still no result.

Thanks once again

Srikant

Former Member
0 Kudos

Hi Nibu,

Let me explain few more things about the BAPIs.

They have been little modified.

The First BAPI is just dispalying data.

The Second BAPI is to do three operations: 1. Add, 2. Modify and Update 3. Remove.

For this we have included an import parameter TYPE which has to sent as input along with the TABLE. and they do the operation accordingly.

Previously simplest of update and remove worked without using the import parameter worked fine. But with the present TYPE parameter. Its not working fine.

and more than that presently the "ArrayOutOfBoundException" is happening.

Can you guide me from here.

Thanks for the patience for reading and helpin me out.

Srikant

Former Member
0 Kudos

Hi Srikant,

1) About the first row being selected : that is the lead selection of the node. If the 'initialize LeadSelection' property of the node is set to true, by default the first row will be set as selected. For model nodes by default it is set to true and I am not sure if we can set that to 'false' manually. But through code you can set any of the data rows as selected by

wdContext.node<node name>.setLeadSelection(<index of the req row>);

2) For edit functionality, let us say you have one input field per row. Create a non-singleton value node inside the node bound to the table. set the singleton property to false and cardinality to 1..1. Inside this node, create an attribute of type boolean. Bind the 'readonly' property of the inputfield to this attribute(let us call this attribute as 'readOnly'). Now when the user clicks on a particular row and click edit, you can set the input field as editable by:

wdContext.current<table node>Element().current<child node>Element().setReadOnly(false);

3) Abt, 'ArrayOutOfBoundsException', see the excepton trace and pick up the line which throws you the exception. If you could post that line here, we might be able to help you.

4) RFC Issues :

Try running the RFC from R/3 and make sure it works fine. If you just need to set a simple input parameter , all that you got to do is :

<BAPI name>Input input = new <BAPI name>Input();

input.set<input parameter>(<value>);

The rest of the code would remain the same.

Best regards,

Nibu.

Answers (8)

Answers (8)

Former Member
0 Kudos

Hi Srikant

I'm madhusudan. You are displaying your data on a table. If u make table using UI Element tools of WebDynpro , then u can add any no of rows. For that goto the properties of the table and then select 'VisibleRowCount' and change the no of rows as u wish. Save All Metadata.

I'm sending the following links for details of tables:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/tu... on creating tables in web dynpro - 11_0_.htm

and

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/tu... on creating a tree structure in a table - 27.htm

regards

Madhusudan

vijayakhanna_raman
Active Contributor
0 Kudos

Hi Srikanth,

As rathna said Visible is the attribute that has been binded to the property of the table(ie. show the no of visible rows) and the data type is integer.

If u want to expand the table,

1) initially write the code in the init method so that the 5 visible rows will be seen ,if the elements are added in the loop.

for(i=0;i<5;i++)

{

IPublicBokApplComp.ILi_List_Of_UsersNode node = wdContext.nodeLi_List_Of_Users();

IPublicBokApplComp.ILi_List_Of_UsersElement nodeElement = node.createLi_List_Of_UsersElement(new com.bok.trg.display.Zstable());

wdContext.nodeLi_List_Of_Users().addElement(nodeElement);

}

2) Then in the init method set the Visible attribute to 5, since the five rows are added initially

3)Then the following code can be written in the action event handler for Add Button...

/* to move to the last element and then get added*/

  • WdContwxt.node<Node name>.moveLast();

Where add is the attribute which is binded to an input field of type integer.. When u type the no of rows to be added, its get binded to the attribue add....

Finally the below code works

/* the no of rows to be added is given in the input field */

for(j=0;j<add;j++)

{

IPublicBokApplComp.ILi_List_Of_UsersNode node = wdContext.nodeLi_List_Of_Users();

IPublicBokApplComp.ILi_List_Of_UsersElement nodeElement = node.createLi_List_Of_UsersElement(new com.bok.trg.display.Zstable());

wdContext.nodeLi_List_Of_Users().addElement(nodeElement);

}

/* then by setting the visible attribute which is binded to the prorerty of table ie. show visible rows, the row expands automatically*/

int visible = wdContext.currentContextElement().getVisible();

visible = visible + add;

wdContext.currentContextElement().setVisible(visible);

Former Member
0 Kudos

Hi sri,

For more information check on to this link.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/tu... on creating tables in web dynpro - 11_0_.htm

Hope this might help u.

Regards,

Nagarajan.

Former Member
0 Kudos

Hi Srikant,

To add a row inside the table try this out sri,

IPrivate<viewname>.I<nodeelement> var=wdcontext.<node element>.createelement;

wdContext.<node>.addelement(var);

wdContext.<node>.movenext(var);

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

x=x+1;

wdContext.nodeList().setLeadSelection(x);

Check this out and reply me sri.

Regards,

Nagarajan.

Former Member
0 Kudos

Hi Nagarajan

I've tried the following code but it doesn't seem to work for me.


IPublicBokApplComp.ILi_List_Of_UsersNode node = wdContext.nodeLi_List_Of_Users();
	IPublicBokApplComp.ILi_List_Of_UsersElement nodeElement = node.createLi_List_Of_UsersElement(new com.bok.trg.display.Zstable());
    
   	wdContext.nodeLi_List_Of_Users().addElement(nodeElement);
  	 wdContext.nodeLi_List_Of_Users().moveNext();
   
   	int x = wdContext.nodeLi_List_Of_Users().size();
  	 x= x+1;
  	 wdContext.nodeLi_List_Of_Users().setLeadSelection(x);

this code i have written in method in controller and called in the action handler of button.

But it doesn't work for me.

Thanks

Srikant

Former Member
0 Kudos

Hi Srikant,

Have u tried the code that I posted u last.It works fine for adding elements inside the table.Is there any problem in it.If so let me know it yar so that i could correct it.

Regards,

Nagarajan.

Former Member
0 Kudos

Hi Nagarajan

The code which you gave me didn't work out for me.

I have stated my requirement. Can you think on the lines and give me a solution??

Thanks

Srikant

Former Member
0 Kudos

Hi Srikant,

For adding data into the table

1)create a table ui element and bind it to the node properties.

2)then in the implementation:

IPrivate(ur viewname).I(ur node element)x=wdContext.nodeVn_sendnode().create(ur nodeElement());

wdContext.nodeVn_sendnode().addElement(x);

suppose if u want to add name:

wdContext.currentVn_sendnodeElement().setVa_sendname(name);

wdContext.nodeVn_sendnode().moveNext();

This will add data inside ur table.

For deleting follow the same pocess instead of add element get the lead selection and give the removeelement(name) inside the implementation.

Hope this is clear.

Regards,

Nagarajan.

Former Member
0 Kudos

Hi Srikant,

U can add a row to the table using :

wdContext.nodeelement().addElement();

wdContext.nodeelement().moveNext();

If u want to delete it then:

wdContext.nodeelement().getLeadSelection();

wdContext.nodeelement().clearSelection(); (or)

wdContext.nodeList().removeElement(list);

I hope for editing u can use:

wdContext.nodeelement().bind();

Hope this helps u,

Regards,

Nagarajan.

Former Member
0 Kudos

Hi Nagarajan

Can you be more clear with adding and removing table as its quite unclear to me.

Thanks

Srikant

Former Member
0 Kudos

Hi Srikant,

You need to have some Button say "Insert" in your view. Create a new Action say "Insert" for this button in the "onAction" Event.

Say you table name is Item

In the event handler onActionInsert, write the following code.

I<Controller/View Name>.I<TableName>Node node = wdContext.node<TableName>();

I<Controller/View Name>.I<TableName>Element element = node.create<TableName>Element(new <Structure/Table>);

new <Structure/Table> is needed only if your table is bind to some structure/table in dictionary.

node.addElement(element);

Regards,

Shubham

Former Member
0 Kudos

Hi Subham

Sorry for getting back to you late.

Well our requirement has bit changed. The table now needs to be dispalyed. And a toolbar has to inserted with 3 different buttons. "ADD", "EDIT" and "REMOVE".

And accordingly I have to complete new row to a table, Edit an existing row and remove a row from the table and all these changes should be subsequently reflected in Backend server.

Is there any way its possible in Web Dynpro??

Thanks in advance

Srikant

Former Member
0 Kudos

Hi Srikant,

To Insert a toolbar, rightclick on the table and select insert toolbar. Now rightclick on the Toolbar and insert toolbarbuttons.

For ADD I gave you the logic.

For Remove

I<Controller/View Name>.I<TableName>Node node = wdContext.node<TableName>();

I<Controller/View Name>.I<TableName>Element element = node.create<TableName>Element(new <Structure/Table>);

int nodeSize = node.size();

int leadSelect = node.getLeadSelection();

for(int index=nodeSize-1; index>=0; index--){

if(node.isMultiSelected(index) || index == leadSelect){

element = node.<TableName>ElementAt(index);

node.removeElement(element);

}

}

This will remove single/multiple seleted rows.

For Edit, create a value attribute in your table

node of type boolean. Attach this to the read only property of each column editor of your table. When you load your table, loop through the table and set the value of this new value attribute to true.

On Click of Edit Button do like this.

int nodeSize = node.size();

int leadSelect = node.getLeadSelection();

for(int index=0; index<nodeSize; index++){

if(node.isMultiSelected(index) || index == leadSelect){

element = node.<TableName>ElementAt(index);

element.set<New Value Attr>(false);

node.removeElement(element);

}

}

This can set all the selected rows to editable.

To save this data to backend, I suggest, use another button SAVE in the Toolbar. Else it might be very slow performance depending on the amount of data, since you have to call the BAPI on every action.

Hope this helps.

Regards,

Shubham

Former Member
0 Kudos

Hi Shubham

Its been very helpful answer to me.

There is problem with "ADD" Button it still not working.

Let me state you my requirement.

1. User enters table display criteria and the table gets displayed.

2. now he wants to add complete new row. and clicks add button and a complete row with all editable fields and no values gets created in the table

3. user adds data and clicks save button and the data gets saved.

4. Next time he gives table display criteria he should be seeing all the old and newly entered entries.

How do go about this???

Thanks in advance

Srikant

Former Member
0 Kudos

hi srikant,

in the action method of the add button,do the following

create a nodeelement reference.

IPrivateNewappView.ITablenodeElement tab=wdContext.nodeTablenode().createTablenodeElement();

and add this to the node.

wdContext.nodeTablenode().addElement(tab);

bind the property visible row count of the table to a value attribute say visible.

get this attribute

int visible=wdContext.currentContextElement().getVisible();

and set it to a new value which is the sum of previous value and the new rows added.

visible=visible+add;

wdContext.currentContextElement().setVisible(visible);

Former Member
0 Kudos

Hi Srikant,

If you have implemented how to make a row display only, I think I know your problem.

Your add should be like this.

I<Controller/View Name>.I<TableName>Node node = wdContext.node<TableName>();

I<Controller/View Name>.I<TableName>Element element = node.create<TableName>Element(new <Structure/Table>);

new <Structure/Table> is needed only if your table is bind to some structure/table in dictionary.

element.set<New Value Attribute for Read Only>(true);

node.addElement(element);

If this is not helping, please cut and paste your code for Add Event.

Regards,

Shubham

Former Member
0 Kudos

Hi Rathna Ramamoorthy

Following is my code:


IPublicBokApplComp.ILi_List_Of_UsersNode node = wdContext.nodeLi_List_Of_Users();
    IPublicBokApplComp.ILi_List_Of_UsersElement nodeElement = node.createLi_List_Of_UsersElement(new com.bok.trg.display.Zstable());
    
    wdContext.nodeLi_List_Of_Users().addElement(nodeElement);
    
    int visible = wdContext.currentContextElement().getVisible();
    int add = wdContext.nodeLi_List_Of_Users().size();
    
    visible = visible + add;
    wdContext.currentContextElement().setVisible(visible);

It doesn't help me either. As nothing happens when i Click the button the lead selection nor the count of rows increases.

Can you help with this ??

Regards

Srikant

Former Member
0 Kudos

Hi Subham

The part of the code

"element.set<New Value Attribute for Read Only>(true);"

I can't write as that as the I've binded the table to model node which is binded to model and u can't declare any value attribute in that.

and for the Edit:

the problem is similar.

Regards

Srikant.

P.S. Nagarajan I've seen those documents before and other than row removal nothing is helping me.

Former Member
0 Kudos

Hi Srikant,

If you want to create a value attributes inside Model Nodes, you have to do something like this.

1) Create a Value Node in your context preferably with the same name as your model node.

2) Add a value attribute to this context.

3) Now right click on the Value Node and say Model Binding(to the Model) / Context Mapping (to the Model Node in some other Controller).

So now you can create the value attribute that can store whether a row is ReadOnly or not.

For your problem that you are not able to add, please post your complete node structure(you can restrict the value/model attributes to 3 if they are a lot).

Regards,

Shubham

Former Member
0 Kudos

Hi Madhusudan, Subham

Well all the help you provided to me doesn't seem to work for me. I'm till now able to remove a complete row only.

Editing and adding a row till now not happened.

For my application if someone can give me different approach. It will be great help. I don't know why the code doesn't work out for me

any new way of thinking will be great help for me.

Thanks in advance

Srikant

Former Member
0 Kudos

I recommend reading the book "Inside Web Dynpro for Java" by Chris Whealy. It explains the concepts of controllers, context, models etc. rather clearly.

Armin

Former Member
0 Kudos

Hi Srikant,

Please make a test project with the help of \Table Tutorial. Apply all our suggestions in that project first before trying this on you live project and see if it works. Also that will help you a lot in clearing all your concepts.

I guess we are missing something about your project/context/scenario.

Regards,

Shubham