EXEC SQL

EXEC

Addition:

... PERFORMING form

Effect

Executes the

Native SQL command enclosed by the statements EXEC SQL and ENDEXEC. In contrast to Open SQL, addressed database tables do not have to be known to the ABAP/4 Dictionary and the ABAP/4 program does not have to contain appropriate TABLES statements.

EXEC SQL. 
  CREATE TABLE AVERI_CLNT ( 
		 CLIENT   CHAR(3)  NOT NULL, 
		 ARG1	 CHAR(3)  NOT NULL, 
		 ARG2	 CHAR(3)  NOT NULL, 
		 FUNCTION CHAR(10) NOT NULL, 
		 PRIMARY KEY (CLIENT, ARG1, ARG2) 
						) 
ENDEXEC.

With Native SQL commands, passing data between an ABAP/4 program and the database is achieved using host variables . A host variable is an ABAP/4 variable prefixed by a "*" in the Native SQL statement.

DATA: F1(3), F2(3), F3(3). 
F3 = ' 1 ' 
EXEC SQL. 
  SELECT CLIENT, ARG1 INTO :F1, :F2 FROM AVERI_CLNT 
		 WHERE ARG2 = :F3 
ENDEXEC. 
WRITE: / F1, F2.

To simplify the specification of INTO lists in the SELECT command, you can specify a single structure as the target area as in Open SQL.

DATA: BEGIN OF WA, 
		CLIENT(3), ARG1(3), ARG2(3), 
	END OF WA. 
DATA  F3(3). 
F3 = ' 1 ' 
EXEC SQL. 
  SELECT CLIENT, ARG1 INTO :WA FROM AVERI_CLNT 
		 WHERE ARG2 = :F3 
ENDEXEC. 
WRITE: / WA-CLIENT, WA-ARG1.

In contrast to Open SQL, a client field in Native SQL is a field like any other and must be specified explicitly in calls.

Effect

If the result of a SELECT command is a table, you can read this table line by line in a processing loop. The subroutine form is called once for each line. In this subroutine, you can leave the loop by using EXIT FROM SQL . If the result of the selection is a single record, the subroutine form is called only once.

DATA: F1(3), F2(3), F3(3). 
 
F3 = ' 1 ' 
EXEC SQL PERFORMING WRITE_AVERI_CLNT. 
  SELECT CLIENT, ARG1 INTO :F1, :F2 FROM AVERI_CLNT 
		 WHERE ARG2 = :F3 
ENDEXEC. 
 
FORM WRITE_AVERI_CLNT. 
  WRITE: / F1, F2. 
ENDFORM.

Note

This addition is allowed only with a SELECT command.

Related

SELECT, INSERT, UPDATE, MODIFY, DELETE, OPEN CURSOR, FETCH, CLOSE CURSOR, COMMIT WORK and ROLLBACK WORK.