06-18-2008 11:06 AM
HI All,
I have two fields one is text field and another one is numeric field,by using text field I done sum for numeric field,but my poblem is after adding mumeric field I need to sort numeric field in Descending order,if I am sorting by Numeric field,the fields of same name are repeating they are not been added,I need same name of text field should be appear once and Numerical field should be added and it is descending order.pls help me out.
Thanks®ds,
Sree.
06-18-2008 11:10 AM
Use Collect Statement for your requirement.
First Sort the table according to char field .
Then loop at the table and use collect inside the loop.
This will solve your problem.
06-18-2008 11:09 AM
use collect in place of append
sort itab by field1 . " by char fields
loop at itab.
collect itab to itab2.
endloop.
sort itab2 by field2.
loop at itab2.
write: itab2.
endloop.
Edited by: S.r.v.r.Kumar on Jun 18, 2008 3:39 PM
Edited by: S.r.v.r.Kumar on Jun 18, 2008 3:44 PM
06-18-2008 11:09 AM
hi use the collect statement ..like this..
DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.
COLLECT COMPANIES.
loop at companies.
write:/ COMPANIES-NAME, COMPANIES-SALES.
endloop.
06-18-2008 11:09 AM
Hi,
While adding the numeric fields take the resulted data to another table, so that u can have single character and the sum of that.
So you will have a single unique record. Now you can sort in descending order and find the result.
06-18-2008 11:09 AM
Use collect statement .. If text fields are same then numeric
values will get added ...
06-18-2008 11:10 AM
hiiiii
Use following code..as here given use AT NEW event on your text field which is repeating..
LOOP AT i_output INTO wa_output.
wa_output2-matnr = ' '.
wa_output2-werks = wa_output-werks.
wa_output2-prctr = wa_output-prctr.
AT NEW matnr.
wa_output2-matnr = wa_output-matnr.
ENDAT. " AT NEW matnr
lw_srecid = lw_srecid + 1.
wa_output2-srecid = lw_srecid.
APPEND wa_output2 TO i_output2.
CLEAR wa_output.
ENDLOOP. " LOOP AT i_output
reward if useful
thx
twinkal
06-18-2008 11:10 AM
Use Collect Statement for your requirement.
First Sort the table according to char field .
Then loop at the table and use collect inside the loop.
This will solve your problem.