1. Open SQL
- ABAP’s database-independent SQL.
- Works on all supported DBs (HANA, Oracle, MSSQL, DB2, …).
- ABAP converts Open SQL statements into the database-specific SQL automatically.
- Ensures portability → same ABAP program runs regardless of underlying DB.
- Supports buffering (e.g., table buffers in SAP).
-
Only a subset of SQL is allowed (the part SAP makes portable).
Example :
DATA: it_mara TYPE TABLE OF mara.
SELECT matnr mtart FROM mara
INTO TABLE it_mara
WHERE mtart = ‘FERT’.
-
This works in any DB under SAP (Oracle, HANA, DB2, etc.).
-
Optimized by SAP kernel, can use table buffering.
2. Native SQL
-
Database-specific SQL.
-
You write SQL directly for the underlying DBMS.
-
Executed via EXEC SQL … ENDEXEC or ADBC (ABAP Database Connectivity).
-
No automatic portability → may not work if you change DB.
-
No table buffering → always hits the DB.
-
Useful when:
-
You need features not available in Open SQL (e.g., DB-specific functions, hints).
-
You want DB-level optimizations.
-
Example:
DATA: lv_matnr TYPE mara-matnr.
EXEC SQL.
SELECT MATNR INTO :lv_matnr
FROM MARA
WHERE MTART = ‘FERT’
ENDEXEC.
This will only work if the DB syntax matches your system (e.g., Oracle-specific SQL won’t run on HANA).
Key Difference Summary:
Feature | Open SQL | Native SQL |
---|---|---|
Portability | DB-independent, portable | DB-dependent, not portable |
Syntax | Subset of SQL, ABAP-friendly | Full DB SQL, DB-specific extensions |
Buffering | Uses SAP buffering (if available) | Bypasses buffering, always DB access |
Performance | Optimized by SAP kernel | Can be optimized manually at DB |
Use Case | Most reports, standard programs | Special DB features, performance tuning, admin tasks |