‎2009 May 07 1:44 PM
Hi Gurus....
My requirement as follows,
In internal table ITAB_1 entries are
aaa 200 1.1 abc
aaa 100 1.1 abc
bbb 200 1.2 bcd
ccc 50 1.1 acd
ccc 25 1.1 acd
ccc 150 1.1 acd
now i need to process this internal table and show the result as
aaa 300 1.1 abc
bbb 200 1.2 bcd
ccc 225 1.1 acd
.......Thanks in advance.
‎2009 May 07 1:48 PM
HI,
" Assumption Field3 is of char type
Field1 Field2 Field3 Field4
aaa 200 1.1 abc
aaa 100 1.1 abc
bbb 200 1.2 bcd
ccc 50 1.1 acd
ccc 25 1.1 acd
ccc 150 1.1 acd
Loop at itab_1.
Collect itab_1 to itab_2.
Endloop.If field 3 of F/P type then declate the itab_2 as same as itab_1 chage the datatype of field3 to char
code}Loop at itab_1.
MOVE:
itab2-field1 to itab1-field1,
itab2-field2 to itab1-field2,
itab2-field3 to itab1-field3,
itab2-field4 to itab1-field4.
Collect itab_1 to itab_2.
clear itab_2.
Endloop.
‎2009 May 07 1:47 PM
Hi,
loop over the table and use the statement collect.
Save it into a new internal table (or do the action while filling the first internal table)
Afterwards delete adjacent duplicates from table (first sort the table)
Example:
Loop
Collect ... into ...
Endloop
sort xxx by Y
delete adjacent duplicates from xxx comparing Y
Regards,
Peter
‎2009 May 07 1:48 PM
define a second ITAB with identical structure and don't APPEND but COLLECT the lines to it.
The amount field has to be defined numeric, the other fields as CHAR.
‎2009 May 07 1:48 PM
HI,
" Assumption Field3 is of char type
Field1 Field2 Field3 Field4
aaa 200 1.1 abc
aaa 100 1.1 abc
bbb 200 1.2 bcd
ccc 50 1.1 acd
ccc 25 1.1 acd
ccc 150 1.1 acd
Loop at itab_1.
Collect itab_1 to itab_2.
Endloop.If field 3 of F/P type then declate the itab_2 as same as itab_1 chage the datatype of field3 to char
code}Loop at itab_1.
MOVE:
itab2-field1 to itab1-field1,
itab2-field2 to itab1-field2,
itab2-field3 to itab1-field3,
itab2-field4 to itab1-field4.
Collect itab_1 to itab_2.
clear itab_2.
Endloop.
‎2009 May 07 2:30 PM
... loop at itab1 into wa1.
itab2[] = itab1[].
collect itab2.
endloop.This is not working.Whats the mistake.
‎2009 May 07 2:35 PM
Hi
IF you want to use COLLECT statament:
loop at itab1 into wa1.
* itab2[] = itab1[]. "<----------Error: you're moving all data of itab1 to itab2
* collect itab2. "<----------Error: Any value is transfered to work area of itab2, so u're collecting an
" initial record
collect wa1 into itab2.
endloop.Max
‎2009 May 07 2:36 PM
‎2009 May 07 3:04 PM
‎2009 May 07 1:51 PM
Hi Deepan,
There are two options. if the 3rd column 1.1 is of character type then you can use COLELCT.
tab1 and tab2 with same structure.
char numeric(int) char char
aaa 200 1.1 abc
aaa 100 1.1 abc
bbb 200 1.2 bcd
ccc 50 1.1 acd
ccc 25 1.1 acd
ccc 150 1.1 acd
loop at tab1.
tab2 = tab1.
collect tab2.
endloop.
otherwise
loop at tab1 into wa_tab1.
wa_tab2-column1 = wa_tab1-column1.
wa_tab2-column2 = wa_tab1-column2 + wa_tab2-column2.
wa_tab2-column3 = wa_tab1-column3.
wa_tab2-column4 = wa_tab1-column4.
on change of column2.
append wa_tab2 to tab2.
clear wa_tab2.
endon.
endloop.
Like this you can acheive.
Thanks,
Jyothi
‎2009 May 07 2:01 PM
Hi
DATA: BEGIN OF ITAB OCCURS 0,
FIELD1(3),
FIELD2(3),
FIELD3(3),
VAL TYPE I,
END OF ITAB.
ITAB-FIELD1 = 'aaa'.
ITAB-FIELD2 = '1.1'.
ITAB-FIELD3 = 'abc'.
ITAB-VAL = 200.
APPEND ITAB.
ITAB-FIELD1 = 'aaa'.
ITAB-FIELD2 = '1.1'.
ITAB-FIELD3 = 'abc'.
ITAB-VAL = 100.
APPEND ITAB.
ITAB-FIELD1 = 'bbb'.
ITAB-FIELD2 = '1.2'.
ITAB-FIELD3 = ' bcd'.
ITAB-VAL = 200.
APPEND ITAB.
ITAB-FIELD1 = 'ccc'.
ITAB-FIELD2 = '1.1'.
ITAB-FIELD3 = 'acd'.
ITAB-VAL = 50.
APPEND ITAB.
ITAB-FIELD1 = 'ccc'.
ITAB-FIELD2 = '1.1'.
ITAB-FIELD3 = 'acd'.
ITAB-VAL = 25.
APPEND ITAB.
ITAB-FIELD1 = 'ccc'.
ITAB-FIELD2 = '1.1'.
ITAB-FIELD3 = 'acd'.
ITAB-VAL = 150.
APPEND ITAB.
SORT ITAB.
LOOP AT ITAB.
AT END OF FIELD3.
SUM.
WRITE: / ITAB-FIELD1,
ITAB-FIELD2,
ITAB-FIELD3,
ITAB-VAL.
ENDAT.
ENDLOOP.Max
‎2009 May 07 2:01 PM
Sort itab by Fld1 fld3 fld4.
Loop at Itab.
Itab1-fld2 = itab-fld2 + itab1-fld2.
Itab1-fld1 = itab-fld1.
Itab1-fld3 = itab-fld3.
Itab1-fld4 = itab-fld4.
At new fld1.
append itab1.
clear itab1.
endat.
Endloop.Or Use Collect.
Loop at itab
collect itab to itab1.
endloop.
Note: Fld3 should be char type key field of tableResult:
aaa 300 1.1 abc
bbb 200 1.2 bcd
ccc 225 1.1 acdRegards,
Gurpreet