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

select query problem

ashish_gupta11
Explorer
0 Likes
596

Hi Expert ,

i have one which take more time to execute . can you please suggest me how to make it effective .

select KUNNR from knvp into CORRESPONDING FIELDS OF TABLE customer where KUNN2 = P_KUNNR AND PARVW = 'ZD' .

SORT CUSTOMER BY KUNNR.

DELETE ADJACENT DUPLICATES FROM CUSTOMER .

                                • p_year - 1**********

IF CUSTOMER[] IS NOT INITIAL.

SELECT AKUNAG AVBELN AFKDAT BMATNR BARKTX BFKIMG BVRKME BMEINS C~EXTWG INTO CORRESPONDING FIELDS OF TABLE IT FROM ( ( VBRK AS A INNER JOIN VBRP AS B ON

AVBELN = BVBELN ) INNER JOIN MARA AS C ON BMATNR = CMATNR ) FOR ALL ENTRIES IN

CUSTOMER WHERE AKUNAG = CUSTOMER-KUNNR AND ( BPSTYV NE 'TANN' AND B~PSTYV NE 'RENN' )

AND A~VBTYP = 'M'

AND C~EXTWG = 'SALE_IB'

AND A~BUKRS IN S_BUKRS

AND A~FKSTO = SPACE

AND ( A~FKDAT BETWEEN CUTOFF AND CUTOFF1 ) .

ENDIF.

cutoff & cutoff1 are month variable between dates

Thanks ,

Ashish Gupta

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
560

asish..

few suggestions...

1. Do not keep non key fields in the where clause, rather use DELETE after selection is done to remove the unwanted entries in the fetched table

2. break down the big select statement . that will help.

now try.

3 REPLIES 3
Read only

Former Member
0 Likes
561

asish..

few suggestions...

1. Do not keep non key fields in the where clause, rather use DELETE after selection is done to remove the unwanted entries in the fetched table

2. break down the big select statement . that will help.

now try.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
560

1. In the select you're neither utilising any key fields nor hitting any DB indexes (as a matter of fact i checked and do not find any relevant indexes defined by SAP as well) If i understand correctly you're searching for billing dates in 1 month range (correct me if i'm wrong).

2.

B~PSTYV NE 'TANN' AND B~PSTYV NE 'RENN'

You can take this out of your SELECT & add a DELETE statement on the corresponding internal table after your SELECT.

3. You can try removing the INTO CORRESPONDING FIELDS OF addition & check if it fasten your runtime. ( I know many sceptics who would say this doesn't improve the runtimes much ! )

All said make full use of SAP Runtime Analysis Tool (SE30), compare your runtimes, tweak the SELECT

Cheers,

Suhas

Anyways good join construct (i prefer them with aliases)

Read only

0 Likes
560

Masters ................Thanks for replies .

yes I am searching within one month ........

your supports are valuable.

Thanks ,

Ashish