Saturday, December 18, 2010

Totals and Subtotals in ALV Web Dynpro

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.

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 to 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.

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.

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites