Hi Ramesh,
That is normal that second and next repetition of query gives much faster results than first run. That is why you need to compare different solutions after few query runs, to have comparable results (so called "warmed up system"). In this way you may find most efficient algorithm for your needs.
With SAT / SE30 you can find exactly the place which takes most time. If you see it is a database query, try to measure it with ST05, as you probably did. Then open menu option "Trace List -> Summarized by SQL statement" and check:
- Redundancy column (ideally should have value 0 which means that there were no duplicated queries).
- Number of executions to see how many times query was executed (it is better to have one query with bigger result than separated queries with partial results).
- BfTp - Type of buffer to see if any of tables you use are buffered.
- Explain statement, to see if indexes are used.
By the way, 1 second for database query is not long time in case of large tables and query with JOIN and FOR ALL ENTRIES. Anyhow if database queries are slowest part of your program, review and match indexes. Perfectly matched index for your query would be on BATCH, SPRAS and VLTYP, but having BATCH only should help as well. Creating good indexes is the key factor to have quick query execution also for the first time.
Regards,
Adam