‎2006 Dec 19 6:53 AM
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
‎2006 Dec 19 7:06 AM
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
‎2006 Dec 19 6:55 AM
HI,
<b>SORT ITAB BY field1 field2 DESCENDING.</b>
Assending is default
Regards,
‎2006 Dec 19 6:55 AM
‎2006 Dec 19 6:55 AM
i cant get you properly but for internal table you can use
sort itab by <f>.
sort itab by <f> descending.
regards
shiba dutta
‎2006 Dec 19 7:03 AM
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.
‎2006 Dec 19 6:55 AM
Hi,
Just use SORT itab BY fld1, fld2...
before looping on the internal table for display.
Regards,
Amit
‎2006 Dec 19 6:57 AM
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.
‎2006 Dec 19 7:06 AM
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
‎2006 Dec 19 7:30 AM
Hi,
Use it in the following way:
SORT ITAB DESCENDING BY PLNDT.
Hope it helps.
Reward if helpful.
Regards,
Sipra