cancel
Showing results for 
Search instead for 
Did you mean: 

how to calculate the total, subtotal and average of a column using abap webdynpro

Former Member
0 Kudos

Dear Exports

Greetings of the day! Can anyone kindly guide me how to calculate, Total, Subtotal and Average of a columns using webdynpro. I have created a wda to fetch the data from MBEW table with 5 fields(MATNR, SALK3, LBKUM, BWKEY, BKLAS) in sorted order. Now I need to calculate the subtotal of SALK3 based on the Valuation class(BKLAS) means subtotal for 3000, subtotal for 3001 and like this. Then total SALK3 which is the sum of all subtotals, the average of SALK3.

and I have written these codes in OnActionSearch event of the Search button.

DATA lo_nd_mbew_node TYPE REF TO if_wd_context_node.
TYPES: BEGIN OF STRUCT_MBEW,
        MATNR
TYPE MBEW-MATNR,
        BWKEY
TYPE MBEW-BWKEY,
        LBKUM
TYPE MBEW-LBKUM,
        SALK3
TYPE MBEW-SALK3,
        BKLAS
TYPE MBEW-BKLAS,
     
END OF STRUCT_MBEW.
DATA: it_mbew TYPE SORTED TABLE OF STRUCT_MBEW WITH NON-UNIQUE KEY BKLAS,
      wa_mbew
LIKE LINE OF it_mbew.

SELECT MATNR BWKEY BKLAS LBKUM SALK3 FROM MBEW INTO CORRESPONDING FIELDS OF

TABLE it_mbew UP TO 50 rows.

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


    lo_nd_mbew_node
= wd_context->get_child_node( name = 'MBEW_NODE' ).
    lo_nd_mbew_node
->bind_table( it_mbew ).

please anyone can help to complete this application.

Thanks and Regards

Rashmita

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Rashmitha,

pls Use below code u can get totals, and subtotals.......

loop at lt_column into ls_column.

   
case ls_column-id.

  


     

when 'PRICE'.
* aggregate field
       
call method lr_config->if_salv_wd_field_settings~get_field
         
exporting
            fieldname =
'PRICE'
          receiving
           
value     = lr_field_amnt.

* create aggregate rule as total
       
call method lr_field_amnt->if_salv_wd_aggr~create_aggr_rule
         
exporting
            aggregation_type = if_salv_wd_c_aggregation=>aggrtype_total
          receiving
           
value            = lv_aggr_rule.

   
endcase.
endloop.

For reference see this URL:-

http://www.saptechnical.com/Tutorials/WebDynproABAP/Totals/ALV.htm

Regards,

Venkat.

Former Member
0 Kudos

Thanks a lot for your valueable answer.Can I calculate the total, subtotal and average without using AVL. Because my client needs a normal object without using ALV.Because they have the falt file. So they need to upload it and calculate the sum, average and display it in browser. So if I use ALV it will be a complex application. So kindly BOSS guide me to solve this application in a simple way without using any ALV.My requirement is to display the fetched data with these 3 values. When a new BKLAS value will come on the above of that row a new row will added which contais the subtotal value SALK3 for all the same BKLAS. In ABAP this type of things we can do using Smartform. But here I have no need of use of ALV also.  So I m not able to understand how to display the new rows within this displayed table. Kindly help me.I have so many issues in my project and I am fresher one in this SAP platform.So I am facing a lot of problems. Please help me to solve the problem.     Please help me.

I m in deadline condition. please help me to solve the application.

Regards

Rashmita

Former Member
0 Kudos

Hi Rashmita,

Yes you can do the above without ALV.

1. Get the data in itab1.

2. Loop at itab1

3. Bind elements one by one to node

4. AT NEW BKLAS ,

     calulate total, subtotal and average as mentioned in my previos post. Create a new element and only bind the caluclated values in the element. So the element value will only have the value for SALK3 column and nothing else. Now bind this element to the node. Since the element will have only one value, the entire row will appear blank but only the total, subtotal and average will be seen in SALK3 column.

Hope this helps.

Former Member
0 Kudos

Hi,

You have the Internal table. What you need for total, subtotal and average is Normal ABAP Coding.

DATA: l_subtot, l_tot, l_avg.

Loop  at it_mebw INTO st_mebw.

    

     AT NEW BKLAS.

          CLEAR: l_subtot.

     ENDAT.

     l_subtot = l_subtot + st_mebw-SALK3.

     l_tot = l_tot + st_mebw-SALK3..

    

End Loop.

DESCRIBE TABLE it_mebw LINES l_lines.

l_avg = l_tot / l_lines.

Former Member
0 Kudos

Thanks a lot for your valueable answer.I have followed your codes. But whatever the calculated value means, subtotal of SALK3 based on the Valuation class BKLAS, total and average is not displayed on the browser. My requirement is to display the fetched data with these 3 values. When a new BKLAS value will come on the above of that row a new row will added which contais the subtotal value SALK3 for all the same BKLAS. In ABAP this type of things we can do using Smartform. But here I have no need of use of ALV also.  So I m not able to understand how to display the new rows within this displayed table. Kindly help me.I have so many issues in my project and I am fresher one in this SAP platform.So I am facing a lot of problems. Please help me to solve the problem.     

Please help me.

Regards

Rashmita