Totals and Subtotals in ALV Web Dynpro (Web Dynpro for ABAP)

By Richa Tripathi, Yash Technologies 

Scenario: To create a dynamic ALV based on a SFLIGHT context node in Web Dynpro for ABAP and display the TOTALS and SUBTOTALS in it.  

First, create a web dynpro application and include the ALV component in the “Used Web Dynpro Components”.  


Now in the Component Usages add the component used  

Now in the Main window include the components in the Properties.  

Create the node and its attribute.  

Do the mapping of the node to the Data. Take Care for the Cardinality. If the Cardinality is not proper, it gives a runtime error for cardinality.  

Now in the Layout, create the View Container in Which the ALV will be displayed.  

Now in the Methods tab in the DOINIT, enter the following code for the ALV.  

First bind the data to the ALV, instantiate the ALV and then code to display the Totals in ALV.  

   DATA lo_nd_sflight TYPE REF TO if_wd_context_node.
DATA lo_el_sflight TYPE REF TO if_wd_context_element.
DATA ls_sflight    TYPE        wd_this->elements_sflight.  

type ref to if_wd_component_usage,
type ref to iwci_salv_wd_table,
type ref to cl_salv_wd_config_table.

data: lr_column_settings type ref to if_salv_wd_column_settings,
type ref to cl_salv_wd_column,
type ref to cl_salv_wd_column_header.

data : lt_column type salv_wd_t_column_ref,
type salv_wd_s_column_ref.

data:  lr_field_amnt type ref to cl_salv_wd_field.

data: lv_aggr_rule   type ref to cl_salv_wd_aggr_rule.
data: lr_sort_rule   type ref to cl_salv_wd_sort_rule.
data  fs_flight      like line of ls_sflight.  

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

  lo_nd_sflight = wd_context->get_child_node( name = 

*& Fetch flight  data from database table
select mandt
from sflight
into corresponding fields
of   table ls_sflight.

call method lo_nd_sflight->bind_table( ls_sflight ).

*... ALV Component Usage
  lr_comp_alv = wd_this->wd_cpuse_alv_test2( ).

if lr_comp_alv->has_active_component( ) is initial.
    lr_comp_alv->create_component( ).

  lr_comp_if_alv = wd_this->wd_cpifc_alv_test2( ).

*... Configure ALV
  lr_config = lr_comp_if_alv->get_model( ).

call method lr_config->if_salv_wd_table_settings~set_selection_mode
value = cl_wd_table=>e_selection_mode-multi_no_lead.

*... ALV Component Usage
  lr_comp_alv = wd_this->wd_cpuse_alv_test2( ).

if lr_comp_alv->has_active_component( ) is initial.
    lr_comp_alv->create_component( ).

  lr_comp_if_alv = wd_this->wd_cpifc_alv_test2( ).

*... Configure ALV
 wd_this->lr_config = lr_comp_if_alv->get_model( ).

* display columns in correct order
  lr_column_settings ?= wd_this->lr_config.

  lt_column = lr_column_settings->get_columns( ).

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
            fieldname = 
value     = lr_field_amnt.

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



Now, in the Window add the View Container and the ALV Table in it.  

Create a Web dynpro Application for the Program.  

Activate and test the Application.  

The Total is displayed as shown below.  

After you click the sort, the Subtotals are shown as below.  

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image