Application Development and Automation 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: 
Read only

SORTING ITAB

Former Member
0 Likes
784

Hi Experts,

In my Internal Table ITAB, I have 2 fields. DATE, MBLNR(material Doc. No.). I want to sort my ITAB on date as ascending order and MBLNR in Descending. Like with in a single data there must b many MBLNR. SO on a single data lets say 01.01.2008, there are 3 MBLNR No., say 4000123, 4000111, 4000222. I want it should display in below manner:

01.01.2008 4000222

01.01.2008 4000123

01.01.2008 4000111

Plz help.

Thanks.

Khan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
752

HI,

sort itab by DATE ascending MBLNR descending.

loop at itab.

endloop.

regards

Nicole

8 REPLIES 8
Read only

Former Member
0 Likes
753

HI,

sort itab by DATE ascending MBLNR descending.

loop at itab.

endloop.

regards

Nicole

Read only

0 Likes
752

hi Lorenz,

I tried the same but didnt get the desired output.

Any other Suggetion,

Thanks.

Khan

Read only

0 Likes
752

Hello Khan,

This is what u wanted.


DATA: BEGIN OF ITAB OCCURS 0,
        BUDAT(10),
        MBLNR TYPE MSEG-MBLNR,
      END OF ITAB.

ITAB-BUDAT = '01.01.2008'.
ITAB-MBLNR = '4000222'      .
APPEND ITAB.

ITAB-BUDAT = '01.01.2008'.
ITAB-MBLNR = '4000123'      .
APPEND ITAB.

ITAB-BUDAT = '01.01.2008'.
ITAB-MBLNR = '4000111'      .
APPEND ITAB.

ITAB-BUDAT = '02.01.2008'.
ITAB-MBLNR = '4000252'      .
APPEND ITAB.

ITAB-BUDAT = '02.01.2008'.
ITAB-MBLNR = '4000212'      .
APPEND ITAB.

SORT ITAB BY BUDAT ASCENDING MBLNR DESCENDING.

LOOP AT ITAB.
  WRITE:/ ITAB-BUDAT, ITAB-MBLNR.
ENDLOOP.

Cheers,

Vasanth

Read only

Former Member
0 Likes
752

write like this ...

SORT ITAB by DATE MBLNR descending.

Read only

Former Member
0 Likes
752

try like this.


DATA : BEGIN OF itab OCCURS 0,
       date TYPE sy-datum,
       mblnr(10),
       END OF itab.

itab-date = sy-datum.
itab-mblnr = '4000222'.
APPEND itab.

itab-date = sy-datum.
itab-mblnr = '4000223'.
APPEND itab.

itab-date = sy-datum.
itab-mblnr = '4000224'.
APPEND itab.

itab-date = sy-datum + 1.
itab-mblnr = '4000225'.
APPEND itab.

itab-date = sy-datum +  1.
itab-mblnr = '4000228'.
APPEND itab.

itab-date = sy-datum + 1.
itab-mblnr = '4000234'.
APPEND itab.

SORT itab BY date ASCENDING mblnr DESCENDING. "<<<<<<<<

LOOP AT itab.
  WRITE :/ itab-date, itab-mblnr.
ENDLOOP..

Read only

Former Member
0 Likes
752

Hi,

Try this method.

Sort itab date ascending.

move itab to itab2.

sort itab2 mblnr descending.

This should work I guess.. and the kind of output you want will be present in the other internal table itab2. Make sure the fields and their types in both the internal tables are same.

Regards.

Read only

Former Member
0 Likes
752

Hi Khan

Try this

SORT ITAB by MBLNR descending.

Regards

Anbu

Read only

Former Member
0 Likes
752

Hello Khan,

You can do that by using sort statement as below.

SORT g_t_mara DESCENDING BY matnr ASCENDING ernam.

Refer to the code below.

REPORT zsample.

TABLES: mara.

SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECT-OPTIONS: s_ernam FOR mara-ernam.

DATA: BEGIN OF g_t_mara OCCURS 0,
        matnr LIKE mara-matnr,
        ernam LIKE mara-ernam,
      END OF g_t_mara.

SELECT matnr ernam FROM mara INTO CORRESPONDING FIELDS OF TABLE g_t_mara
       WHERE matnr IN s_matnr.

SORT g_t_mara ASCENDING BY ernam DESCENDING matnr.

LOOP AT g_t_mara.

  WRITE: / g_t_mara-ernam, g_t_mara-matnr .

ENDLOOP.

Plese try to give points for good answers. It seems you didn't give points to atleast one time. You will get one point if you reward points to answers.

Reward If Helpful.

Regards

--

Sasidhar Reddy Matli.