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

Former Member
0 Kudos

Hi guys

i have a structure(ABC) with name address and varaiable called as BP( with char 1)

but when i sort the structure

like sort ABC by name address BP

aaa 123 null

aaa 123 X

but i want the sort by

aaa 123 x

aaa 123 null

how can i write the sort statement

senthil

1 ACCEPTED SOLUTION

gopi_narendra
Active Contributor
0 Kudos

use the DESCENDING for sort

<b>sort ABC by name address ascending BP descending.</b>

Regards

- Gopi

Message was edited by:

Gopi Narendra

16 REPLIES 16

gopi_narendra
Active Contributor
0 Kudos

use the DESCENDING for sort

<b>sort ABC by name address ascending BP descending.</b>

Regards

- Gopi

Message was edited by:

Gopi Narendra

0 Kudos

hi

i want the sort everthing name address by asc only the bp

is only i want it by desc ie with values it should cum first

senthil

0 Kudos

Use this sort itab NAME ADDRC ascending BP decending.

Former Member
0 Kudos

hi,

try this

sort ABC by name address BP <b>DESCENDING</b>.

here name and address will be sorted in ASCENDING fashion

and bp will be in DESCENDING fashion.

Former Member
0 Kudos

SORT abc ASCENDING BY name address DESCENDING bp.

regards

shiba dutta

Message was edited by:

SHIBA DUTTA

Former Member
0 Kudos

sort itab by name ascending

BP descending.

Former Member
0 Kudos

USE THIS CODE AND REWARD POINTS IF HELPFULL -

data: begin of itab occurs 0,

name(20),

add(20),

bp(1),

end of itab.

itab-name = 'aaa'.

itab-add = '123'.

APPEND ITAB.

CLEAR ITAB.

itab-name = 'aaa'.

itab-add = '123'.

itab-bp = 'X'.

APPEND ITAB.

SORT ITAB ASCENDING BY name add DESCENDING bp.

LOOP AT ITAB.

WRITE:/ ITAB.

ENDLOOP.

Message was edited by:

Amit Tyagi

0 Kudos

thanx for all u r replies

i want a sort like this

if the table contains values like

AAA 123 null

BBB 123 X

it should check if the BP is X then the sort should change it means

it should disaly the value liek this

BBB 123 X

AAA 123 null

senthil

0 Kudos

considering ABC to be your internal table

sort ABC by BP descending.

Regards

- Gopi

0 Kudos

TRY THIS CODE AND POINTS

data: begin of itab occurs 0,

name(20),

add(20),

bp(1),

end of itab.

DATA ITAB1 LIKE TABLE OF ITAB WITH HEADER LINE.

itab-name = 'aaa'.

itab-add = '123'.

APPEND ITAB.

CLEAR ITAB.

itab-name = 'bbb'.

itab-add = '123'.

itab-bp = 'X'.

APPEND ITAB.

ITAB1[] = ITAB[].

loop at itab1 .

IF ITAB-BP = 'X'.

SORT ITAB DESCENDING BY NAME ADD BP.

EXIT.

ELSE.

SORT ITAB ASCENDING BY name add DESCENDING bp.

EXIT.

ENDIF.

ENDLOOP.

LOOP AT ITAB.

WRITE:/ ITAB.

ENDLOOP.

Message was edited by:

Amit Tyagi

0 Kudos

HI senthil,

try following code and let me know is this your requirement.

DATA : BEGIN OF itab OCCURS 0,

name(1) TYPE c,

add(1) TYPE c,

bp(1) TYPE c,

END OF itab.

DATA wa LIKE LINE OF itab.

CLEAR wa.

wa-name = 'A'.

wa-add = '1'.

wa-bp = 'V'.

APPEND wa TO itab.

CLEAR wa.

wa-name = 'B'.

wa-add = '2'.

wa-bp = 'X'.

APPEND wa TO itab.

SORT itab BY bp DESCENDING.

LOOP AT itab INTO wa.

WRITE 😕 wa-name,

wa-add,

wa-bp.

ENDLOOP.

regards

Ashutosh

Reward points if helpful

Former Member
0 Kudos

Use sor by decending order

Former Member
0 Kudos

READ TABLE ITAB WITH KEY BP = 'X'.

IF SY-SUBRC = 0.

SORT sort ABC by BP DESCENDING.

ELSE.

sort ABC by name address BP.

ENDIF.

REGARDS

SHIBA DUTTA

Former Member
0 Kudos

hi,

try this.

select single * from table into itab where bp = 'X'.

*check whether bp filed hase value 'x'.

if sy-subrc = 0.

sort ABC by name address BP DESCENDING.

else

sort ABC by name address BP.

endif.

0 Kudos

hi guys,

Thanx for u replies

but it is not working for me

any more ideas on this issue

senthil

SantoshKallem
Active Contributor
0 Kudos

post u r code here.