Skip to content

Limit Number of Table JOINs in OpenSQL Queries ​

WarningPerformance & Database#EC MAX_SQL_JOINSRemote Enabled

Overview ​

Limit number of JOINs in OpenSQL queries.

ATC Finding Message: Too many table JOINs in SQL query; consider CDS View or query decomposition

Rationale ​

Queries joining more than 4 database tables degrade database optimizer join-graph planning, create expensive intermediate temporary tables, and saturate memory on SAP HANA and relational databases. Complex multi-table entity graphs should be encapsulated in Core Data Services (CDS) Views or decomposed into targeted queries.

Best Practice: Model multi-table join hierarchies as reusable CDS Analytical or Transactional Views.

Non-Compliant ​

abap
" Anti-pattern: Excessive table joins in single OpenSQL query (5 joins)
SELECT a~id, b~val, c~text, d~status, e~curr, f~amt
  FROM ztab_a AS a
  INNER JOIN ztab_b AS b ON a~id = b~id
  LEFT JOIN ztab_c AS c ON b~id = c~id
  INNER JOIN ztab_d AS d ON c~id = d~id
  INNER JOIN ztab_e AS e ON d~id = e~id
  INNER JOIN ztab_f AS f ON e~id = f~id
  INTO TABLE @DATA(lt_data).

Compliant ​

abap
" Clean ABAP: Encapsulate join graph in reusable CDS view or decompose
SELECT id, val, text, status, curr, amt
  FROM zc_order_analytics
  INTO TABLE @DATA(lt_data).

Configuration & Thresholds ​

This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:

Parameter NameData TypeDefault ValueDescription & Guidance
MAX_JOINSInteger4Maximum number of table JOINs allowed per query (default: 4)

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC MAX_SQL_JOINS

" SAP CI_ prefix format:
... "#EC CI_MAX_SQL_JOINS

Technical Details ​

Released under the MIT License.