‎2007 Apr 27 11:11 PM
Hi,
i have requirement to get all unique entries from table .if i am getting duplicate record then i need to add qunatity field which i have define like rlbes-anfme.
my internal table is :
11 name1 23.00
22 name2 1,324.00
11 name1 10.00
I want output in this way
11 name1 33.00
22 name2 1,324.00
i tried to use collect statement but the problem is its not working on character type field.
if i use packed field then i am not able to upload my file because i am getting quantity filed 1,2344.00 this way.( instead of 1325.00)
please give me any solution.
thanks,
jack
‎2007 Apr 28 5:23 AM
Hi,
Try the below code
For your internal table the datatype must be Character for all the fields inorder to upload successfully. Create another internal table,say it_collect, which has the same structure of your internal table but the datatype of quantity field must be like rlbes-anfme and for other fields it must be Character.
Loop through your uploaded internal table
LOOP AT ITAB.
Move the fields to it_collect
IT_COLLECT-FIELD1 = ITAB-FIELD1.
IT_COLLECT-FIELD2 = ITAB-FIELD2.
IT_COLLECT-FIELD3 = ITAB-FIELD3.
COLLECT IT_COLLECT.
ENDLOOP.
Now your collect statement will work perfectly. The criteria for using Collect statement is in order to sum up quantity fields then all other fields must be Character datatype.
thanks,
sksingh
‎2007 Apr 27 11:58 PM
Hi,
Try this..
Create another internal table which has the same structure of your internal table.
DATA: LT_COLLECT LIKE ITAB OCCURS 0 WITH HEADER LINE.
DATA: V_QUANTITY TYPE MENGE_D.
Sort the internal table.
SORT ITAB BY field1 field2. " Give the appropriate field names.
<b>* process the internal table which has the records.</b>
LOOP AT ITAB.
Sum up the quantity.
V_MENGE = V_MENGE + ITAB-ANFME. " Quantity field.
Move the first two fields.
LT_COLLECT-FIELD1 = ITAB-FIELD1.
LT_COLLECT-FIELD2 = ITAB-FIELD2.
At the end of the record..append the record.
AT END OF FIELD2. " Give the corresponding field name.
LT_COLLECT-ANFME = V_MENGE.
APPEND LT_COLLECT.
CLEAR: V_MENGE.
ENDAT.
ENDLOOP.
Thanks,
Naren
‎2007 Apr 28 5:23 AM
Hi,
Try the below code
For your internal table the datatype must be Character for all the fields inorder to upload successfully. Create another internal table,say it_collect, which has the same structure of your internal table but the datatype of quantity field must be like rlbes-anfme and for other fields it must be Character.
Loop through your uploaded internal table
LOOP AT ITAB.
Move the fields to it_collect
IT_COLLECT-FIELD1 = ITAB-FIELD1.
IT_COLLECT-FIELD2 = ITAB-FIELD2.
IT_COLLECT-FIELD3 = ITAB-FIELD3.
COLLECT IT_COLLECT.
ENDLOOP.
Now your collect statement will work perfectly. The criteria for using Collect statement is in order to sum up quantity fields then all other fields must be Character datatype.
thanks,
sksingh
‎2007 Apr 28 6:34 AM
<b>You will get the desired output below:</b>
REPORT Z_82235_TEST4 .
types: begin of t_ab,
no(2) type c,
name(5) type c,
amt type i,
end of t_ab.
data: itab type table of t_ab,
wa like line of itab.
wa-no = '11'.
wa-name = 'name1'.
wa-amt = 23.
append wa to itab.
clear : wa.
wa-no = '22'.
wa-name = 'name2'.
wa-amt = 1324.
COLLECT wa INTO itab.
clear : wa.
wa-no = '11'.
wa-name = 'name1'.
wa-amt = 10.
COLLECT wa INTO itab.
clear : wa.
loop at itab into wa.
write: / wa-no, wa-name, wa-amt.
clear wa.
endloop.