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 internal table

Former Member
0 Likes
689

Hi All,

I have select and endselect statement

like

select .........from... into itab.

endselect.

now I wante dto sort itab

but when I am using sort itab by field1.

after endselect I am not gettng o/p.

see my coding

REPORT ZSDCOLLECTFORERPT message-id f7 .

*

TABLES: VBRK,

KONV,

BSID.

DATA: BEGIN OF ITAB OCCURS 0,

VKORG LIKE VBRK-VKORG,

VBELN LIKE VBRK-VBELN,

KIDNO like VBRK-KIDNO,

KALSM LIKE VBRK-KALSM,

KNUMV LIKE VBRK-KNUMV,

  • KSCHL LIKE KONV-KSCHL,

  • WRBTR LIKE BSID-WRBTR,

END OF ITAB.

DATA: BEGIN OF JTAB OCCURS 0,

KSCHL LIKE KONV-KSCHL,

END OF JTAB.

DATA: BEGIN OF KTAB OCCURS 0,

WRBTR LIKE BSID-WRBTR,

ZBD1T LIKE BSID-ZBD1T,

ZBD2T LIKE BSID-ZBD1T,

ZFBDT LIKE BSID-ZFBDT,

END OF KTAB.

DATA: NEW_DATE LIKE SY-DATUM.

parameters : " VBELN LIKE VBRK-VBELN.

COMP_COD LIKE BSID-bukrs default 'GNPL',

w_date LIKE BSID-budat.

SELECT SINGLE VKORG VBELN KALSM KNUMV INTO CORRESPONDING FIELDS OF ITAB

FROM VBRK

WHERE KALSM = 'ZDEPO2' OR KALSM = 'ZNET01'.

SELECT KSCHL FROM KONV INTO CORRESPONDING FIELDS OF JTAB

WHERE KNUMV = ITAB-KNUMV AND KSCHL IN ('ZSKP', 'ZRPP', 'SKTO').

IF JTAB-KSCHL = 'ZSKP'.

SELECT WRBTR ZFBDT ZBD1T FROM BSID INTO CORRESPONDING FIELDS OF KTAB WHERE VBELN = ITAB-VBELN.

NEW_DATE = KTAB-ZFBDT + KTAB-ZBD1T.

ENDSELECT.

ELSEIF JTAB-KSCHL = 'ZRPP'.

SELECT WRBTR ZFBDT ZBD2T FROM BSID INTO CORRESPONDING FIELDS OF KTAB WHERE VBELN = ITAB-VBELN.

NEW_DATE = KTAB-ZFBDT + KTAB-ZBD2T.

ENDSELECT.

ELSEIF JTAB-KSCHL = 'SKTO'.

SELECT WRBTR ZFBDT ZBD2T FROM BSID INTO CORRESPONDING FIELDS OF KTAB WHERE VBELN = ITAB-VBELN.

NEW_DATE = KTAB-ZFBDT + KTAB-ZBD2T.

ENDSELECT.

ENDIF.

ENDSELECT.

ENDSELECT.

SORT ITAB BY VKORG.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
658

First you are using select single to ITAB and ENDSELECT. So only one rows will be selected. So there is no meening of sorting the ITAB because it will contain only one row.

Remove that 'SINGLE' from select statement.

secondly, SELECT....ENDSELECT is not efficient as it execute a loop in database, instead use the following:

select * from dbtable into table ITAB where..........

5 REPLIES 5
Read only

Former Member
0 Likes
659

First you are using select single to ITAB and ENDSELECT. So only one rows will be selected. So there is no meening of sorting the ITAB because it will contain only one row.

Remove that 'SINGLE' from select statement.

secondly, SELECT....ENDSELECT is not efficient as it execute a loop in database, instead use the following:

select * from dbtable into table ITAB where..........

Read only

0 Likes
658

if I remove the single still it is not working whatever is the performance but it should work.

Read only

0 Likes
658

Hi,

There is no APPEND statement to populate data into ITAB internal table.

1. Remove SINGLE from select statement.

2. use APPEND statement to populate ITAB.

3. The purpose of NEW_DATE is not clear.

Hope this helps you.

Read only

Former Member
0 Likes
658

Hi,

The mistake you have done is that, you have not appended the values. So the value is only in the header line and not in the internal table. So include this statement.

Append itab to itab.

After this select statement.

SELECT SINGLE VKORG VBELN KALSM KNUMV INTO CORRESPONDING FIELDS OF ITAB

Reward if helpful.

Regards.

Read only

dhruv_shah3
Active Contributor
0 Likes
658

Hi,

First of all Dont use Select .......EndSelect.

Also select single is not preferrable.

Try using For all Entries when making comparison with another Internal Table.

E.g

SELECT VKORG VBELN KALSM KNUMV INTO CORRESPONDING FIELDS OF ITAB

FROM VBRK

WHERE KALSM = 'ZDEPO2' OR KALSM = 'ZNET01'.

SELECT KSCHL FROM KONV INTO CORRESPONDING FIELDS OF JTAB FOR ALL ENTRIES IN ITAB

WHERE KNUMV = ITAB-KNUMV AND KSCHL IN ('ZSKP', 'ZRPP', 'SKTO').

SORT ITAB BY VKORG VBELN.

HTH

Regards,

Dhruv Shah