Skip to Content
author's profile photo Former Member
Former Member

Sort

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10:09 AM

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

    values will get added ...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 10: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.