2009 Jan 28 4:23 AM
Hi guru's,
I am having the internal table itab. in that the fields are
date snt sabah
01.01.2009 1000 0000
02.01.2009 2000 0000
02.01.2009 3000 0000
here i need to calculate the data sccording to the date wise
which means
01.01.2009 1000 0000
02.01.2009 5000 0000
can any one help me how to do the loop here.
Thanks & Best Regards,
Praveen.
2009 Jan 28 6:01 AM
Hi,
check this code. Just execute this code and see huv it works.
**Data declaration*******
data : begin of it occurs 0,
dats(10),
value type i,
end of it.
data it1 like it occurs 0 with header line.
**Moving the values***
it-dats = '01.01.2009'.
it-value = 1000.
append it.
clear it.
it-dats = '02.01.2009'.
it-value = 2000.
append it.
clear it.
it-dats = '02.01.2009'.
it-value = 3000.
append it.
clear it.
it-dats = '01.01.2009'.
it-value = 4000.
append it.
clear it.
sort it by dats.
****Main process*******
loop at it.
it1-value = it1-value + it-value.
At end of dats.
it1-dats = it-dats.
append it1.
clear it1.
endat.
endloop.
loop at it1.
write : it1-dats , it1-value.
endloop.
I hope it will solve your problem.
Rgds.
siva
Hi,
check this code. Just execute this code and see huv it works.
**Data declaration*******
data : begin of it occurs 0,
dats(10),
value type i,
end of it.
data it1 like it occurs 0 with header line.
**Moving the values***
it-dats = '01.01.2009'.
it-value = 1000.
append it.
clear it.
it-dats = '02.01.2009'.
it-value = 2000.
append it.
clear it.
it-dats = '02.01.2009'.
it-value = 3000.
append it.
clear it.
it-dats = '01.01.2009'.
it-value = 4000.
append it.
clear it.
sort it by dats.
****Main process*******
loop at it.
it1-value = it1-value + it-value.
At end of dats.
it1-dats = it-dats.
append it1.
clear it1.
endat.
endloop.
loop at it1.
write : it1-dats , it1-value.
endloop.
I hope it will solve your problem.
Rgds.
siva
2009 Jan 28 4:27 AM
Hi
You need to first sort the internal table based on the date. Later use 'collect' statement and see if its working.
Loop at ITAB.
collect ITAB.
Endloop.
If this way its not working, use ON CHANGE OF and calculate as u needed it.
Let me know if you need any more details.
Regards,
Vinod.
2009 Jan 28 4:29 AM
hi,
try this..
sort <internal table> by <field name> asccending/descending
loop at <internal table>
endloop.
hope this help you
Regards
Ritesh J
2009 Jan 28 4:34 AM
Use Control statements AT END OF
Sort iatb by Date.
LOOP AT Itab INTO WA.
AT END OF DATE.
SUM.
..........
ENDAT.
ENDLOOP.
Hope this helps...
2009 Jan 28 4:37 AM
Hi,
Go through this abap help.
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb36d5358411d1829f0000e829fbfe/frameset.htm
Hope this helps.
Regards,
Deepthi.
2009 Jan 28 4:53 AM
Hi, Praveen
Test the following code and in the final internal table where you find date = '99991231' this row is the sum of the date and at the end you will also find date = '99991231' it the Grand total, i have tested is is working fine, hope will solve out your problem,
TYPES: BEGIN OF t_name,
date LIKE sy-datum,
amount1 TYPE p,
amount2 TYPE p,
END OF t_name.
DATA: it1_sum TYPE STANDARD TABLE OF t_name WITH HEADER LINE,
wa_it1_sum TYPE t_name,
it2_sum TYPE STANDARD TABLE OF t_name WITH HEADER LINE,
wa_it2_sum TYPE t_name.
wa_it1_sum-date = '20080103'.
wa_it1_sum-amount1 = 500.
wa_it1_sum-amount2 = 200.
APPEND wa_it1_sum TO it1_sum.
wa_it1_sum-date = '20080101'.
wa_it1_sum-amount1 = 100.
wa_it1_sum-amount2 = 200.
APPEND wa_it1_sum TO it1_sum.
wa_it1_sum-date = '20080102'.
wa_it1_sum-amount1 = 500.
wa_it1_sum-amount2 = 10000.
APPEND wa_it1_sum TO it1_sum.
wa_it1_sum-date = '20080102'.
wa_it1_sum-amount1 = 105000.
wa_it1_sum-amount2 = 20500.
APPEND wa_it1_sum TO it1_sum.
wa_it1_sum-date = '20080103'.
wa_it1_sum-amount1 = 21000.
wa_it1_sum-amount2 = 22000.
APPEND wa_it1_sum TO it1_sum.
SORT it1_sum BY date.
LOOP AT it1_sum INTO wa_it1_sum.
APPEND wa_it1_sum TO it2_sum.
AT END OF date.
SUM.
wa_it1_sum-date = '99991231'.
APPEND wa_it1_sum TO it2_sum.
ENDAT.
AT LAST.
SUM.
wa_it1_sum-date = '99991231'.
APPEND wa_it1_sum TO it2_sum.
ENDAT.
ENDLOOP.Please let me know if any problem,
Kind Regards,
Faisal
2009 Jan 28 4:56 AM
Hi Praveen,
try this code,
LOOP AT it_tab INTO wa_tab.
"Copy to anothr wrk area as we r using at on date remaining fields will be initial
wa_tab1 = wa_tab.
ADD wa_tab-snt TO w_sum. "store it to a variable
AT END OF date.
wa_tab1-snt = w_sum.
APPEND wa_tab1 TO it_tab1.
CLEAR w_sum. "clear at end of each date
ENDAT.
ENDLOOP.Regards,
Manoj Kumar P
2009 Jan 28 5:38 AM
Hi,
Pls try following Code . If any queries please let me know.
*Declearation of strcture having one date and two currency fields
TYPES: BEGIN OF ts_amt,
sdate TYPE augdt,
amt1 TYPE dmbtr,
amt2 TYPE wrbtr,
END OF ts_amt.
*Delceration of internal tables and work areas.
DATA: it_amt TYPE TABLE OF ts_amt,
it_sumamt TYPE TABLE OF ts_amt,
is_sumamt TYPE ts_amt,
is_amt TYPE ts_amt.
*Start of selection of date
START-OF-SELECTION.
*Selection of data from table..i have taken only 100 u can take as ur required
SELECT augdt dmbtr wrbtr
FROM bseg
INTO TABLE it_amt
UP TO 100 ROWS.
SORT it_amt BY sdate.
*loop with Collect statement
LOOP AT it_amt INTO is_amt.
is_sumamt-sdate = is_amt-sdate.
is_sumamt-amt1 = is_amt-amt1.
is_sumamt-amt2 = is_amt-amt2.
COLLECT is_sumamt INTO it_sumamt.
CLEAR: is_amt, is_sumamt.
ENDLOOP.
*End of selection
END-OF-SELECTION.
Thanks & Regards,
Syed
2009 Jan 28 5:52 AM
hello praveen,
loop at it into wa.
at end of date.
SUM.
end at.
endloop.
Have a Nice Day,
Regards,
Sujeet
2009 Jan 28 6:01 AM
Hi,
check this code. Just execute this code and see huv it works.
**Data declaration*******
data : begin of it occurs 0,
dats(10),
value type i,
end of it.
data it1 like it occurs 0 with header line.
**Moving the values***
it-dats = '01.01.2009'.
it-value = 1000.
append it.
clear it.
it-dats = '02.01.2009'.
it-value = 2000.
append it.
clear it.
it-dats = '02.01.2009'.
it-value = 3000.
append it.
clear it.
it-dats = '01.01.2009'.
it-value = 4000.
append it.
clear it.
sort it by dats.
****Main process*******
loop at it.
it1-value = it1-value + it-value.
At end of dats.
it1-dats = it-dats.
append it1.
clear it1.
endat.
endloop.
loop at it1.
write : it1-dats , it1-value.
endloop.
I hope it will solve your problem.
Rgds.
siva
2009 Jan 28 6:38 AM
hello guru,
method 1.
you can make use of AT statement
and
method 2.
move the first row of internal table to a local work area. when you are looping check if sy-tabix equals1, then do the processing as required and move the processed data to new work area, but if it is not equal to 1 then check whether current date is equal to the previous date from the local work area, then modify new work area otherwise and so on.
regards,
Dheeraj
2009 Jan 28 9:35 AM
Sort it_tab by Date.
LOOP AT it_tab.
AT END OF Date.
SUM.
ENDAT.
ENDLOOP.
Regards,
Joan
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |