Native SQL
We all know that the ABAP programs use Open SQL, which is translated by the SAP Database Interface into the native SQL of the underlying database during execution. What if I told you that the folks at SAP were prodigies and even before the concept of code pushdown or the existence of SAP HANA by itself, ABAP already supported a way to call and execute native database code directly from the application layer using native SQL!
EXEC SQL.
<native SQL code>
ENDEXEC.
<native SQL code>
ENDEXEC.
This block allowed developers to write native SQL statements specific to the underlying DB (e.g., Oracle, SQL Server, etc.) directly inside ABAP code. It bypassed the abstraction layer of Open SQL and talked straight to the database.
Example:
- Let's say I want to apply some conditions and then retrieve data. These conditions can be based either on default values or on inputs provided by the user. In native SQL, we handle them as follows:
- User-provided values are treated as variables and are prefixed with a colon (
:). - Default values are passed directly within single quotes (
').
- Let’s say I want to select multiple lines of data, this is where the concept of a cursor becomes handy in native SQL. When you're expecting more than one result row, you can use a cursor to fetch rows one by one inside a loop. This gives you control over how data is read and processed, especially in native SQL where direct internal table usage isn't supported like in Open SQL.
Comments
Post a Comment