‎2007 Jul 30 11:37 AM
Hi,
During sorting the internal table i was facing the problem...
See internal table having two fields namely num and name..
sort itab descending by num-->It works...
But
sort itab descending by ____.Here i need to display the value in run time..How it is possible.
‎2007 Jul 30 11:42 AM
‎2007 Jul 30 11:40 AM
Hi,
If the fields are not many try using CASE ENDCASE.
CASE FLD.
WHEN FLD1.
SORT ITAB BY FLD1.
WHEN FLD2.
SORT ITAB BY FLD2.
ENDCASE.
Regards,
Sesh
‎2007 Jul 30 11:42 AM
You can't SORT an internal table during runtime, because you need to mention the SORT field in the SORT statement in the coding part.
Regards,
Pavan
‎2007 Jul 30 11:42 AM
‎2007 Jul 30 11:43 AM
Hi ,
Pass it within the brackets.
Data var1(35).
If condition1 = true.
var1 = 'FIELD1'.
else.
var1 = 'FIELD2'.
Endif.
Sort itab by ( var1 ).
‎2007 Jul 30 11:44 AM
Instead you can develop a code of this format....
parameters: p_string(10) type c default 'CARRID'.
DATA: BEGIN OF fs_spfli,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
countryfr TYPE spfli-countryfr,
END OF fs_spfli.
DATA: t_spfli LIKE STANDARD TABLE OF fs_spfli.
START-OF-SELECTION.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE t_spfli.
IF P_STRING EQ 'CARRID'.
sort t_spfli by CARRID.
ELSEIF P_STRING EQ 'CONNID'.
SORT T_SPFLI BY CONNID.
ENDIF.
loop at t_spfli into fs_spfli.
write:
fs_spfli-carrid.
write fs_spfli-connid.
endloop.
Regards,
Pavan
‎2007 Jul 30 11:46 AM
use token method:
data: fname type string.
during runtime :
fname = 'NUM' or
fname = 'NAME'.
SORT itab DESCENDING BY (fname).
Reward if useful
Regards
Pradeep
‎2007 Jul 30 11:51 AM
You can use following method :
SORT <itab> BY (otab).
where otab is an internal table of type abap_sortorder_tab.
declare it as:
DATA: otab TYPE abap_sortorder_tab,
oline TYPE abap_sortorder.
in ur code:
oline-name = 'NUM'.
oline-descending = 'X'. " Descending
append oline to otab.
clear oline.
oline-name = 'NAME'.
oline-descending = ' '. " AScending
append oline to otab.
Reward if helpful
Regards
Prax