Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Compute average in ALV using do_sum using different columns

Former Member
0 Likes
653

Hi Experts,

I know that the fieldcat-do_sum = 'C' calculates average of specified column in ALV. But is there a possibility that it computes average of two other columns?

Here's an example of a scenario I was talking about.

Column A values:

100

200

-


300 - Total amount

Column B values:

500

100

-


600 - Total amount

Column C values:

400

100

-


250 - Average (Here's where do_sum was declared)

The expected output should be displayed in Column C but it needs to calculate B / A, ( 600 / 300 ).

Any suggestion will highly appreciated.

Thanks!

Aura

2 REPLIES 2
Read only

Former Member
0 Likes
422

Hi,

Yes, it´s possible. What type of ALV you are using? ALV_GRID or ALV_LIST?

- In ALV_LIST you can manipulate the data before is printed on screen, by event BEFORE_OUTPUT

- In ALV_GRID you can create a class and redefine the method set_data_table.

Best regards,

Leandro Mengue

Read only

Former Member
0 Likes
422

I had to calculate average in totals for a ALV report. This is how I achieved this.


* Change Total
  FIELD-SYMBOLS:
  <FT_TAB>   TYPE ANY TABLE,
  <FS_TAB>   TYPE ANY,
  <GAMNG>    TYPE ANY,
  <FKIMG>   TYPE ANY,
  <FAILRATE> TYPE ANY.

  TRY.
      CALL METHOD G_ALV->GET_SUBTOTALS
        IMPORTING
          EP_COLLECT00 = IT_01.

    CATCH CX_SY_REF_IS_INITIAL INTO LREF_EXCEP.
  ENDTRY.

  ASSIGN IT_01->* TO <FT_TAB>.

  LOOP AT <FT_TAB> ASSIGNING <FS_TAB>.
    ASSIGN COMPONENT 'FKIMG' OF STRUCTURE <FS_TAB> TO <FKIMG>.
    ASSIGN COMPONENT 'GAMNG'  OF STRUCTURE <FS_TAB> TO <GAMNG>.
    ASSIGN COMPONENT 'FAILRATE' OF STRUCTURE <FS_TAB> TO <FAILRATE>.
    IF <GAMNG> IS NOT INITIAL AND <FKIMG> IS NOT INITIAL.
      V_FAILRATE = ( <GAMNG> / <FKIMG> ) * 100.
      V_FAILRATE = V_FAILRATE * V_DATEDIF.
      <FAILRATE> = V_FAILRATE.
    ENDIF.
  ENDLOOP.

If you want to change subtotals you can call the method with EP_COLLECT01 instead of EP_COLLECT00