2010 Jul 21 2:35 AM
Hi All,
I encountered the runtime error while try to sort the internal table by using field symbol below. Can anyone please advice how does this issues can be resolved? Thanks.
SORT i_test
BY <fs_a> ASCENDING <fs_b>.
Runtime error: -
When attempting to sort the internal table "I_test[ ]" in the current ABAP/4
program "Ztest", the field symbol " " was used as a dynamic
criterion.
To be used in this way, all of " " would have to fit into the header
line "I_test" of the internal table "I_test[ ]".
Since this is not the case, the program "Ztest" had to be terminated.
2010 Jul 21 3:36 AM
If the field-symbols <fs_a> & <fs_b> contain the you can try:
SORT i_test
BY ( <fs_a> ) ASCENDING ( <fs_b> ).
Check this online help documentation for details [http://help.sap.com/abapdocu_70/en/ABENITAB_COMPONENTS.htm], [http://help.sap.com/abapdocu_70/en/ABAPSORT_ITAB.htm#!ABAP_ADDITION_4@4@]
BR,
Suhas
If the field-symbols <fs_a> & <fs_b> contain the you can try:
SORT i_test
BY ( <fs_a> ) ASCENDING ( <fs_b> ).
Check this online help documentation for details [http://help.sap.com/abapdocu_70/en/ABENITAB_COMPONENTS.htm], [http://help.sap.com/abapdocu_70/en/ABAPSORT_ITAB.htm#!ABAP_ADDITION_4@4@]
BR,
Suhas
2010 Jul 21 3:28 AM
You can also specify the sort fields dynamically in the form (name). If name is blank at runtime, the sort field is ignored. If itab is a table with a header line, you can also use a field symbol pointing to the header line of itab as a dynamic sort criterion. A field symbol that is not assigned is ignored. If a field symbol is assigned, but does not point to the header line of the internal table, a runtime error occurs.
2010 Jul 21 3:36 AM
If the field-symbols <fs_a> & <fs_b> contain the you can try:
SORT i_test
BY ( <fs_a> ) ASCENDING ( <fs_b> ).
Check this online help documentation for details [http://help.sap.com/abapdocu_70/en/ABENITAB_COMPONENTS.htm], [http://help.sap.com/abapdocu_70/en/ABAPSORT_ITAB.htm#!ABAP_ADDITION_4@4@]
BR,
Suhas
2010 Jul 21 10:54 AM
Hi All,
Sort with field symbol for an internal table is not allowed within an loop.
Please see the following code and it is working:
TYPES : BEGIN OF y_trial,
n TYPE i,
END OF y_trial.
DATA : t_table TYPE STANDARD TABLE OF y_trial WITH HEADER LINE,
e_table LIKE LINE OF t_table.
FIELD-SYMBOLS : <fs_trial> TYPE y_trial.
INITIALIZATION.
CLEAR e_table.
MOVE 10 to e_table-n.
APPEND e_table to t_table.
CLEAR e_table.
MOVE 15 to e_table-n.
APPEND e_table to t_table.
CLEAR e_table.
MOVE 7 to e_table-n.
APPEND e_table to t_table.
" Assign the field symbol to internal table and then sort.
ASSIGN t_table to <fs_trial>.
SORT t_table ASCENDING by <fs_trial>.
LOOP AT t_table ASSIGNING <fs_trial>.
WRITE 😕 <fs_trial>-n.
ENDLOOP.
Output is : 7,10,15.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |