cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Empty row to table

Former Member
0 Kudos

Hi All

In my requirement, when user click on add button i want to add empty rec as first record, then user enters data and save. i wrote some code for this. record is adding after last record in the table. how to add at first?? any help.

Thanks

kris.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

Please create a blank structure of type your table and insert the structure into the internal table that is binded to context at index 1. For more details please see the code below,

node = wd_context->get_child_node( name = wd_This->wdctx_n_sflight ).

node->get_static_attributes_Table(

IMPORTING

table = itab ).

INSERT ls_Sfl into itab index 1. " ls_Sfl is the structure or line that is being inserted.

node->bind_table( itab ).

With Regards,

Shridhar

Former Member
0 Kudos

Hi Sridhar,

Thanks that is working, points added.

can u tell this, when user select one record and click on copy button, i need to create new record with same data as selectd after that selected record. but my code is creating at last, same as mentioned for add.

Thanks,

kris.

Former Member
0 Kudos

You can get the index of selected row and then while inserting a new element increment the index by 1 to append it at row below the selected one..

try this .

Regards

Manas Dua

Former Member
0 Kudos

Hi,

For achieving this , you will need the index of selected row , which can be achieved through GET_LEAD_SELECTION_INDEX().

Once you have the index , insert a new row at the indexreturnd+1 to the internal table and bind it to the context.

Hope it helps,

Aditya.

Former Member
0 Kudos

Hi Aditya and Manas,

i am reading index using get_lead_selection_index.

ind = lo_nd_itab->get_lead_selectio_(index( ).

ind = ind + 1.

insert itab into stru index 'ind'.

lo_nd_it_result->bind_table( stru ).

i defined ind as type i.

i am getting error " Unable to interpret ind as a number".? please tel me how to solve?

Thanks,

kris.

Former Member
0 Kudos

Hi,

You can get the selected element by the using get_lead_selection method, read its attributes and bind the same to the node.

Please see below,

      • read lead selected element ***

node = wd_context->get_child_node( name = wd_This->wdctx_n_sflight ).

element = node->get_lead_selection( ).

element->get_Static_Attributes(

IMPORTING

static_Attributes = ls_Sfl ).

    • get index ***

index = element->get_index( ).

index = index + 1.

    • bind element ***

node->bind_structure(

EXPORTING

new_item = ls_Sfl

SET_INITIAL_ELEMENTS = ABAP_FALSE

index = index ).

Note : You need to take care of Primary Key matters.

With Regards,

Shridhar

Former Member
0 Kudos

Thanks sridhar for your help.

Thanks and Regards,

kris.

Answers (2)

Answers (2)

Former Member
0 Kudos

HI,

Check this thread:

While binding a new element to the context, make sure that index parameter is passed as 0 ( With the standard value 0 the new element is added as the first element ).

Regards

Manas Dua

Former Member
0 Kudos

Hi,

Can u post the way you followed to add a new row at the end??

Aditya.

Former Member
0 Kudos

Hi Aditya,

here the code :

stru type zemp.

lo_el_itab = lo_nd_itab->get_element.

lo_nd_itab->create_element( ).

lo_el_itab->get_static_attributes( importing static_attributes = stru ).

lo_nd_itab->bind_structure(exporting new_item = stru

set_initial_elements = abap_false ).

Thanks,

kris.

Former Member
0 Kudos

Hi,

The bind_structure() method has a paramater called index , try giving a value of 1(or 0..not sure) to that and check.

Aditya.