Thursday, July 2, 2026

🚀 SAP ABAP Mock Interview — Question 2/50

 

⚠️ The Empty Driving Table Trap in FOR ALL ENTRIES

📋 Scenario

Consider the following code:

SELECT *
 FROM vbak
 INTO TABLE lt_vbak.
SELECT *
  FROM vbap
  INTO TABLE lt_vbap
  FOR ALL ENTRIES IN lt_vbak
  WHERE vbeln = lt_vbak-vbeln.

❓ Question

1️⃣ What will happen if lt_vbak is empty?
2️⃣ Why is this dangerous? 🤔


⚙️ What Happens?

If the driving internal table (lt_vbak) is empty, the FOR ALL ENTRIES condition is ignored.

Effectively, SAP executes:

SELECT *
  FROM vbap
  INTO TABLE lt_vbap.

🔴 All records from VBAP are fetched!


⚠️ Why Is This Dangerous?

  • 🗄️ Massive and unnecessary data retrieval
  • 💾 High memory consumption
  • 📉 Significant performance degradation
  • ⏱️ Potential TIME_OUT dump
  • 📊 Potential TSV_TNEW_PAGE_ALLOC_FAILED dump
  • 🚨 Can severely impact system resources in production


🛡️ Correct Prevention

Always check whether the driving internal table contains data before using FOR ALL ENTRIES.

Classic Approach:

IF lt_vbak IS NOT INITIAL.
  SELECT *
    FROM vbap
    INTO TABLE lt_vbap
    FOR ALL ENTRIES IN lt_vbak
    WHERE vbeln = lt_vbak-vbeln.
ENDIF.

Modern ABAP:

CHECK lt_vbak IS NOT INITIAL.

💡 This ensures the query runs only when there is data to fetch.


🎓 Interview Tip

Many developers answer:
👉 "It causes high database hits."

That's not entirely accurate.

The real issue is usually:
👉 One extremely expensive database read that can fetch millions of records.

Precise terminology matters in senior-level interviews.


💬 Bonus Question

Would your answer change if lt_vbak contained duplicate VBELN values?
Let's discuss in the comments! 👇


📌 Always validate your driving table and remove duplicates for safe and efficient data retrieval.

No comments:

Post a Comment