01-26-2009 9:46 AM
Hi guyz,
In an Internal table for eg if i have data like this
tv20 | germany | 1.2 | 2.3 | 3.4 | 3
tv20 | germany | 1.2 | 2.3 | - 3.4 | 4
tv20 | germany | 1.2 | 2.3 | 3.4 | 3
then the output should be
tv20 | germany | 1.2 | 2.3 | 3.4 | 6
tv20 | germany | 1.2 | 2.3 | -3.4 | 3
plz advise..
regards
01-26-2009 9:49 AM
Hello,
Sort the table first & then use COLLECT statement for this requirement.
Search SDN for details.
BR,
Suhas
01-26-2009 9:49 AM
Hello,
Sort the table first & then use COLLECT statement for this requirement.
Search SDN for details.
BR,
Suhas
01-26-2009 9:58 AM
the COLLECT only works if the fields you want to compare are defined as character type fields. In your case it means all fields of the internal table has to be character type, except the last one (you want to sum that field). If this is not the case, you have two options to go:
1. Define all fields as character type (except the last one) and COLLECT
2. Develop a manual COLLECT, roughly:
LOOP AT itab INTO wa.
READ TABLE itab2 INTO wa2 WITH KEY ... = wa-... "here you mention all fields excpet the last one
IF sy-subrc EQ 0.
wa2-... = wa2-... + wa-... "entry found => add the last field
ELSE.
APPEND wa TO itab2. "entry not found => add new line
ENDIF.
01-26-2009 3:57 PM
Hi,
you can use COLLECT statement.
Before that declare all the fields you want to compare as CHAR and for the last field which you want to add declare it as NUMC.
Mubeen