Hi,
Use the logic.
person month amount1 amount2
A jan rs.500(1) rs.1000 (3)
A feb rs.500 (2) rs.1000
B jan rs.1000(1) rs.2000(4)
B feb rs.1500(2) rs.2000
B mar rs.1000(3) rs.1000
Sort it on person.
take temporary variables for Person.
g_1 and g_2.
g_var is for the amount.
loop on itab.
MOve itab-peson to g_1.
g_index = sY-tabix + 1.
read itab into wa index g_index.
if sy-subrc eq 0 and wa-person = itab-person.
g_var = amount 1 + amount2 + g_var.
elseif sy-subrc eq 0 and wa-person NE itab-person.
append a new record.
clear: g_var.
else.
append a new record with the data
clear: g_var.
endif.
endloop.
Regards,
Venkatesh
Hi ,
As i see the requirement,
You need the sum of
total for the amount1 for each person
and amount2 for first month
Loop at itab into wa at new person. clear amt1. v_amt2 = wa-amount2. "ONLY FIRST RECORD endat. v_amt1 = wa_amount1 + v_amt1 . "EACH TIME at end of person. tot_amount = v_amt1 + v_amt2 . clear : v_amt1 ,v_amt2 .
Hi Shakthi,
Its very simple. I hope u have the records in internal table.
Just Sort the table by person.
LOOP AT itab INTO wa.
AT END OF person.
SUM.
CLEAR l_sum.
l_sum = wa-amount1 + wa-amount2.
WRITE: /1 wa-person, l_sum.
ENDAT.
ENDLOOP.
Thanks,
Vinod.
Hi,
By Sakthi sri
thanks for your immediate response venkatesh.
r u asking me to take g_1 and g_2 for person A and B. here i have given an example showing 2 persons alone. but i need to calculate for 1000's of person. in that case what i should do?
plz guide me...
By Venkatesh
I am sorry to mis guide you with the two variable called G_1 and g_2. there is no use at all for these variables.
What ever may be number of persons in the list. I mean they are not effecting the logic.
for eg Persons from 1 to 100 or 1 to 1000 what ever it is the logic will work.
Regards,
Venkatesh
hi,
something like this:
SORT itab. LOOP AT itab INTO wa. wa_temp = wa. "because of the control break statements AT FIRST person. total = total + wa_temp-amount2. "amount2 only needed if first line for person ENDAT. total = total + wa-amount1. "amount1 always needed AT LAST person. APPEND total TO itab2. "last line of person => data into another internal table CLEAR total. ENDAT. ENDLOOP.
hope this helps
ec
Add comment