group by - Make math operations on a grouped table -


my problem not in real programming language.

i have exercise in abap language not important language.

anyway, have table:

see picture

i need make total cost of position(after select obviously). then, table grouped 2 fields (matnr , bukrs), need know each group total cost max, total cost min , total cost average of positions.

however need simple algorithm solve problem (pseudo-code).

i hope clear.

for table aggregations find @ functions within loop handy.

sort fields according dimensions need , sort values within ascending or descending.

the order of fields important here, because @ looks changes in specified field , fields left of in same row. handle group group , append result of group aggregation result table.

loop @ lt_itab assigning <ls_itab>.   @ new bukrs. "at first entry of combination matnr, bukrs     ls_agg-matnr = <ls_itab>-matnr.     ls_agg-bukrs = <ls_itab>-bukrs.   endat.    try.     add <ls_itab>-amount lf_sum.   catch cx_sy_arithmetic_overflow.      lf_sum = 9999.   endtry.    lf_count = lf_count + 1.   if <ls_itab>-amount > lf_max.      lf_max = <ls_itab>-amount.   endif.    @ end of bukrs. "after last entry of combination matnr,bukrs     ls_agg-avg = lf_sum / lf_count.     ls_agg-max = lf_max.     append ls_agg lt_agged.     clear: ls_agg, lf_sum, lf_count, lf_max.   endat. endloop. 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -