cancel
Showing results for 
Search instead for 
Did you mean: 

Edit a single row in a table

Former Member
0 Kudos

Hi All,

I have a requirement to display a table in the non editable mode intially. The user when selects a row and selects a button(EDIT) the selected row should be editable.

Also When add row button is clicked it should add an empty row and the user should be able to add new records in the table.

Please let me know how this can be achieved.

Thanks for the help.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Do this way....

1.When you click on the EDIT the selected row should be editable.

Take an attribute READONLY type ABAP_BOOL and this attribute to READ ONLY property of your table.

write event handler method for EDIT buton action.here read your context node use GET_STATIC_ATTRIBUTES method to receive the selected row information.

Now modify your internal table with readonly value is ABAP_FALSE.

thats all your selected row will be in Editable.

2.When add row button is clicked it should add an empty row and the user should be able to add new records in the table.

do same as above

Thaks

Suman

TomVanDoo
Active Contributor
0 Kudos

Build your table with input fields.

Your table is bound to your context node.

your context node is populated by a supply method.

In the supply method, add every line seperately. (node->add_element ) (this returns an element object which you will need)

set the properties for the element (every field in the node has some properties, among which read_only) (element->setprop something)

bind the read_only property of your input fields to the respective read_only property of your context attribute (look at the special option, bind property in the binding popup)

as a result you will now have an editable table with all fields ineditable.

now when you select an element in the table and press edit, you can retrieve the selected element (node->get_lead_selection or node->get_selection_collection, or ... something similar, see what best fits your needs.)

for the retrieved element(s) set the properties again (element->setprops something..)

specifically turn off the read_only property.

As an extra tip here: Do NOT have existing keyfields editable. In other words, check if the record existed already in the database. If yes, keep the key fields read_only. if not, you can have them editable.

same goes for adding a row. you push the button add.

the code simply adds an empty element to the node (node->add_element) and you leave all properties blank (which they are by default, so no extra work there)