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

ALV Sorting and Subtotal

Former Member
0 Likes
929

Hi Experts,

In ALV, Is it possible to include into the subtotal line a value from a grouped column example as below?

Material Mix | Material Grade | Qty | Amount | Average Selling Price

Subtotal Line 1 A A1 100 2400 24

Subtotal Line 2 A A1 170 4500 26.47

Subtotal Line 3 A A1 250 6533 26.132

Subtotal Header A A1 620 13433 21.67

Where:

The Subtotal Lines are summed up Quantities and Amounts from Material Grouped Classification Mix and Material Grade (CL04)

The Average Selling Price subtotal Header is from 13433 / 620 = 21.67. And this value should be under the Average selling Price Column also.

Can it be done also in the Total Line sample?

Material Mix | Material Grade | Qty | Amount | Average Selling Price

Subtotal Line 1 A A1 100 2400 24

Subtotal Line 2 A A1 170 4500 26.47

Subtotal Line 3 A A1 250 6533 26.132

Subtotal Header A A1 620 13433 21.67

Subtotal Line 4 B B1 800 15000 18.75

Subtotal Header B B1 800 15000 18.75

Total 1420 28433 20.02

Where:

Total Qty is the total of Subtotal Header 620 + 800 = 1420 and Total Amount 13433 + 15000 = 28433 and the Total Average Selling Price is 28433 / 1420 = 20.02

Hi Experts,

In ALV, Is it possible to include into the subtotal line a value from a grouped column example as below?

Material Mix | Material Grade | Qty | Amount | Average Selling Price

Subtotal Line 1 A A1 100 2400 24

Subtotal Line 2 A A1 170 4500 26.47

Subtotal Line 3 A A1 250 6533 26.132

Subtotal Header A A1 620 13433 21.67

Where:

The Subtotal Lines are summed up Quantities and Amounts from Material Grouped Classification Mix and Material Grade (CL04)

The Average Selling Price subtotal Header is from 13433 / 620 = 21.67. And this value should be under the Average selling Price Column also.

Can it be done also in the Total Line sample?

Material Mix | Material Grade | Qty | Amount | Average Selling Price

Subtotal Line 1 A A1 100 2400 24

Subtotal Line 2 A A1 170 4500 26.47

Subtotal Line 3 A A1 250 6533 26.132

Subtotal Header A A1 620 13433 21.67

Subtotal Line 4 B B1 800 15000 18.75

Subtotal Header B B1 800 15000 18.75

Total 1420 28433 20.02

Where:

Total Qty is the total of Subtotal Header 620 + 800 = 1420 and Total Amount 13433 + 15000 = 28433 and the Total Average Selling Price is 28433 / 1420 = 20.02

4 REPLIES 4
Read only

Former Member
0 Likes
776

Created 2 Columns for the Average Price per Grade and Total Average Price for all selected Materials

Read only

Former Member
0 Likes
776

"types: BEGIN OF ITABmain,

MATGRADE TYPE C LENGTH 10,

  • MATNR TYPE MSEG-MATNR,

MATQTY TYPE MSEG-MENGE,

MATAMT TYPE MSEG-DMBTR,

avgr type mseg-menge,

line_color(4) type c, "Used to store row color attributes

END OF ITABmain.

data: itab type STANDARD TABLE OF itabmain WITH HEADER LINE,

itab1 type STANDARD TABLE OF itabmain WITH HEADER LINE,

wa LIKE LINE OF itab1.

data: varmatgrade like itab-matgrade.

  • ITAB-MATNR = '000000000030000002'.

ITAB-MATGRADE = 'A1'.

ITAB-MATQTY = '100'.

ITAB-MATAMT = '2400'.

APPEND ITAB.

data: sumdmbtr type mseg-dmbtr,

sumqty TYPE mseg-menge.

  • ITAB-MATNR = '000000000030000002'.

ITAB-MATGRADE = 'A1'.

ITAB-MATQTY = '170'.

ITAB-MATAMT = '4500'.

APPEND ITAB.

  • ITAB-MATNR = '000000000030000002'.

ITAB-MATGRADE = 'A1'.

ITAB-MATQTY = '250'.

ITAB-MATAMT = '6533'.

APPEND ITAB.

  • ITAB-MATNR = '000000000030000002'.

ITAB-MATGRADE = 'B1'.

ITAB-MATQTY = '800'.

ITAB-MATAMT = '15000'.

APPEND ITAB.

loop at itab into itab.

itab-avgr = itab-matamt / itab-matqty.

sumqty = sumqty + itab-matqty.

sumdmbtr = sumdmbtr + itab-matamt.

move itab-matgrade to itab1-matgrade.

append itab to itab1.

at end of matgrade.

CONCATENATE itab1-matgrade 'total' INTO itab-matgrade SEPARATED BY space.

itab-matamt = sumdmbtr.

itab-matqty = sumqty.

itab-avgr = itab-matamt / itab-matqty.

itab-line_color = 'C201'.

append itab to itab1.

wa-matamt = wa-matamt + sumdmbtr.

wa-matqty = wa-matqty + sumqty.

wa-avgr = sumdmbtr / sumqty.

wa-matgrade = itab1-matgrade.

clear: itab,sumdmbtr,sumqty.

ENDAT.

at LAST.

wa-matgrade = 'Grnd total'.

itab-line_color = 'C201'.

append wa to itab1.

ENDAT.

endloop."

Edited by: ZAHID HAMEED on Oct 20, 2011 4:05 PM

Read only

Former Member
0 Likes
776

Hi,

ALV has the default functionlity to ONLY Sum.

you can SUM and calculte avarge manually in Internal table by ABAP logic, and display new table in ALV.

but in this case where you are using sort function then it will mass up all the data that you are displaying.

Regards

Naresh

Read only

0 Likes
776

Yes SUM will just mass up all the average selling price in the Subtotal Line, but because each Average Selling Price is dependent on the subtotal qty and amount. I have to improvise, create 2 columns for CHAR 18 for subtotal Average Selling Price and Total Average Selling Price and Sort and Total them in ALV. It worked but not exactly the same format.