‎2007 Jul 16 12:35 PM
Hi,
This is a sample Program which i m using to add using collect.
<code>
REPORT Z_F2004A2PS738_4 line-count 20(5)
no standard page heading.
tables : z739.
data : begin of it_z739 occurs 0,
name like z739-name,
date like z739-dat,
amount like z739-amount,
end of it_z739.
data sum type i value 0.
selection-screen begin of block b1 with frame title text-001.
select-options : s_date for z739-dat.
selection-screen end of block b1.
select name dat amount from z739 into table it_z739 where dat in s_date.
perform summation.
form summation.
loop at it_z739.
on change of it_z739-name.
collect it_z739.
write: it_z739-name,'=',it_z739-amount.uline.
endon.
endloop.
endform.
</code>
I hav data in db table like.
NAME AMOUNT
HARI 100
HARI 200
HARI 399
PURA 400
PURA 500
Regards,
Suraj
‎2007 Jul 16 12:56 PM
hi,
instead of summing in loop u fetch sum in selecct statement like:
select name sum( amount ) from z739 into table it_z739 where dat in s_date group by name.
and read this entries using read table stmt.
Jogdand M B
‎2007 Jul 16 12:36 PM
form summation.
loop at it_z739.
collect it_z739.
write: it_z739-name,'=',it_z739-amount.uline.
endloop.
endform.
‎2007 Jul 16 12:54 PM
Hi ravi,
When ur using that statement .. its only taking the whole data from database table and displaying its not collecting.
Regards,
suraj
‎2007 Jul 16 12:58 PM
hi suraj,
try this..
form summation.
loop at it_z739.
at end of name.
SUM.
write: / it_z739-name,
it_z739-date,
it_z739-amount.
endat.
endloop.
‎2007 Jul 16 12:39 PM
Hi,
Try this,
loop at it_z739.
on change of it_z739-name.
write: it_z739-name,'=',it_z739-amount.uline.
endon.
collect it_z739.
endloop.
Reward if useful!
‎2007 Jul 16 12:42 PM
Hi,
Pasete & Check this code for Form Summation :
form summation.
sort it_z739 by name.
data : total type netpr.
clear : total.
loop at it_z739 into it_z739.
total = total + it_z739-amount.
at end of name.
write: it_z739-name,'=',total.uline.
clear total.
endat.
endloop.
endform.
Reward Points, if helpful,
Sandeep Kaushik
Message was edited by:
Sandeep Kaushik
‎2007 Jul 16 12:50 PM
Frnds
When i m using that code its not working out.
<code>
REPORT Z_F2004A2PS738_4 line-count 20(5)
no standard page heading.
tables : z739.
data : begin of it_z739 occurs 0,
name like z739-name,
date like z739-dat,
amount like z739-amount,
end of it_z739.
data sum type i value 0.
selection-screen begin of block b1 with frame title text-001.
select-options : s_date for z739-dat.
selection-screen end of block b1.
select name dat amount from z739 into table it_z739 where dat in s_date.
perform summation.
form summation.
loop at it_z739.
at end of name.
collect it_z739.
write: / it_z739-name,
it_z739-date,
it_z739-amount.
skip.
endat.
endloop.
endform.
</code>
When i m executing i m getting ******* as output.
Can anyone help me regarding this.
Regards,
suraj
‎2007 Jul 16 12:54 PM
At the start of a new control level (i.e. immediately after AT), the following occurs in the output area of the current LOOP statement:
All character type fields (on the right) are filled with "*" after the current control level key.
All other fields (on the right) are set to their initial values after the current control level key.
‎2007 Jul 16 12:57 PM
Hi,
copy and paste my code from my earlier reply, it will work.
Reward Points, if helpful,
Sandeep kaushik
‎2007 Jul 16 12:58 PM
Change the code of form summation as below .
FORM summation.
DATA : it_copy TYPE TABLE OF z739 WITH HEADER LINE .
LOOP AT it_z739.
it_copy = it_z739 .
COLLECT it_copy .
ENDLOOP.
LOOP AT it_copy .
WRITE: / it_copy-name,
it_copy-date,
it_copy-amount.
SKIP.
ENDLOOP.
ENDFORM.
‎2007 Jul 16 1:05 PM
HI,
TRY LIKE THIS,
SORT it_z739 BY NAME.
DATA: FLAG TYPE C.
LOOP AT it_z739.
AT FIRST.
WRITE:/10 'EMPNAME'.
/25 'DATE'.
/40 'AMOUNT'.
WRITE:/10 it_z739-name,
25 it_z739-date,
40 it_z739-amount.
AT NEW NAME.
FLAG = 'X'.
IF FLAG = 'X'.
WRITE:/10 it_z739-name,
25 it_z739-date,
40 it_z739-amount.
/* AT END OF NAME.
COLLECT it_z739. */
ENDLOOP.
IF HELPFUL REWARD SOME POINTS.
WITH REGARDS,
SURESH.A
‎2007 Jul 16 12:56 PM
hi,
instead of summing in loop u fetch sum in selecct statement like:
select name sum( amount ) from z739 into table it_z739 where dat in s_date group by name.
and read this entries using read table stmt.
Jogdand M B
‎2007 Jul 16 12:57 PM
Frnds,
Tank u for ur reply but i hav to use only collect to get the output.
‎2007 Jul 16 12:59 PM
Hi Suraj,
if you remove field (date like z739-dat) from internal table , then your code will work fine because date is not number type. so collect works when name and date are same.
if you really want to include date field. try this:
loop at it_z739.
on change of it_z739-name.
write:/ 'checking'.
endon.
collect it_z739.
write: it_z739-name,'=',it_z739-amount.uline.
endloop.
Regards,
Sukhee
‎2007 Jul 16 1:16 PM
Hello Frnds,
Still i m facing problem i m not getting.
what i feel is , we cant use COLLECT to add up the numeric fields.
Plz help me.
Regards,
suraj
‎2007 Jul 16 1:25 PM
Hi,
use
loop at it_z739.
at end of it_z739-name.
sum.
write: it_z739-name,'=',it_z739-amount.uline.
endat.
endloop.
Regards,
Sesh
‎2007 Jul 17 7:01 AM
HI,
COLLECT STATEMENT WORKS AT THE TIME OF FILLING UP OF THE INTERNAL TABLE WHEN U DO NOT USE APPEND STATEMENT. SUM STATEMENT WILL ONLY WORK FOR YOU. ALSO MOVE THE DATE TYPE FIELD ABOVE THE NAME FIELD IN DECLARATION SO THAT ****** DO NOT COME. SEE THE EG BELOW.
data : begin of itAB occurs 0,
date like SY-DATUM,
name(15),
amount TYPE P,
end of itAB.
data sum type i value 0.
ITAB-NAME = 'AAA'.
ITAB-DATE = SY-DATUM.
ITAB-AMOUNT = 1010.
aPPEND ITAB.
ITAB-NAME = 'AAA'.
ITAB-DATE = SY-DATUM.
ITAB-AMOUNT = 1020.
aPPEND ITAB.
ITAB-NAME = 'AAA'.
ITAB-DATE = SY-DATUM.
ITAB-AMOUNT = 1030.
aPPEND ITAB.
ITAB-NAME = 'AAA'.
ITAB-DATE = SY-DATUM.
ITAB-AMOUNT = 1040.
aPPEND ITAB.
ITAB-NAME = 'BBB'.
ITAB-DATE = SY-DATUM.
ITAB-AMOUNT = 2010.
aPPEND ITAB.
ITAB-NAME = 'BBB'.
ITAB-DATE = SY-DATUM.
ITAB-AMOUNT = 2020.
aPPEND ITAB.
ITAB-NAME = 'BBB'.
ITAB-DATE = SY-DATUM.
ITAB-AMOUNT = 2030.
aPPEND ITAB.
sort itAB by NAME. "it now looks like figure 13.9
loop at itAB.
at new NAME.
sum.
write: / 'total:', itAB-NAME, itAB-DATE, itAB-AMOUNT.
endat.
endloop.
free itAB.
‎2007 Jul 17 5:23 AM