2009 Jul 03 9:23 AM
Guys,
Im having problem with this select statement. It takes much time just to get single record.
The problem is with accessing the LTAP table and the ORDER BY DESCENDING statement.
The objective of this select statement is to get the non blocked storage bin which is used by latest transfer order number.
If the latest transfer order no storage bin is blocked, then it will loop and get the 2nd latest transfer order no's storage bin and
checks whether it blocked or not. It will keep looping.
The secondary index has been created but the it still taking much time (3 minutes for 10K records in LTAP)
Secondary Indexes:
a) LTAP_M ->MANDTLGNUM PQUIT MATNR
b)LTAP_L ->LGNUM PQUIT VLTYP VLPLA
Below is the coding.
******************Start of DEVK9A14JW**************************
SELECT ltaptanum ltapnlpla ltap~wdatu INTO (ltap-tanum, ltap-nlpla, ltap-wdatu)
UP TO 1 ROWS
FROM ltap INNER JOIN lagp "DEVK9A15OA
ON lagplgnum = ltaplgnum
AND lagplgtyp = ltapnltyp
AND lagplgpla = ltapnlpla
WHERE lagp~skzue = ' '
AND ltap~pquit = 'X'
AND ltap~matnr = ls_9001_scrn-matnr
AND ltap~lgort = ls_9001_scrn-to_lgort
AND ltap~lgnum = ls_9001_scrn-lgnum
AND ltap~nltyp = ls_9001_scrn-nltyp
ORDER BY tanum DESCENDING.
ENDSELECT.
IF sy-subrc EQ 0.
ls_9001_scrn-nlpla = ltap-nlpla.
EXIT.
ENDIF.
******************End of DEVK9A14JW**************************
Guys,
Im having problem with this select statement. It takes much time just to get single record.
The problem is with accessing the LTAP table and the ORDER BY DESCENDING statement.
The objective of this select statement is to get the non blocked storage bin which is used by latest transfer order number.
If the latest transfer order no storage bin is blocked, then it will loop and get the 2nd latest transfer order no's storage bin and
checks whether it blocked or not. It will keep looping.
The secondary index has been created but the it still taking much time (3 minutes for 10K records in LTAP)
Secondary Indexes:
a) LTAP_M ->MANDTLGNUM PQUIT MATNR
b)LTAP_L ->LGNUM PQUIT VLTYP VLPLA
Below is the coding.
******************Start of DEVK9A14JW**************************
SELECT ltaptanum ltapnlpla ltap~wdatu INTO (ltap-tanum, ltap-nlpla, ltap-wdatu)
UP TO 1 ROWS
FROM ltap INNER JOIN lagp "DEVK9A15OA
ON lagplgnum = ltaplgnum
AND lagplgtyp = ltapnltyp
AND lagplgpla = ltapnlpla
WHERE lagp~skzue = ' '
AND ltap~pquit = 'X'
AND ltap~matnr = ls_9001_scrn-matnr
AND ltap~lgort = ls_9001_scrn-to_lgort
AND ltap~lgnum = ls_9001_scrn-lgnum
AND ltap~nltyp = ls_9001_scrn-nltyp
ORDER BY tanum DESCENDING.
ENDSELECT.
IF sy-subrc EQ 0.
ls_9001_scrn-nlpla = ltap-nlpla.
EXIT.
ENDIF.
******************End of DEVK9A14JW**************************
2009 Jul 03 9:49 AM
Instead of using select....endselect if u can fetch ur data in an internal table and instead of doing ORDER BY in select query
You can use SORT itab by DESCENDING.
2009 Jul 03 9:55 AM
Yep I tried that too, select from ltap into internal table, SORT it descdending by tanum. Then I loop and check with LAGP table.
But the problem is during fetching the records from LTAP into internal table. It still takes much time.(3 minutes for 10K records).
2009 Jul 03 10:00 AM
Try using for all entries instead of join as in ur query in ur where clause u are using non-key fields and not all the key fields are there in where clause...so join will reduce performance
2009 Jul 03 10:10 AM
Yep I tried that too like below. But the performance is better if I use INNER JOIN than FOR ALL ENTRIES.
The problem is when select from the LTAP table.
I have used OPEN CURSOR statement also. And limit the ltap record by 50 but still takes much time accessing LTAP table. Weird!
I even have used MAX GROUP BY in my above INNER JOIN statemen to replace the GROUP BY DESCENDING, but it returned me incorrect result maybe because of the INNER JOIN.
SELECT tanum nlpla wdatu lgnum nltyp INTO TABLE t_ltap
WHERE lgnum = ls_9001_scrn-lgnum
AND pquit = 'X'
AND matnr = ls_9001_scrn-matnr
AND lgort = ls_9001_scrn-lgort
AND nltyp = ls_9001_scrn-nltyp
IF t_ltap[] IS NOT INITIAL.
SORT t_ltap DESCENDING BY lgnum nltyp nlpla tanum.
DELETE ADJACENT DUPLICATES FROM t_ltap COMPARING lgnum nltyp nlpla.
SORT t_ltap DESCENDING BY tanum.
SELECT lgpla INTO TABLE lt_lgap
FROM lagp FOR ALL ENTRIES IN t_ltap
WHERE blablabla
ENDIF.
2009 Jul 03 10:22 AM
Use into corresponding fields of table instead of into table
2009 Jul 03 10:25 AM
Nope, INTO CORRESPONDING slower than INTO TABLE because it transfer the value by the name of the fields while INTO TABLE is by the sequence of the fields.
2009 Jul 03 10:28 AM
Ans also see the order in which you are selecting fields from LTAP it should be:-
select lgnum tanum wdatu nltyp from ltab and so on
2009 Jul 03 10:35 AM
Yep! Tried that too, but it dont improve at all. I checked the ST05, the response is about the same.
2009 Jul 03 9:57 AM
In your code you are using Select Endselect,to avoid performence issue we should not use this statement untill it is really very necessary.
You can use the statement
Selet (fields) from database table into table itab.
so you can use the below code for example
SELECT single ltaptanum ltapnlpla ltap~wdatu
INTO table itab
FROM ltap INNER JOIN lagp
ON lagplgnum = ltaplgnum
AND lagplgtyp = ltapnltyp
AND lagplgpla = ltapnlpla
WHERE lagp~skzue = ' '
AND ltap~pquit = 'X'
AND ltap~matnr = ls_9001_scrn-matnr
AND ltap~lgort = ls_9001_scrn-to_lgort
AND ltap~lgnum = ls_9001_scrn-lgnum
AND ltap~nltyp = ls_9001_scrn-nltyp
ORDER BY tanum DESCENDING.
2009 Jul 03 9:59 AM
Hmm.. actually I need to use the SELECT n ENDSELECT because of UP TO 1 ROWS.
I need to use UP TO 1 ROWS because i select the LTAP not using key fields.
2009 Jul 03 10:28 AM
ORDER BY clause directly put a load on Database.
SO never use order by ever in your queries.
Instead always use sort itab by field names.
Secondly Try to minimise the where clause conditions during fetching data in a query.
instead delete them depending upon the conditions.
Regds,
Anil
2009 Jul 03 10:32 AM
Yep! But I cant avoid to use sorting in database layer. Tried sort in application server as well. But the problem not during sort
but during access to LTAP table.
Yes that is the minimum where clause conditions I could use otherwise the records selection could be 3,4 times more.
2009 Jul 03 10:34 AM
did u try to change the order in your select query...............bcoz of it performance becomes slow keep it according to the order defined in table.
2009 Jul 03 11:13 AM
HI,
In your original select:-
SELECT ltaptanum ltapnlpla ltap~wdatu INTO (ltap-tanum, ltap-nlpla, ltap-wdatu)
UP TO 1 ROWS
FROM ltap INNER JOIN lagp "DEVK9A15OA
ON lagplgnum = ltaplgnum
AND lagplgtyp = ltapnltyp
AND lagplgpla = ltapnlpla
WHERE lagp~skzue = ' '
AND ltap~pquit = 'X'
AND ltap~matnr = ls_9001_scrn-matnr
AND ltap~lgort = ls_9001_scrn-to_lgort
AND ltap~lgnum = ls_9001_scrn-lgnum
AND ltap~nltyp = ls_9001_scrn-nltyp
ORDER BY tanum DESCENDING.
ENDSELECT.
in where clause use :
WHERE
ltap~lgnum = ls_9001_scrn-lgnum
AND ltap~pquit = 'X'
AND ltap~matnr = ls_9001_scrn-matnr
AND lagp~skzue = ' '
AND ltap~lgort = ls_9001_scrn-to_lgort
AND ltap~nltyp = ls_9001_scrn-nltyp
ORDER BY tanum DESCENDING.
since there is already an index 'M' defined in the syatem with lgnum,pquit & matnr as the key. If still not satisfied you may have to think about creating a secondary index via SE11 with fields appearing in your 'where' clause as the key. ( obviously in the same order i.e. lgnum,pquit,matnr,skzue,lgort,nltyp )
Regards
Raju Chitale
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |