01-08-2008 9:21 PM
Hi SAP experts,
I have an internal table with the following fields and data :
Emp_number Section Days
1 A 10
1 B 20
3 A 20
3 B 10
2 A 20
2 B 10
Now I want to calculate the total days for each employee which is a sum of days of section A and days of section B.
I want the data as below into another internal table
:
Emp_number Total_days
1 30
2 30
3 30
Could any one tell the code for the same.
Useful answers wud be rewarded.
Vishnu.
01-08-2008 9:26 PM
01-08-2008 9:26 PM
01-08-2008 9:48 PM
01-08-2008 10:00 PM
01-08-2008 9:26 PM
Here you go:
<div class="jive-quote">
BEGIN OF IT_SUM
selction TYPE C,
Days TYPE I, " << should be I, P or F to get sum for that field
END OF IT_SUM.
LOOP AT ITAB.
MOVE-CORESSPONDING ITAB TO IT_SUM.
COLLECT IT_SUM.
CLEAR IT_SUM.
ENDLOOP.
</div>
Raja T
01-08-2008 9:29 PM
hi,
emp_tab1 is Emp_number Section Days .
emp_tab2 is Emp_number Total_days.
field-symbols <fs_emp> like emp_tab2.
loop at emp_tab1.
read table emp_tab2 assigning <fs_emp> where Emp_number = emp_tab1-Emp_number.
if sy-subrc = 0.
add emp_tab1-Days to <fs_emp>-total_days.
else.
move emp_tab1-Emp_number to emp_tab2-Emp_number.
move emp_tab1-days to emp_tab2-total_days.
append emp_tab2.
clear emp_tab2.
endif.
endloop.
01-08-2008 9:55 PM
DATA : begin of itab2 occurs 0, "new internal table
emp_number like itab-emp_number,
days like itab-days,
end of itab2.
"your code goes here.
loop at itab.
itab2-emp_number = itab-emp_number.
itab2-days = itab-days.
COLLECT itab2.
endloop.
01-09-2008 8:14 PM
01-10-2008 10:57 AM
Hi Vishwanath,
In this case you have to use CONTROL BREAK STATEMENTS.
1.At first
2.At new
3.At end
4.At last
1.At first is going to trigger at the 1st loop of the internal table.From the 2nd loop it is not going to trigger.
It is mainly used for sub headings.
2.At new is going to trigger at the new value of the internal table.
3. At end is going to trigger at the end of the new value of a particular field.
It is mainly use for subtotals.
4.At last is going to trigger at the last loop of the internal table.
It is mainly use for grand totals.
So you gothrough the above 4 statements.
In your case you have to use the third statement i.e., At end.
At end
-
ur logic
-
endat.