Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sort

former_member125931
Active Participant
0 Kudos

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&regds,

Sree.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

6 REPLIES 6

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

Use collect statement .. If text fields are same then numeric

values will get added ...

Former Member
0 Kudos

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

Former Member
0 Kudos

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.