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 the fields

Former Member
0 Likes
885

hi all,

do i have a way to sort the fields of an internal table like one which is carried out in alv.

In alv we have the options for sorting ascending and descending the fields which are selected and operation carried out according to the radio buttons selected .

can we do it with internal table without using solution .if so please.

thanks for viewers,

magesh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
844

in classical report ithink it is not possible but you can do it in interactive report.

in AT line-selection or at user-command just take the function code for that and sort your internal table there and show it.

regards

shiba dutta

8 REPLIES 8
Read only

dani_mn
Active Contributor
0 Likes
844

HI,

<b>SORT ITAB BY field1 field2 DESCENDING.</b>

Assending is default

Regards,

Read only

Former Member
0 Likes
844

Hi,

Use...

SORT itab BY field1 [ASCENDING/DESCENDING].

Read only

Former Member
0 Likes
844

i cant get you properly but for internal table you can use

sort itab by <f>.

sort itab by <f> descending.

regards

shiba dutta

Read only

0 Likes
844

hi shiba,

u know that u will have the ascend and descend icon as an option in the alv when execute . when u click that it will make u to select fields which r all u need to ascend and which are to descend with radio buttons .

similarly can we carryout with internal table having four fields and selecting while runtime which r the fields to ascend and which to descend and execute it .

I think u r getting me .

thanks for reply,

magesh.

Read only

amit_khare
Active Contributor
0 Likes
844

Hi,

Just use SORT itab BY fld1, fld2...

before looping on the internal table for display.

Regards,

Amit

Read only

Former Member
0 Likes
844

Yes u can sort the internal table by fields by using the following syntax.

SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE]

BY <f1> [ASCENDING|DESCENDING] [AS TEXT]

...

<fn> [ASCENDING|DESCENDING] [AS TEXT].

For more information in sorting see this example.

DATA: BEGIN OF LINE,

LAND(3) TYPE C,

NAME(10) TYPE C,

AGE TYPE I,

WEIGHT TYPE P DECIMALS 2,

END OF LINE.

DATA ITAB LIKE STANDARD TABLE OF LINE WITH NON-UNIQUE KEY LAND.

LINE-LAND = 'G'. LINE-NAME = 'Hans'.

LINE-AGE = 20. LINE-WEIGHT = '80.00'.

APPEND LINE TO ITAB.

LINE-LAND = 'USA'. LINE-NAME = 'Nancy'.

LINE-AGE = 35. LINE-WEIGHT = '45.00'.

APPEND LINE TO ITAB.

LINE-LAND = 'USA'. LINE-NAME = 'Howard'.

LINE-AGE = 40. LINE-WEIGHT = '95.00'.

APPEND LINE TO ITAB.

LINE-LAND = 'GB'. LINE-NAME = 'Jenny'.

LINE-AGE = 18. LINE-WEIGHT = '50.00'.

APPEND LINE TO ITAB.

LINE-LAND = 'F'. LINE-NAME = 'Michele'.

LINE-AGE = 30. LINE-WEIGHT = '60.00'.

APPEND LINE TO ITAB.

LINE-LAND = 'G'. LINE-NAME = 'Karl'.

LINE-AGE = 60. LINE-WEIGHT = '75.00'.

APPEND LINE TO ITAB.

PERFORM LOOP_AT_ITAB.

SORT ITAB.

PERFORM LOOP_AT_ITAB.

SORT ITAB.

PERFORM LOOP_AT_ITAB.

SORT ITAB STABLE.

PERFORM LOOP_AT_ITAB.

SORT ITAB DESCENDING BY LAND WEIGHT ASCENDING.

PERFORM LOOP_AT_ITAB.

FORM LOOP_AT_ITAB.

LOOP AT ITAB INTO LINE.

WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.

ENDLOOP.

SKIP.

ENDFORM.

Read only

Former Member
0 Likes
845

in classical report ithink it is not possible but you can do it in interactive report.

in AT line-selection or at user-command just take the function code for that and sort your internal table there and show it.

regards

shiba dutta

Read only

Former Member
0 Likes
844

Hi,

Use it in the following way:

SORT ITAB DESCENDING BY PLNDT.

Hope it helps.

Reward if helpful.

Regards,

Sipra