SAP ST05 SQL trace: Find repeated database work before rewriting the query
A manufacturer finds its purchasing worklist slow and needs to know whether repeated reads or expensive individual access dominates.
START HERE · NO PRIOR TOPIC KNOWLEDGE NEEDED
What it is. Why it matters.
SQL is the language used to request database data. ST05 records database activity for a selected action so a developer can examine the queries and their cost.
Completely new to SAP?
Manufacturers use SAP to connect work such as buying components, recording inventory, planning production, shipping equipment and accounting for costs. SAP S/4HANA is an enterprise resource planning system: it connects these activities through shared business data.
ABAP is SAP’s programming language for business applications. A program reads data, applies rules and produces a result. Start with the objects involved before investigating code.
A transaction code, or t-code, is a shortcut to a task in classic SAP GUI. Fiori apps provide another way to work. Names and screens depend on the product and release; you do not need a live system to learn the concepts in this guide.

Scope and source-review notes
Scope and evidence
Source review by FAST SAP SOLUTIONS® editorial. This badge describes our editorial review; it does not represent SAP certification or independent endorsement.
Classic ST05 SQL analysis and related documented ADT SQL-trace concepts; available controls and scope depend on backend and deployment.
Primary documentation reviewed on 14 November 2026 using official indexed excerpts. Documentation review only; authored examples were not compiled or executed in an SAP system.
A MANUFACTURING EXAMPLE
Investigate a slow component purchasing list
Trace the defined workload
Read the example values
- Action
- Open one filtered report
- Trace scope
- Relevant user and interval
- Finding
- Many repeated reads
- Next review
- Query and call pattern
Words you’ll meet in this guide
- Program
- A set of instructions executed by a computer.
- Class
- A reusable unit that groups data with operations called methods.
- Database
- Organized information kept beyond one program execution.
- Internal table
- A list of rows held temporarily in an ABAP program’s memory.
- Key
- One or more fields used to identify or find a record.
- ABAP
- SAP’s programming language for business applications.
- CDS
- Core Data Services: reusable definitions of business data and relationships.
- BTP
- SAP Business Technology Platform: cloud services for applications, data and integration.
- SQL
- A language used to read and work with database data.
- ADT
- ABAP Development Tools: SAP tools for ABAP development in Eclipse and, on supported systems, Visual Studio Code.
Preview the practical steps
SEE THE CONNECTION
See it in a simple example.
A small example to make the idea concrete.
Investigate a slow component purchasing list
A manufacturer finds its purchasing worklist slow and needs to know whether repeated reads or expensive individual access dominates.
Use the SQL trace to distinguish repeated work from one expensive request
ST05 SQL trace helps explain the database activity generated by a defined ABAP action.
Scope and prerequisites
Use ST05 where it is documented and available in the classic ABAP landscape.
Understand the SQL boundary and its limits
The SQL trace records database requests rather than a complete ABAP source-level runtime breakdown.
Investigate a slow component purchasing list
A manufacturer finds its purchasing worklist slow and needs to know whether repeated reads or expensive individual access dominates.
Trace a bounded reproduction and compare SQL call patterns before prescribing a database or ABAP change.
| Reader | Business question | Evidence to carry forward |
|---|---|---|
| SAP developers and application teams supporting manufacturers | Investigate a slow component purchasing list | Trace a bounded reproduction and compare SQL call patterns before prescribing a database or ABAP change. |
01 Use the SQL trace to distinguish repeated work from one expensive request
ST05 SQL trace helps explain the database activity generated by a defined ABAP action. Look for execution frequency, duration, returned/accessed record context, parameters and the originating source location. Many cheap calls can be more significant than one moderately expensive call. A slow user action can also spend most of its time outside SQL, which requires another tool. [1] [2]
Start with one reproducible workload and a bounded capture. This tutorial compares a repeated customer lookup with an oversized item selection using fictional trace values. The purpose is to choose a testable correction from evidence, not to rewrite a query because its syntax looks old.
02 Scope and prerequisites
Use ST05 where it is documented and available in the classic ABAP landscape. SAP BTP ABAP environment and newer ADT workflows provide related SQL trace analysis through their supported tools. Trace controls, authorizations and analysis interfaces differ by release; a Trade Management example is not a universal menu specification for every product. [1] [3]
You need a representative action, authorized trace access and enough application knowledge to interpret the selected data. Record system/client, application server where relevant, execution identity, selection and observation interval. Trace data can contain business values in parameters, so retain and share only the permitted diagnostic detail. This article has not captured a customer trace.
03 Understand the SQL boundary and its limits
The SQL trace records database requests rather than a complete ABAP source-level runtime breakdown. One ABAP operation can produce several database-level trace records, and buffering can change whether a logical access reaches the database. Do not count every displayed trace row as a separate business query without understanding the event types and analysis view. [1] [2]
A duration is an observation for that request under those conditions. It does not by itself establish a missing index, a bad join or database overload. Parameters and data volume can change the work dramatically. Preserve the source location and input context so a proposed explanation can be checked against the actual code and candidate population.
04 Worked case: two patterns with different corrections
Assume fictional report Z_ORDER_REPORT reads 800 order items for a defined date range. Pattern A retrieves a customer label once per item: 800 executions at an illustrative average 1.5 ms, totaling 1,200 ms. Only sixteen distinct customer keys occur. Pattern B is one item query taking 600 ms and returning 20,000 rows, although the final report uses 800.
Pattern A suggests repeated access that may be reducible by grouping required keys or using a correct in-memory lookup. Pattern B suggests an overly broad candidate population or late filtering. Neither conclusion is proven by the aggregate alone. Inspect the actual predicates, parameters, source location and business filtering rules before selecting a correction.
| Pattern | Executions | Rows/context | Total duration |
|---|---|---|---|
| A: customer lookup | 800 | Mostly repeated sixteen keys | 1,200 ms |
| B: item selection | 1 | 20,000 returned; 800 used | 600 ms |
| Application processing | Outside SQL trace scope | Mapping, calculations and display | Measure separately |
05 Prepare the capture around the business question
Decide whether first-use latency or steady repeated execution is the issue. The cited Trade Management guidance warms caches for its repeatable-run scenario. That is useful when initial costs are intentionally excluded; it would hide evidence if the complaint specifically concerns first launch. Record which experiment you are running. [1]
Choose the smallest representative selection that still exercises the suspicious pattern. A one-item case cannot demonstrate 800 repeated calls, while an unrestricted report may create unnecessary load. Coordinate the available trace resource and stopping responsibility in the actual landscape. Start collection only when the test is ready, execute the defined action, stop promptly and retain the trace reference.
Define inputs and expected output
Record date range, organization, expected 800 item identities and relevant totals.
Expected observation: Correctness can be checked after optimization.
Set the supported trace scope
Target the intended execution user/server according to installed tooling.
Expected observation: Unrelated work is minimized.
Execute and stop
Perform one representative action, then deactivate collection promptly.
Expected observation: The capture has a clear start and finish.
Preserve context
Save trace reference, settings, source revision and cache-state assumption.
Expected observation: A comparison can be reproduced.
06 Read the trace in both chronological and accumulated views
Chronological records show the sequence of accesses. A suitable summary or grouping exposes accumulated cost and repetition. Use both: a summary can reveal 800 similar reads, while detail can show that their parameters repeat the same sixteen keys. Sorting by duration alone may emphasize one event and hide a larger repeated total. [2]
Navigate to the ABAP source location where supported. Check whether the statement is inside an item loop or invoked by several callers. Grouping textually similar SQL is useful but does not prove identical business context. Keep predicates, parameter values and the source call path together before deciding that two requests can safely be combined.
07 Investigate repeated requests without breaking semantics
For Pattern A, compare total lookup invocations with distinct complete business keys. Customer ID may need language, validity date or organizational context. A cache keyed only by the visible customer number could return the wrong label even if it reduces database calls. Define the complete lookup identity first.
Then consider a supported set read or appropriately keyed internal table. Preserve authorization behavior and missing-row outcomes. Repeated references from several items should still enrich every item, and a missing customer must not inherit the previous customer's name. Test both duplicate requested keys and missing lookup rows. SQL reduction is useful only if the output mapping remains correct.
08 Investigate oversized selections and join multiplication
For Pattern B, trace which filters run in SQL and which run later in ABAP. A missing company/date predicate may explain the 20,000-row transfer. A join to several texts per item may multiply rows, especially when language or validity conditions are incomplete. The right correction can be population definition rather than a new database index.
Compare selected columns as well as row count. A broad SELECT can transport unnecessary payload, but reducing fields must retain identity and amount/unit semantics. If aggregation or duplicate elimination is involved, verify that a narrower projection does not collapse distinct business items. Use the related CDS cardinality and join lessons when the multiplication originates in a view model.
09 Troubleshooting trace evidence
Keep the observed SQL fact separate from the explanation being tested. A trace can show high duration or repetition without establishing the underlying cause.
| Observation | Question | Next evidence |
|---|---|---|
| Many repeated parameter sets | Is access inside a repeated business loop? | Caller location and distinct complete keys |
| One broad result | Were filters applied too late? | SQL predicates versus ABAP filtering |
| Rows multiply unexpectedly | Is a join genuinely one-to-many? | Join fixture and language/validity keys |
| SQL time small; app still slow | Is cost elsewhere? | SAT/ABAP Profiler and end-to-end boundaries |
| Expected read absent | Was buffering or wrong scope involved? | Trace scope and supported buffer evidence |
| Before/after timings differ widely | Equivalent input and cache conditions? | Repeat controlled comparison |
10 Avoid premature index and syntax recommendations
An index can help a particular access but also changes write and storage costs. Database platform, cardinality, existing access paths and the wider workload matter. Use the supported plan and database analysis when evidence justifies it, with the appropriate database owners. Do not create an index solely because one predicate contains a familiar field.
Likewise, changing SELECT SINGLE to UP TO 1 ROWS does not automatically reduce repeated requests. A deterministic business choice may require ordering; removing it to simplify a plan changes behavior. First reduce unnecessary work while preserving the required result, then measure the actual access. Keep a copy of the baseline evidence before experiments.
11 Verify correctness and measured effect separately
A positive check compares the same 800 item identities, enrichment values and totals. A negative check includes a missing customer or excluded organization and confirms the intended result. A boundary check uses an empty selection and a larger authorized volume to expose scaling. Compare amounts with their currencies rather than checking only a grand numeric sum.
Then collect an equivalent trace for the reviewed change. For Pattern A, verify whether the relevant database executions actually fell; do not infer that from fewer method calls. For Pattern B, compare transferred rows and result correctness. Report observed duration under stated conditions and include end-to-end runtime if that is the user's concern. These are proposed checks, not performance results from this article.
12 Frequently asked questions and handoff
Does ST05 tell me every expensive ABAP statement? No. Use runtime profiling for the application-code path and SQL trace for database requests.
Should I always warm caches? Only when the experiment concerns repeated execution and excludes initial costs. Keep a separate first-use measurement when that is the symptom.
Does a long SELECT prove a missing index? No. Inspect population, plan, parameters and operational context.
A useful handoff includes action, selection, trace reference, source location, accumulated execution pattern, proposed cause, reviewed change and actual functional/performance checks. State “800 lookups for sixteen complete keys” as the observation and “bulk lookup may reduce work” as the hypothesis until the replacement is measured.
Related services and next steps
Primary sources
Found this useful?
Share this guide with your network, or leave a like.
Your like is saved in this browser.