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: 

compute total on a field based on change in values in 2 other fields

Former Member
0 Kudos
105

I have the following requirement

ITAB has fields

PO# PO_LINE# ............ PRICE

100 1 500

100 2 100

200 1 300

300 1 200

300 2 700

300 3 100

and my required output in ALV is

PO# PO_LINE# ............ PRICE

100 1 500

100 2 100

Total 600

200 1 300

Total 300

300 1 200

300 2 700

300 3 100

Total 1000

i want to compute the total price for each PO#.

Can someone please suggest how ?

Thank u so much.

8 REPLIES 8

Former Member
0 Kudos
73

ALV has the total and subtotal function,

why do you like this? may be you can use the idoc

Former Member
0 Kudos
73

Hello all,

Appreciate very much your responses...

but i have to also send this itab with total calculated via email as xls file. so i would want to do this at itab level and not for just alv display.

can i use any control break statements to achieve this ?

0 Kudos
73

Yes, you can use the control break statements. First sort the internal table and then in the loop u can use on change of PO(also check at new). do the sum.

Thanks and Regards,

C Naresh

0 Kudos
73

Hi,

Seems you are facing problem in using AT END on two fields since we cannot give AT END

on two fields in a single statement. If this is the case then you can use below approach.

Create another internal table and in this table give one column say KEY which will contain

concatenated value of fields PO# PO_LINE#. Sort internal table on this field KEY and

tThen loop this new table and Use AT END OK key(concatenated value of fields PO# PO_LINE#)

& SUM functinality.

Regards,

Pawan

Former Member
0 Kudos
73

HI,

I have one doubt whether total is field of itab or not?

Thanks

Arun

0 Kudos
73

@Pawan - i can't use PO&POLINE# together as key as i want to add the net price for all the line items of same PO

@ Arun - itab doesn't actually have the field value. the total of price for each po has to be added and displayed in field PRICE before the next PO row is displayed.

0 Kudos
73

If you want to add all line items of a PO then simply AT END of PO & SUM will do the job.

Former Member
0 Kudos
73

Hi,

I have given some sample code . Try this.

Data:ITTABfinal like ITTAB,

wa like line of ittab,

W_INDEX TYPE SY-TABIX,

w_flag type sy-tabix VALUE 1,

w_counter type sy-tabix VALUE 0.

data: w_total like wa-price.

ITTABfinal[] = ITTAB[].

loop at ittab into wa.

w_counter = w_counter + 1.

w_total = w_total + wa-price.

at end of po#.

clear wa.

wa-price = w_total.

w_INDEX = w_counter + w_flag.

insert wa into ittabfinal index W_INDEX.

w_flag = w_flag + 1.

CLEAR:w_total.

endat.

endloop.

Thanks

Arun