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

Sorting an Internal Table

Hi All,

I have 4 materials in an internal table say,

123

456

ABC

BCD

after sorting based on Material Number,

I need the output like

ABC

BCD

123

456

Help me to achieve this.

Points Assured.

Regards

Suresh

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 11:59 AM

    hi check this.

    i have tested.

    TYPES : BEGIN OF S,

    S(5) TYPE C,

    END OF S.

    DATA : ITAB TYPE STANDARD TABLE OF S WITH HEADER LINE,

    ITAB1 TYPE STANDARD TABLE OF S WITH HEADER LINE.

    ITAB-S = 'ABC'.

    APPEND ITAB.

    ITAB-S = '123'.

    APPEND ITAB.

    ITAB-S = 'BCD'.

    APPEND ITAB.

    ITAB-S = '456'.

    APPEND ITAB.

    SORT ITAB BY S ASCENDING.

    LOOP AT ITAB.

    IF ITAB-S CA SY-ABCDE.

    MOVE ITAB TO ITAB1.

    APPEND ITAB1.

    DELETE ITAB.

    CLEAR ITAB.

    CLEAR ITAB1.

    ENDIF.

    ENDLOOP.

    APPEND LINES OF ITAB TO ITAB1.

    LOOP AT ITAB1.

    WRITE ITAB1.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 12:07 PM

    Check this code, I hope it helps:

    TYPES: BEGIN OF ty_matnr,
             matnr LIKE mara-matnr,
           END   OF ty_matnr.
    
    
    DATA: gt_matnr TYPE STANDARD TABLE OF ty_matnr WITH HEADER LINE.
    
    
    START-OF-SELECTION.
    
      DATA: lv_numeric TYPE i,
            lt_aux TYPE STANDARD TABLE OF ty_matnr.
    
      CLEAR: gt_matnr,
             lt_aux.
    
      gt_matnr-matnr = '123'. APPEND gt_matnr.
      gt_matnr-matnr = '456'. APPEND gt_matnr.
      gt_matnr-matnr = 'ABC'. APPEND gt_matnr.
      gt_matnr-matnr = 'BCD'. APPEND gt_matnr.
    
      SORT gt_matnr BY matnr ASCENDING.
    
      LOOP AT gt_matnr.
        IF gt_matnr CA '1234567890'.
          APPEND gt_matnr TO lt_aux..
          DELETE gt_matnr.
        ENDIF.
      ENDLOOP.
    
      APPEND LINES OF lt_aux TO gt_matnr.

    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.