‎2007 Apr 23 12:37 PM
Hi,
I have an internal table type string, which should be sorted based on a column name.
Column name and the table type are only known during runtime.
My idea is to build a formated internal table, sort it and copy back. However I'm stuck, as I have no idea how to do an APPEND for example.
I'm not even sure if this would be the way it should be done.
Any idea?
Thanks in advance,
Peter
My program part so far:
METHOD sort_searchresult .
DATA:
dref_line TYPE REF TO data,
dref_table TYPE REF TO data.
FIELD-SYMBOLS:
<lwa_raw> TYPE ANY,
<lwa_typed> TYPE ANY,
<lit_typed> TYPE ANY.
*--------------------------------------------------------------------------------------------------
IF column IS NOT INITIAL.
CREATE DATA dref_line TYPE (shlp_info-intdescr-selmethod).
CHECK sy-subrc = 0.
ASSIGN dref_line->* TO <lwa_typed>.
CHECK sy-subrc = 0.
*
CREATE DATA dref_table TYPE STANDARD TABLE OF (shlp_info-intdescr-selmethod).
CHECK sy-subrc = 0.
ASSIGN dref_table->* TO <lit_typed>.
CHECK sy-subrc = 0.
LOOP AT t_searchresult_internal ASSIGNING <lwa_raw>.
<lwa_typed> = <lwa_raw>.
* APPEND <lwa_typed> TO <lit_typed>. ????
ENDLOOP.
* SORT <lit_typed> BY (column).
* refresh t_searchresult_internal.
* t_searchresult_internal[] = <lit_typed>[].
ENDIF.
‎2007 Apr 23 12:41 PM
hi,
Try with INSERT
INSERT <lwa_typed> INTO TABLE <lit_typed>.
‎2007 Apr 23 12:41 PM
hi,
Try with INSERT
INSERT <lwa_typed> INTO TABLE <lit_typed>.
‎2007 Apr 23 12:52 PM
Thanks, unfortunately I got the message ""<LIT_TYPED>" is not an internal table."
Also tried the following, however then I got the message "The Dictionary structure or table "<LIT_TYPED>" is either not active or does not exist."
INSERT INTO <lit_typed> ASSIGNING <lwa_typed>.
Any idea?
Thanks,
Peter
‎2007 Apr 23 1:01 PM
Actually I realized, that I can write the following and it works fine:
<lit_typed> = t_searchresult_internal[].However sorting fails
"SORT <lit_typed> BY (column)." is not accepted.
Any idea on this?
Thanks,
Peter
‎2007 Apr 23 1:12 PM
this seems to be working for me , whats the problem
data : begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
parameters : p_col(5) default 'MATNR'.
itab-matnr = '456'.
append itab.
clear itab.
itab-matnr = '123'.
append itab.
clear itab.
sort itab by (p_col).
‎2007 Apr 23 1:15 PM
SORT <lit_typed> BY (column). should work
make sure that the column name passed to variable column is in uppercase.
Raja
‎2007 Apr 23 1:22 PM
Hi Raja,
Thanks for your help.
I cannot even activate my method, I got the message, that ""<LIT_TYPED>" is not an internal table."
Any idea?
Thanks,
Peter
‎2007 Apr 23 1:23 PM
Problem is with the internal table and not the sort by part.
Peter
‎2007 Apr 23 1:26 PM
If I change the definition to the following, than it can be activated...let me check how it looks in the debugger:
<lit_typed> TYPE STANDARD TABLE.
‎2007 Apr 23 1:28 PM
sorry i didnt notice it.
change it to
<lit_typed> TYPE ANY TABLE.
‎2007 Apr 23 1:36 PM
Thanks a lot for everyone, who helped me!!!!
It works fine now with the following code:
METHOD sort_searchresult .
DATA:
dref_table TYPE REF TO data.
FIELD-SYMBOLS:
<lit_typed> TYPE STANDARD TABLE.
*--------------------------------------------------------------------------------------------------
IF column IS NOT INITIAL.
CREATE DATA dref_table TYPE STANDARD TABLE OF (shlp_info-intdescr-selmethod).
CHECK sy-subrc = 0.
ASSIGN dref_table->* TO <lit_typed>.
CHECK sy-subrc = 0.
* Move to formatted itab
<lit_typed> = t_searchresult_internal[].
* Sort
SORT <lit_typed> BY (column).
* Move back SORTED itab
REFRESH t_searchresult_internal[].
t_searchresult_internal[] = <lit_typed>.
ENDIF.
ENDMETHOD.