cancel
Showing results for 
Search instead for 
Did you mean: 

Subtotal function in ALV report

Former Member
0 Kudos

Hi, experts,

I got a problem when creating an ALV report about billing document.

This ALV report include following info:

Billing date

Billing doc no.

Customer no.

Customer name

Material no.

Material name

Condition name

Qty

Unit price

Amount

Tax amount

Invoice total

The logic of subtotal for this report is:

In same billing document no.

1. If condition name=A, then subtotal Qty, Amount, Invoice total by material no.

2. If condition name ≠A, then subtotal Qty, Amount , Invoice total by condition name

Is it possible? How can I achieve it?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi YGWENDOLYN,

I think It is possible to display Sub-Total based on conditions.

While you are creating field catalog, use the if condition for the field "do_sum". i.e., IF CONDITION EQ A, then do_sum = 'X'

ELSE do_sum = space.

ENDIF.

Now, before calling the ALV display function module, use "slis_sortinfo_alv" to provide the SORT information again based on the IF Condition

IF CONDITION = A, then SORTINFO-fieldname = Material No.

ELSE. SORTINFO-fieldname = Condition name.

ENDIF.

Pass this table as well to the ALV Function Module. This should help you provide the sub-totals as you required.

<b>Reward points for helpful answers.</b>

Best Regards,

Ram.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi

Refer to this using FACTORY CLASSES:

Aggregations – CL_SALV_AGGREGATIONS

Since we sorted by CITYTO, we can add an aggregation to subtotal the DISTANCE by CITYTO. Create the object reference variable and receive the object using the GET_AGGREGATIONS method of the GR_TABLE object. Next, add the aggregation by calling the ADD_AGGREGATION method of the GR_SORTS object. We also need to modify the call to ADD_SORT to set the SUBTOTAL = ABAP_TRUE.

report zalvom_demo1.

data: ispfli type table of spfli.

data: gr_table type ref to cl_salv_table.

data: gr_functions type ref to cl_salv_functions.

data: gr_display type ref to cl_salv_display_settings.

data: gr_columns type ref to cl_salv_columns_table.

data: gr_column type ref to cl_salv_column_table.

data: gr_sorts type ref to cl_salv_sorts.

data: gr_agg type ref to cl_salv_aggregations.

data: color type lvc_s_colo.

start-of-selection.

select * into table ispfli from spfli.

cl_salv_table=>factory( importing r_salv_table = gr_table

changing t_table = ispfli ).

gr_functions = gr_table->get_functions( ).

gr_functions->set_all( abap_true ).

gr_display = gr_table->get_display_settings( ).

gr_display->set_striped_pattern( cl_salv_display_settings=>true ).

gr_display->set_list_header( 'This is the heading' ).

gr_columns = gr_table->get_columns( ).

gr_column ?= gr_columns->get_column( 'CITYTO' ).

gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ).

gr_column->set_short_text( 'This is sh' ).

gr_column ?= gr_columns->get_column( 'CITYFROM' ).

color-col = '6'.

color-int = '1'.

color-inv = '0'.

gr_column->set_color( color ).

gr_sorts = gr_table->get_sorts( ).

gr_sorts->add_sort( columnname = 'CITYTO' subtotal = abap_true ).

gr_agg = gr_table->get_aggregations( ).

gr_agg->add_aggregation( 'DISTANCE' ).

gr_table->display( ).

Regards

Preeti

<b>

Reward if useful</b>

Former Member
0 Kudos

hai,

you can Keep a separate Variable ,

Apply the formula u needed , then move all the values into that particular

variable and finally u write Variable as one of the field in ALV Report.

kiran_k8
Active Contributor
0 Kudos

Wong,

Just declare two different field catalogs w.r.t the condition.

if condition = A.

a field catalog having do_sum = 'X'

else

a field catalog without do_sum = 'X'.

Just try.It may give you som lead.

K.Kiran.

Former Member
0 Kudos

Hi,

This is not possible using ALV.

Former Member
0 Kudos

No it is not possible to do like that in ALV... go with clasical reporting.

Thanks

Mahesh

Former Member
0 Kudos

Hi, Mahesh

How can I use classical report to get the subtotal result? Thanks a lot.