04-12-2006 9:42 AM
Hi all,
I am trying to sort an internal table dynamically.
In this table I have a number of field to use for an ascending sort and other used to sort descending.
I have writen the code to create two fields (character field) in which I concatenate the sort field names.
The result is :
sort_field_up = ' field1 field2 field 3'
sort_field_dn = ' field4 field5 field 6'
and then i coded :
sort itab by (sort_field_up) ascending (sort_field_dn) descending.
But I get a dump ...
has anyone ever done this ?
regards,
Nicolas
04-12-2006 9:45 AM
Dynamic Sort of internal TAable
tables : mara.
data : itab like mara occurs 0 with header line.
data : begin of fieldtab occurs 0 ,
name(40),
end of fieldtab.
select * from mara into table itab up to 100 rows.
fieldtab-name = 'ERSDA'.
append fieldtab.
fieldtab-name = 'ERNAM'.
append fieldtab.
break-point.
sort itab by (fieldtab).
break-point.
regards
vinod
04-12-2006 9:45 AM
hi Nicholas,
try using two sort statements i.e, 1 sort for ascending and other as a decending sort ...
i.e, <b>sort itab by (sort_field_up) ascending .
sort itab by (sort_field_dn) descending.</b>
or else
<b> sort itab by field1 field2 field 3 ascending.
sort itab by field4 field5 field 6 descending.</b>
Regards,
Santosh
04-12-2006 9:47 AM
04-12-2006 9:46 AM
Hi,
I guess u can use :
<b>sort itab by field1 field2 field 3 ascending.</b>
<b>sort itab by field4 field5 field 6 descending.</b>
in two different steps.
This may give you the same result.
Thanks,
Rashmi.
04-12-2006 9:50 AM
Hello,
Creat an internal table an fill your fields <b>IN CAPITAL LETTERS</b> into that and then do sort.
Regards,
Naimesh
04-12-2006 9:55 AM
Hi,
only single fields can be mentioned in dynamic sort.
REPORT Z_DYNAMIC_SORT .
data: sort1 type string,
sort2 type string.
data: begin of itab occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
end of itab.
"not possible to group the fileds.
"sort_field_up = ' field1 field2 field 3'
sort1 = 'VBELN'.
sort2 = 'POSNR'.
sort itab by (sort1) ascending (SORT2) descending.
"or
sort itab by (sort1) (SORT2) ascending .
write sy-subrc.
regards
vijay