Application Development 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: 

Regarding average in AT END option

Former Member
0 Kudos

Hi all,

Can anybody say me how can i do average at AT END.

I getting data from BSEG based on lifnr and i need to average DMBTR.We can do sum but how to do average after getting the sum since at that place we don't know how many records there for particular vendor.Tell me ASAP.

regards,

Sagar.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sagar,

Please try to use a variable and clear it at new of that field

and incremnet that in the loop

and Divide you sum with the counter value

Reward if Usefull

3 REPLIES 3

Former Member
0 Kudos

loop at itab.

v_count = v_count + 1.

v DMBTR = vDMBTR + itab-DMBTR.

at end of lifnr.

v_average = v_DMBTR / v_count.

clear : v_count , v_DMBTR.

endat.

endloop.

Former Member
0 Kudos

Hi Sagar,

Please try to use a variable and clear it at new of that field

and incremnet that in the loop

and Divide you sum with the counter value

Reward if Usefull

Former Member
0 Kudos

hi,,

chek this....hope it will be helpful

The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT-ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables.

The statement SUM calculates the component total with the numeric data type ( i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST , and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.