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

Sort table problem

Former Member
0 Likes
577

Hi everyone,

I have a internal table with two columns STATE and ID, using table control user can change the id for specific state. When he press enter i want to sort the internal table by id, but when the state have id = 0 he goes to final of list.

Exemple:

STATE     ID

AC            0

AM           0

PR           2

RJ            0

RS           0

SC           1

SP           3

Well, after SORT the table needs to stay:

STATE     ID

SC           1

PR           2

SP           3

AC           0

AM          0

RJ           0

RS           0

Anyone can help me?

Thanks!

1 ACCEPTED SOLUTION
Read only

former_member201275
Active Contributor
0 Likes
553

Have 2 ITABS.

then ITAB1[] = ITAB2[] "at this point both itabs contain:

STATE     ID

AC            0

AM           0

PR           2

RJ            0

RS           0

SC           1

SP           3

now,

sort itab1 by ID STATE.

sort itab2 by ID STATE.

delete ITAB1 where ID = 0.

delete ITAB2 where ID <> 0.

append ITAB2 to ITAB1.

now your itab1 will be:

STATE     ID

SC           1

PR           2

SP           3

AC           0

AM          0

RJ           0

RS           0

3 REPLIES 3
Read only

former_member201275
Active Contributor
0 Likes
554

Have 2 ITABS.

then ITAB1[] = ITAB2[] "at this point both itabs contain:

STATE     ID

AC            0

AM           0

PR           2

RJ            0

RS           0

SC           1

SP           3

now,

sort itab1 by ID STATE.

sort itab2 by ID STATE.

delete ITAB1 where ID = 0.

delete ITAB2 where ID <> 0.

append ITAB2 to ITAB1.

now your itab1 will be:

STATE     ID

SC           1

PR           2

SP           3

AC           0

AM          0

RJ           0

RS           0

Read only

0 Likes
553

Genius!!!

Only thing that i need to change is put a loop into itab2 to append itab1, but your answer is right!

Thanks so much!!

Read only

0 Likes
553

happy i could help.

No loop necessary:

 

APPEND LINES OF ITAB2 TO ITAB1.