10-23-2007 7:59 AM
Hi,everyone.
I want to sort internal table in subroutine , but there is an error.My code is below.
TYPES: BEGIN OF TYP_SAKNR,
SAKNR LIKE ZTEFI0710-SAKNR,
END OF TYP_SAKNR.
DATA: TAB_SAKNR TYPE STANDARD TABLE OF TYP_SAKNR,
WA_SAKNR TYPE TYP_SAKNR.
START-OF-SELECTION.
PERFORM GET_SAKNR USING TAB_SAKNR.
LOOP AT TAB_SAKNR INTO WA_SAKNR.
WRITE: / WA_SAKNR-SAKNR.
ENDLOOP.
FORM GET_SAKNR USING TAB_SAKNR TYPE STANDARD TABLE.
SELECT SAKNR
FROM ZTEFI0710
INTO TABLE TAB_SAKNR
WHERE ZZEURENKETU = '2'.
<b> SORT TAB_SAKNR BY SAKNR.</b>
ENDFORM.
If I just write SORT TAB_SAKNR, it's ok.
Can you tell me why?And how to solve this problem?
This is an example,if in the internal table there are many fields,and I want to sort this internal table by a few fields in subroutine,what should I do?
Regards,
feng.
10-23-2007 8:06 AM
You need to pass the table using "Tales" key word. something like
data: wa_saknr type typ_saknr.
PERFORM GET_SAKNR tables TAB_SAKNR.
FORM GET_SAKNR tables TAB_SAKNR structure wa_saknr.
endform.
Reward if useful.
10-23-2007 8:05 AM
TYPES: BEGIN OF TYP_SAKNR,
SAKNR LIKE ZTEFI0710-SAKNR,
END OF TYP_SAKNR.
DATA: TAB_SAKNR TYPE STANDARD TABLE OF TYP_SAKNR,
WA_SAKNR TYPE TYP_SAKNR.
START-OF-SELECTION.
PERFORM GET_SAKNR USING TAB_SAKNR.
LOOP AT TAB_SAKNR INTO WA_SAKNR.
WRITE: / WA_SAKNR-SAKNR.
ENDLOOP.
FORM GET_SAKNR USING TAB_SAKNR TYPE STANDARD TABLE OF TYP_SAKNR. " Specify the type of Standard table as TYP_SAKNR
SELECT SAKNR
FROM ZTEFI0710
INTO TABLE TAB_SAKNR
WHERE ZZEURENKETU = '2'.
SORT TAB_SAKNR BY SAKNR.
ENDFORM.
10-23-2007 8:18 AM
10-23-2007 8:06 AM
You need to pass the table using "Tales" key word. something like
data: wa_saknr type typ_saknr.
PERFORM GET_SAKNR tables TAB_SAKNR.
FORM GET_SAKNR tables TAB_SAKNR structure wa_saknr.
endform.
Reward if useful.
10-23-2007 8:09 AM
Table category of an internal table that is managed using a table index and is <b>always sorted according to its table key</b>. The corresponding generic data type is sorted table.
<b>I want to sort this internal table by a few fields in subroutine,what should I do?</b>
It is not possible to sort the table with any other sort criteria except table key. Otherwise it will give a error. What you can do, inside the subroutine define a standard internal table with same structure and copy the sorted table to that standard table and use it.
IT_sorted_table[] = IT_standard_table[].
and use IT_standard_table[] instead of IT_sorted_table[].
10-23-2007 8:09 AM
Hi Feng,
Use table type in subroutine.
Refer this code :
TYPES: BEGIN OF TYP_SAKNR,
SAKNR LIKE ZTEFI0710-SAKNR,
END OF TYP_SAKNR.
<b>TYPES : ttyp_saknr type standard table of TYP_SAKNR.</b>
data : TAB_SAKNR type ttyp_saknr .
FORM GET_SAKNR USING TAB_SAKNR TYPE <b>ttyp_saknr</b>
SELECT SAKNR
FROM ZTEFI0710
INTO TABLE TAB_SAKNR
WHERE ZZEURENKETU = '2'.
SORT TAB_SAKNR BY SAKNR.
ENDFORM.
Now it would work.
Regards,
Hemant
10-23-2007 8:10 AM
Hi
If u want to sort the internal table by few fields just give
sort it_matnr by f1 f2 ... fn
where f1 , f2 ... fn are the fields on which u want to sort the internal table.