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

can we replace this SELECT query by more efficient code

Former Member
0 Likes
490

can we replace this SELECT query by more efficient code ?:-

SELECT * FROM zv7_custord
     INTO TABLE G_T_ZV7_CUSTORD
     WHERE ( SENDER in S_SENDER and
             ORDNUM in S_ORDER  and
             ZDATE   in S_DATE ) OR
           ( SENDER in S_SENDER AND
             STATUS = SPACE )
     ORDER BY IDOCNUM.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
457

Remove order by addition and use sort on internal table.

SELECT * FROM zv7_custord

INTO TABLE G_T_ZV7_CUSTORD

WHERE ( SENDER in S_SENDER and

ORDNUM in S_ORDER and

ZDATE in S_DATE ) OR

( SENDER in S_SENDER AND

STATUS = SPACE ).

sort g_t_zv7_custord by idocnum.

Regards,

Ravi

4 REPLIES 4
Read only

Former Member
0 Likes
458

Remove order by addition and use sort on internal table.

SELECT * FROM zv7_custord

INTO TABLE G_T_ZV7_CUSTORD

WHERE ( SENDER in S_SENDER and

ORDNUM in S_ORDER and

ZDATE in S_DATE ) OR

( SENDER in S_SENDER AND

STATUS = SPACE ).

sort g_t_zv7_custord by idocnum.

Regards,

Ravi

Read only

Former Member
0 Likes
457

hI,

HERE WITH OUT SPECIFYING * YOU can use the fields names directly.

because it will fetch all the data including mandt so it will get performance problem.

SELECT * FROM zv7_custord

INTO <b>CORREPONDING FIELDS OF</b> TABLE G_T_ZV7_CUSTORD

WHERE ( SENDER in S_SENDER and

ORDNUM in S_ORDER and

ZDATE in S_DATE ) OR

( SENDER in S_SENDER AND

STATUS = SPACE )

ORDER BY IDOCNUM.

Message was edited by:

Purshothaman P

Read only

0 Likes
457

Hi ,

Using into corresponding fields , does not help the cause of performace enhancement.

Regards

Arun

Read only

Former Member
0 Likes
457

Hi

U can leave ORDER BY option and sort the table by yourself and try to split the query:

SELECT * FROM zv7_custord
     INTO TABLE G_T_ZV7_CUSTORD
     WHERE  SENDER in S_SENDER and
                   ORDNUM in S_ORDER  and
                   ZDATE   in S_DATE .

SELECT * FROM zv7_custord
     APPENDING TABLE G_T_ZV7_CUSTORD
     WHERE  SENDER in S_SENDER        and
                   NOT ORDNUM in S_ORDER  and
                   NOT ZDATE   in S_DATE       and
                   STATUS = SPACE

.

or

SELECT * FROM zv7_custord
     INTO TABLE G_T_ZV7_CUSTORD
     WHERE  SENDER in S_SENDER and
                   ORDNUM in S_ORDER  and
                   ZDATE   in S_DATE .

SELECT * FROM zv7_custord
     APPENDING TABLE G_T_ZV7_CUSTORD
     WHERE  SENDER in S_SENDER        and
                   STATUS = SPACE.

* Sort the table key fields
SORT G_T_ZV7_CUSTORD BY <KEY1> <KEY2> .....
DELETE ADJACENT DUPLICATES FROM G_T_ZV7_CUSTORD COMPARING <KEY1> .....

Max