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

10|10000 characters needed characters exceeded

### Related questions

• 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.

10|10000 characters needed characters exceeded
• 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.```