The EXEC SQL ... END-EXEC
statement can be used to embed Native SQL statically in ABAP programs.
According to the SAP documentation:
Alongside ADBC, it is also possible to embed Native SQL statically between EXEC SQL
and ENDEXEC
in ABAP programs. The
recommendation, however, is to use ADBC. While the static embedding of Native SQL offers exclusively static access to the Native SQL interface, ADBC
makes modern object-orientated and dynamic access possible. New developments and improvements, such as optimized performance using bulk access
across internal tables, are now made only for ADBC.
The existing static embedding of Native SQL statements is still supported but should no longer be used in new programs.
Noncompliant code example
EXEC SQL.
CREATE TABLE abap_docu_demo_mytab (
val1 char(10) NOT NULL,
val2 char(10) NOT NULL,
PRIMARY KEY (val1) )
ENDEXEC.
Compliant solution
NEW cl_sql_statement( )->execute_ddl(
`CREATE TABLE ` && dbname &&
`( val1 char(10) NOT NULL,` &&
` val2 char(10) NOT NULL,` &&
` PRIMARY KEY (val1) )` ).