on 09-19-2011 12:00 PM
Hi experts i have problem with total and subtotal in alv. If i create context node with dictionary structure in my case SPFLI everything works fine, total is counted right - i have aggregation on DISTANCE column and sort rule on DISTID column. but if context node doesnt have dictionary structure total is counted wrong - it means miles and kilometrs are calculated together.
Please get me solution
Hi,
The other way possible (without using dictionary structure) is using Intermediate Results. You can show intermediate results with a little more coding.
Pls check thi out:
<a>http://help.sap.com/saphelp_nw2004s/helpdata/en/43/2582509fb24e85e10000000a422035/content.htm</a>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
please find below a piece of code. hope this will solve your problem
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,
LT_COLUMN1 TYPE SALV_WD_T_COLUMN_REF,
LS_COLUMN TYPE SALV_WD_S_COLUMN_REF,
LR_CONFIG TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
DATA LV_VALUE TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
DATA: LR_FIELD_AMNT TYPE REF TO CL_SALV_WD_FIELD.
LT_COLUMN = LR_COLUMN_SETTINGS->GET_COLUMNS( ).
LOOP AT LT_COLUMN INTO LS_COLUMN.
*
CASE LS_COLUMN-ID.
WHEN 'CTX_VN_ORDER_QTY'.
* aggregate field
CALL METHOD LV_VALUE->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
EXPORTING
FIELDNAME = 'CTX_VN_ORDER_QTY'
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.
CLEAR LR_FIELD_AMNT.
WHEN 'CTX_VN_TOT_LI'.
* aggregate field
CALL METHOD LV_VALUE->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
EXPORTING
FIELDNAME = 'CTX_VN_TOT_LI'
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.
Regards,
Sahai.s
data: lo_alv type ref to iwci_salv_wd_table,
lo_config type ref to cl_salv_wd_config_table,
lo_field type ref to cl_salv_wd_field,
lo_sort type ref to cl_salv_wd_sort_rule.
1. Instantiate the alv.
2. Get reference of ALV interface controller using wd_cpifc_<comp_name>.
3. follow the code below.
lo_config = lo_alv->get_model( ).
lo_field = lo_config->if_salv_wd_field_settings~get_field( 'DISTID' ).
lo_sort = lo_field->if_salv_wd_sort~create_sort_rule( ).
lo_sort->set_group_aggregation( ).
lo_field = lo_config->if_salv_wd_field_settings~get_field( 'DISTANCE' ).
lo_field->if_salv_wd_aggr~create_aggr_rule( ).
lo_config->if_salv_wd_field_settings~set_group_aggr_displayed( ).
Hope it helps...
hi,
> please find below a piece of code. hope this will solve your problem
>
>
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,
> LT_COLUMN1 TYPE SALV_WD_T_COLUMN_REF,
> LS_COLUMN TYPE SALV_WD_S_COLUMN_REF,
> LR_CONFIG TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
> DATA LV_VALUE TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
> DATA: LR_FIELD_AMNT TYPE REF TO CL_SALV_WD_FIELD.
>
> LT_COLUMN = LR_COLUMN_SETTINGS->GET_COLUMNS( ).
>
> LOOP AT LT_COLUMN INTO LS_COLUMN.
> *
> CASE LS_COLUMN-ID.
>
>
> WHEN 'CTX_VN_ORDER_QTY'.
> * aggregate field
> CALL METHOD LV_VALUE->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
> EXPORTING
> FIELDNAME = 'CTX_VN_ORDER_QTY'
> 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.
> CLEAR LR_FIELD_AMNT.
>
> WHEN 'CTX_VN_TOT_LI'.
> * aggregate field
> CALL METHOD LV_VALUE->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
> EXPORTING
> FIELDNAME = 'CTX_VN_TOT_LI'
> 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.
> Regards,
> Sahai.s
your code isnt suitable for me because i have column with quantity and column with mass unit of distance
Edited by: jorgen.polack on Sep 20, 2011 3:06 PM
data: lo_alv type ref to iwci_salv_wd_table,
> lo_config type ref to cl_salv_wd_config_table,
> lo_field type ref to cl_salv_wd_field,
> lo_sort type ref to cl_salv_wd_sort_rule.
>
> 1. Instantiate the alv.
> 2. Get reference of ALV interface controller using wd_cpifc_<comp_name>.
> 3. follow the code below.
>
> lo_config = lo_alv->get_model( ).
>
> lo_field = lo_config->if_salv_wd_field_settings~get_field( 'DISTID' ).
> lo_sort = lo_field->if_salv_wd_sort~create_sort_rule( ).
> lo_sort->set_group_aggregation( ).
>
> lo_field = lo_config->if_salv_wd_field_settings~get_field( 'DISTANCE' ).
> lo_field->if_salv_wd_aggr~create_aggr_rule( ).
> lo_config->if_salv_wd_field_settings~set_group_aggr_displayed( ).
>
> Hope it helps...
it doesnt work because i cant have context with dictionary structure - total is calculated wrong...
Edited by: jorgen.polack on Sep 20, 2011 3:44 PM
Hi,
I dont understand why do u need a context node with dictionary structure. You do not require a context node with dictionary structure for this code to work.
I created a context node in Component Controller: NODE_TEST
NODE_TEST is binded to DATA node of the ALV.
NODE_TEST has two attributes:
1. ATTR_SORT Type string - on which the sort id based.
2. ATTR_ADD Type i - on which the aggregation is based.
Now i wrote the following code in wddoinit method of comp controller:
DATA: lo_node TYPE REF TO if_wd_context_node,
lt_tab TYPE wd_this->elements_test,
ls_tab TYPE wd_this->element_test.
CLEAR ls_tab.
ls_tab-sort = 'KM'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ls_tab-sort = 'KM'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ls_tab-sort = 'KM'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ls_tab-sort = 'KM'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ls_tab-sort = 'MI'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ls_tab-sort = 'MI'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ls_tab-sort = 'MI'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ls_tab-sort = 'MI'.
ls_tab-add = 10.
APPEND ls_tab TO lt_tab.
lo_node = wd_context->get_child_node( 'NODE_TEST' ).
lo_node->bind_table( lt_tab ).
DATA: lo_alv TYPE REF TO iwci_salv_wd_table,
lo_config TYPE REF TO cl_salv_wd_config_table,
lo_field TYPE REF TO cl_salv_wd_field,
lo_sort TYPE REF TO cl_salv_wd_sort_rule.
DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
lo_cmp_usage = wd_this->wd_cpuse_alv( ).
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.
lo_alv = wd_this->wd_cpifc_alv( ).
lo_config = lo_alv->get_model( ).
lo_field = lo_config->if_salv_wd_field_settings~get_field( 'SORT' ).
lo_sort = lo_field->if_salv_wd_sort~create_sort_rule( ).
lo_sort->set_group_aggregation( ).
lo_field = lo_config->if_salv_wd_field_settings~get_field( 'ADD' ).
lo_field->if_salv_wd_aggr~create_aggr_rule( ).
lo_config->if_salv_wd_field_settings~set_group_aggr_displayed( ).
This is displaying me correct additions..
Hi,
> I dont understand why do u need a context node with dictionary structure. You do not require a context node with dictionary structure for this code to work.
>
> I created a context node in Component Controller: NODE_TEST
> NODE_TEST is binded to DATA node of the ALV.
> NODE_TEST has two attributes:
> 1. ATTR_SORT Type string - on which the sort id based.
> 2. ATTR_ADD Type i - on which the aggregation is based.
>
> Now i wrote the following code in wddoinit method of comp controller:
> DATA: lo_node TYPE REF TO if_wd_context_node,
> lt_tab TYPE wd_this->elements_test,
> ls_tab TYPE wd_this->element_test.
>
>
> CLEAR ls_tab.
> ls_tab-sort = 'KM'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
>
> CLEAR ls_tab.
> ls_tab-sort = 'KM'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
>
> CLEAR ls_tab.
> ls_tab-sort = 'KM'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
>
> CLEAR ls_tab.
> ls_tab-sort = 'KM'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
>
> CLEAR ls_tab.
> ls_tab-sort = 'MI'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
>
> CLEAR ls_tab.
> ls_tab-sort = 'MI'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
> CLEAR ls_tab.
> ls_tab-sort = 'MI'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
> CLEAR ls_tab.
> ls_tab-sort = 'MI'.
> ls_tab-add = 10.
> APPEND ls_tab TO lt_tab.
>
> lo_node = wd_context->get_child_node( 'NODE_TEST' ).
> lo_node->bind_table( lt_tab ).
>
>
> DATA: lo_alv TYPE REF TO iwci_salv_wd_table,
> lo_config TYPE REF TO cl_salv_wd_config_table,
> lo_field TYPE REF TO cl_salv_wd_field,
> lo_sort TYPE REF TO cl_salv_wd_sort_rule.
> DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
>
> lo_cmp_usage = wd_this->wd_cpuse_alv( ).
> IF lo_cmp_usage->has_active_component( ) IS INITIAL.
> lo_cmp_usage->create_component( ).
> ENDIF.
> lo_alv = wd_this->wd_cpifc_alv( ).
>
> lo_config = lo_alv->get_model( ).
>
> lo_field = lo_config->if_salv_wd_field_settings~get_field( 'SORT' ).
> lo_sort = lo_field->if_salv_wd_sort~create_sort_rule( ).
> lo_sort->set_group_aggregation( ).
>
> lo_field = lo_config->if_salv_wd_field_settings~get_field( 'ADD' ).
> lo_field->if_salv_wd_aggr~create_aggr_rule( ).
> lo_config->if_salv_wd_field_settings~set_group_aggr_displayed( ).
>
>
>
> This is displaying me correct additions..
i have tried your code - subtotals are correct, it means 40 km and 40 miles but total is not correct it shows 80 but correct values have to be 40 mil and 40 km.
Edited by: jorgen.polack on Sep 21, 2011 9:26 AM
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.