10-03-2008 10:11 AM
Hello seniors,
I am a little bit confused about collect statement.
DATA: BEGIN OF ZAMF0 OCCURS 1000,
BUKRS LIKE T001-BUKRS,
GJAHR(4) TYPE N,
MAPA(4) TYPE N,
A01(7) TYPE P DECIMALS 2,
CDDMO(9) TYPE P DECIMALS 2,
end of zamf0.
DATA: BEGIN OF MZAMF0 OCCURS 1000.
INCLUDE STRUCTURE ZAMF0.
DATA: END OF MZAMF0.
collect MZAMF0.
I didn't define any keys for collect statement.
The values are as follows
BUKRS GJAHR MAPA CDDMO
pt01 2008 3100 1.00 ;
pt01 2008 3100 1.00
The output is
BUKRS GJAHR MAPA CDDMO
pt01 2008 3100 2.00 ;
I don't know why it is coming like this. GJAHR,MAPA and CDDMO are of type N or P. But the collect statement adds only CDDMO field.
Could you please explain why it is happening like this?
( If i want the output as
BUKRS GJAHR MAPA CDDMO
pt01 2008 3100 1.00 ;
after the collect statement also, what should i do?)
10-03-2008 10:16 AM
Hi,
If you require data in the way you have suggested then it is better to use modify statement.
Secondly how Collect statement works :
Basically a collect statement adds values and quantity fields( decimals) based on the character fields that are associated with it. Like in your example all characteristic fields are same and only the value field changes. Hence it adds up.
Regards,
Pramod
10-03-2008 10:19 AM
Collect statement sums up Numeric Fields type (f, i, p) only and not N ( N is character type )
10-03-2008 10:38 AM
Hi,
First of all the collect statement will add the non character types.
COLLECT allows you to create unique or summarized datasets. Hence only the last item is added as that of type P.
If you need to replace the 2 rows of internal table
as only one row containing pt01 2008 3100 1.00 , then use delete adjacent duplicates.
That will actually delete the rows which are having the same values in the fields.
Hope this is useful.
Regards,
Pooja