04-03-2009 8:45 AM
Hello Friends,
Can some one please help me with this.
I am trying to use collect statement on table it_bsis2
it_bsis2.
300101 20090227 604000036 10
300101 20090227 604000036 10
300302 20090227 604000036 10
300302 20090227 604000036 10
300304 20090227 604000036 10
300101 20090227 604000037 10
300101 20090227 604000038 10
300302 20090227 604000039 10
Expected output is
it_bsis2
300101 20090227 604000036 20
300302 20090227 604000036 20
300304 20090227 604000036 10
300101 20090227 604000037 10
300101 20090227 604000038 10
300302 20090227 604000039 10
can some one correct me to change my code,
LOOP AT IT_BSIS INTO IT_BSIS.
COLLECT IT_BSIS INTO IT_BSIS2 .
ENDLOOP.
04-03-2009 9:14 AM
Hi,
You need to Sort the table on the first three fields and First three fields of internal table should be of Char type.
04-03-2009 8:49 AM
hi,
the code u have written is correct.
wat was the problem you are facing with this code.
Regards,
naveen
04-03-2009 8:53 AM
hi,
loop at it_bsis2.
collect it_bsis2 into it_bsis.
endloop.
hope it helps you.
regards,
Lokesh
04-03-2009 8:54 AM
COLLECT should be used only for standard and hashed type tables.. Create another itab LIKE HASHED TABLE...WITH UNIQUE KEY.. then only it can add upthe similar content...
DATA:it_bsis LIKE HASHED TABLE it_bsis2 WITH UNIQUE KEY some_key_fldxxxxx.
LOOP AT IT_BSIS INTO IT_BSIS.
COLLECT IT_BSIS INTO IT_BSIS2 .
ENDLOOP.
Hope this helps..
Edited by: Srinivas Kalluri on Apr 3, 2009 9:58 AM
04-03-2009 9:05 AM
04-03-2009 9:06 AM
Hi Jitesh,
The prerequisite is that the collect will happen based on the non numeric fields of the table.
Make sure the first three fields are of non numeric type(Something like CHAR) and the value to be totaled is of numeric tyep, like integer, decimal etc.
then your logic will work.
loop at itab1 into itab1.
collect itab1 into itab2.
endloop.
Regards,
Ravi Kanth Talagana
04-03-2009 9:08 AM
Hi,
could you paste what is the output it is currently giving??
Regards,
Pavan
04-03-2009 9:14 AM
Hi,
You need to Sort the table on the first three fields and First three fields of internal table should be of Char type.
04-03-2009 10:01 AM
bukrs type char still the output of
it_bsis2 : output after using collect statement.
Bukrs HKONT BUDAT AUFNR WRBTR1
1000 0000300000 20071010 AUTO00001 200000.00
1000 0000300000 20071010 BFSI0001 10000.00
1000 0000300000 20071024 000000100000 2560.00
1000 0000300000 20071117 000610000004 100000.00
1000 0000300000 20071201 000000100000 200.00
1000 0000300005 20071024 000000100000 1500.00
1000 0000300007 20071114 000000100000 104.00
1000 0000300008 20071031 07CATTISOE02 2000.00
1000 0000300101 20071101 000602000002 7500.00
1000 0000300101 20071106 000602000017 7000.00
1000 0000300101 20071106 000610000011 10000.00
1000 0000300101 20071120 000602000018 225000.00
1000 0000300101 20071207 000602000012 15000.00
can some one guide me ...
04-03-2009 10:09 AM
HI,
WRBTR1 TYPE BSIS-WRBTR
what is the ref data type you used in the program for the field WRBTR1 If it is char then Collect will not do SUM. WRBTR1 should be of type Numberic type.
04-03-2009 10:55 AM
DATA: BEGIN OF IT_BSIS OCCURS 0,
BUKRS TYPE BSIS-bukrs, " co code
HKONT TYPE BSIS-HKONT, "General Ledger Account
BUDAT TYPE BSIS-BUDAT, "Posting Date in the Document
AUFNR TYPE BSIS-AUFNR, " SO Number
WRBTR1 TYPE BSIS-WRBTR, " Amount in document currency
END OF IT_BSIS.
I want to collect the data on wrbtr1 .
LOOP AT IT_BSIS INTO IT_BSIS.
COLLECT IT_BSIS INTO IT_BSIS2 .
ENDLOOP.
1000 0000300000 20071010 TO00001 200000.00
1000 0000300000 20071010 SI0001 10000.00
1000 0000300000 20071024 0000100000 2560.00
1000 0000300000 20071117 0610000004 100000.00
1000 0000300000 20071201 0000100000 200.00
1000 0000300005 20071024 0000100000 1500.00
1000 0000300007 20071114 0000100000 104.00
1000 0000300008 20071031 CATTISOE02 2000.00
1000 0000300101 20071101 0602000002 7500.00
1000 0000300101 20071106 0602000017 7000.00
1000 0000300101 20071106 0610000011 10000.00
1000 0000300101 20071120 0602000018 225000.00
1000 0000300101 20071207 0602000012 15000.00
1000 0000300101 20071215 0663000016 14000.00
the data is not corrected properly ...
04-03-2009 11:01 AM
Hello Jitesh,
COLLECT stmt is working the way it should work.
COLLECT adds the values of the numeric components of the work area to the existing rows of the internal table with the same key.
E.g.,
> 1000 0000300000 20071010 TO00001 200000.00
> 1000 0000300000 20071010 SI0001 10000.00
In this case TO00001 & SI0001 are not identical so it adds a new line to the int. table.
I cannot comment on how to proceed as i donot know the complete functionality. But if the values TO00001 & SI0001 are not required you can delete the field from your int. table & try.
BR,
Suhas