cancel
Showing results for 
Search instead for 
Did you mean: 

calculate total for a table column in wda

Former Member
0 Kudos

Hi Experts,

I m new to web dynpro abap...

I m doing one application on table(normal-not alv)..  in this i need to print total amount of the last column of the table...

In this i m entering data in 1st row and pressing enter.. then the total amount is displaying in the field which i designed at the bottom of the table..

But when i m entering the data in 2nd row and press enter the total amount is calculating based on the 1st row again but not current row...

Same problem is occuring when i entered 2nd...3rd...4th... etc.. every time total amount is calculating based on 1st row only... in debugger i came to know that

when i m getting the values of table for addition always 1st row value is coming into structure....

1)How can i get current row values into the structure....

2) and how can i add one more row dynamically when i click on row data(when i press enter-- on enter event of the input field of previous row)

helpful and correct answers wil get points....

Thanks in advance

Ramana

Accepted Solutions (1)

Accepted Solutions (1)

chengalarayulu
Active Contributor
0 Kudos

Hi Ramana,

To get current row:

data: lo_element type ref to if_wd_context_element.

lo_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).

lo_element->get_static_attributes( static_attributes = <static_attributes> ).

****** So now you can perform your calculations *******

To add new row to the Table:

nothing complex,,, just use bind_structure method.

data: lo_nd_table type ref to if_wd_context_node,

          lt_nd_table type <nd_table>,

          ls_nd_table type <nd_table_element>.

lo_nd_table = wd_context->get_child_node( <....> ).

lo_nd_table->bind_structure( ls_nd_table ).

OR...

append ls_nd_table to lt_nd_table.

lo_nd_table->bind_table( new_items = lt_nd_table set_initial_elements = abap_false ).

...................................

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi ramana,

Instead of adding the values row by row, you can get the entire table and add all the values as Kiran says. If you did code to add row by row and when you change the value you already entered, it will end up in wrong sum adding the changed value to already available table.

So I think its better to add the entire table and update the total value.

Regards,

Fareez

Former Member
0 Kudos

Hi Fareez,

Thank you for  ur valuble suggestion....

I did the same what kiran specified...

Now i m getting values exactly......

Thank you,

Ramana

former_member184578
Active Contributor
0 Kudos

Hi,

Check the below code,

DATA lo_nd_table TYPE REF TO if_wd_context_node.

   DATA lo_el_table TYPE REF TO if_wd_context_element.

   DATA lt_table TYPE wd_this->Elements_table.

   DATA ls_table TYPE wd_this->Element_table.

   DATA lv_price TYPE wd_this->Element_table-price.

*   navigate from <CONTEXT> to <table> via lead selection

   lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).

   

*  * Get all the table data

   lo_nd_table->get_static_attributes_table( importing table = lt_table ).

*  Enable selected row

   LOOP AT lt_table INTO ls_table.       

       lv_total = lv_total + ls_table-price.

   ENDLOOP.

 

 

*   Set lv_total to Total Input UI

Hope this helps u.,

If you are calling the onAction method for each row, set the total value to one global structure and read the current row and modify the global structure.

Thanks & Regards,

Kiran

Former Member
0 Kudos

thank u guyz.....

i followed both of urs solutions... now i got it.....

Thank you,

Ramana