sap_multi_table_query
Join data from multiple SAP tables with proper joins and aggregation, using depends_on to filter master data and avoid timeouts.
Instructions
Execute a multi-table query with proper joins and optional aggregation. Use this when you need data from 2+ tables that must be merged. Provide a JSON query plan with steps for each table, merge configuration, and optional aggregation. SUPPORTS AGGREGATION: For 'top N' queries, use the aggregation section to group, sum, sort, and limit results. IMPORTANT: Use this instead of multiple sap_read_table_data calls when you need joined data! CRITICAL - depends_on: When querying lookup/master data tables (KNA1, LFA1, MARA, etc.), ALWAYS use 'depends_on' and 'filter_field' to filter by keys from the primary table. This avoids querying the ENTIRE master data table. Example: To get customer names for sales orders, set KNA1 step with depends_on='orders', filter_field='KUNNR' — this queries only the customers in your order results. Without depends_on, KNA1 returns ALL customers (100K+) causing timeouts. NOTE: If the query returns more than 1000 rows, you will receive a 'requires_confirmation' response. You MUST ask the user if they want to see all the data. For 'last N' or 'most recent' requests, use sort_by + sort_order + limit instead of confirmed=true. Example: sort_by='WADAT_IST', sort_order='desc', limit=10 returns the 10 most recent deliveries. Fields in WHERE clauses and field lists are validated against table structure. Use sap_get_field_metadata or sap_read_table_structure first to discover correct field names.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Return only this many rows after sorting. Use with sort_by for 'last N' / 'top N' queries. | |
| sort_by | No | Field to sort final results by (e.g., WADAT_IST, ERDAT, NETWR). Applied after merge. | |
| max_rows | No | Maximum rows in final result (minimum 1000 enforced) | |
| confirmed | No | Set to true after user confirms they want large results (>1000 rows) | |
| query_plan | Yes | Query plan with steps and merge configuration | |
| sort_order | No | Sort direction. Use 'desc' for most recent / highest first. | desc |