This is one more feature of ALV Which is shown here in ALV in Wendynpro as Totals and Subtotals Calculations.
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.This is a Webdynpro Application Explaining the Calculation of Totals in ALV Webdynpro.
First of all create a webdynpro application and introduce the alv component in the Used Component.
Now in the Component Usages add the component used...
Now in the Main window include the components in the Properties ...
Now create the node and its attribute.
Do the mapping of the node to the Data.Take Care for the Cardinality b'coz 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 WDDOINIT do the coding for the ALV.
First Binding the Data to the ALV Table and then instantiating the ALV and then Coding to display the Total in ALV.
Read the Node as above and then code.....
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.
data:
lr_comp_alv type ref to if_wd_component_usage,
lr_comp_if_alv type ref to iwci_salv_wd_table,
lr_config type ref to cl_salv_wd_config_table.
data: lr_column_settings type ref to if_salv_wd_column_settings,
lr_column type ref to cl_salv_wd_column,
lr_column_header type ref to cl_salv_wd_column_header.
data : lt_column type salv_wd_t_column_ref,
ls_column 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 = 'SFLIGHT' ).
*& Fetch flight data from database table
select mandt
carrid
connid
fldate
price
currency
planetype
seatsmax
seatsocc
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( ).
endif.
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
exporting
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( ).
endif.
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
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.
endmethod.
After the Window work is done create a Webdynpro Application for the Program.
Save and Activate the Total Program and test the Application.
The Total is Show for the Price As Below.
After you click the Sort the Subtotals are shown as Below.
This is all About the Totals and Subtotals in ALV Webdynpros.
No comments:
Post a Comment