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 By

Former Member
0 Kudos

Hello Experts,

I have an internal table with two fields. WERKS, for the site, and ERZET, for time counts were created. ERZET will either have a valid time or be blank (article wasn't counted). I need the earliest time brought to the top of the internal table for each site, but not the blank.

If I sort descending by WERKS ERZET I get the latest ERZET by site. If I sort ascending by WERKS ERZET I get the blank ERZET by site.

Problem: I want the earliest time for each site, but because of the blanks if I sort ascending I get the blanks first. Any syntax out there that would allow me to sort the table that would bring the first non-blank ERZET to the top of the internal table.

Thank-You

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Well, you will have to work around it. Here is one solution, copy the internal table to another, delete out all of the lines where ERZET is initial, then sort the table ascending, then you will have the records in order.

itab2[] = itab1[].

delete itab2 where ERZET is initial.
sort itab2 ascending by WERKS ERZET.

Regards,

Rich Heilman

2 REPLIES 2

Former Member
0 Kudos

Hi,

I believe there is no syntax in sort to bring the non-blank values first..

Try this..

SORT ITAB BY WERKS ERZET.

LOOP AT ITAB WHERE WERKS = '1234'

AND NOT ERZET IS INITIAL.

EXIT.

ENDLOOP.

This will get the first record that is that not having a blank value..

Thanks,

Naren

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Well, you will have to work around it. Here is one solution, copy the internal table to another, delete out all of the lines where ERZET is initial, then sort the table ascending, then you will have the records in order.

itab2[] = itab1[].

delete itab2 where ERZET is initial.
sort itab2 ascending by WERKS ERZET.

Regards,

Rich Heilman