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

SORT DYNAMIC INTERNAL TABLE

Former Member
19,415

Hello everybody.

How can I sort a dynamic internal table ???

The sentence sort <gt_table> by matnr werks doesn' t work... How can I do it ??

Thanks a lot.

Regards

1 ACCEPTED SOLUTION
Read only

Pawan_Kesari
Active Contributor
7,357
DATA otab TYPE ABAP_SORTORDER_TAB .

SORT <fs_tab> BY (otab).

Table ABAP_SORTORDER_TAB has fields

NAME

DESCENDING

ASTEXT

fill it accordingly

5 REPLIES 5
Read only

Former Member
0 Likes
7,357

Hi,

sort <gt_table> by (field1) (field2).

Refer to this link..

Read only

former_member212005
Active Contributor
0 Likes
7,357
Read only

Pawan_Kesari
Active Contributor
7,358
DATA otab TYPE ABAP_SORTORDER_TAB .

SORT <fs_tab> BY (otab).

Table ABAP_SORTORDER_TAB has fields

NAME

DESCENDING

ASTEXT

fill it accordingly

Read only

tarangini_katta
Active Contributor
0 Likes
7,357

Hi use this.

SORT <itab> BY (MATNR) (WERKS).

look into this link also.

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/how-to-sort-a-dynamic-internal-table-22...

it will work for you.

.

Read only

Former Member
7,357

Here is an example:

PARAMETERS dbtab TYPE c LENGTH 30.

SELECT-OPTIONS columns FOR dbtab NO INTERVALS.

DATA: otab TYPE abap_sortorder_tab,

oline TYPE abap_sortorder,

dref TYPE REF TO data.

FIELD-SYMBOLS: <column> LIKE LINE OF columns,

<itab> TYPE STANDARD TABLE.

TRY.

CREATE DATA dref TYPE STANDARD TABLE OF (dbtab).

***I have assigned the value dref to internal table as follows***

ASSIGN dref->* TO <itab>.

CATCH cx_sy_create_data_error.

MESSAGE 'Wrong data type!' TYPE 'I' DISPLAY LIKE 'E'.

LEAVE PROGRAM.

ENDTRY.

TRY.

SELECT *

FROM (dbtab)

INTO TABLE <itab>.

CATCH cx_sy_dynamic_osql_semantics.

MESSAGE 'Wrong database table!' TYPE 'I' DISPLAY LIKE 'E'.

LEAVE PROGRAM.

ENDTRY.

LOOP AT columns ASSIGNING <column>.

oline-name = <column>-low.

APPEND oline TO otab.

ENDLOOP.

TRY.

SORT <itab> BY (otab).

CATCH cx_sy_dyn_table_ill_comp_val.

MESSAGE 'Wrong column name!' TYPE 'I' DISPLAY LIKE 'E'.

LEAVE PROGRAM.

ENDTRY.