We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!
A connection to a database must be defined in order to be able to use Native SQL statements. When an AS ABAP is started, a standard connection from the database interface to the standard AS ABAP database is opened. This connection is defined as the current connection for embedded Native SQL statements and as a standard connection for statements when an ABAP program is started. The following SAP-specific Native SQL statements can be used to open additional database connections, which can then be accessed in static Native SQL.
The possible additional AS ABAP connections to database systems are secondary connections defined in the database table DBCON or service connections whose name starts with R/3*.
For detailed information about database connections, see database connections.
EXEC SQL.
CONNECT TO conn $[AS name$]
ENDEXEC.
This static Native SQL statement requests a database connection called conn. This connection is opened or reused if it already exists in an inactive state for the current work process. Once CONNECT TO is executed, the specified connection is the current connection of the internal session, which means that all subsequent static Native SQL statements work with this connection until a connection other than the current is set using a new CONNECT TO statement or using SET CONNECTION.
For conn, a literal or a host variable that contains one of the following values can be specified:
Both of these instances are case-sensitive. If a secondary connection that is not in the database table DBCON is specified, a catchable exception of the class CX_SY_NATIVE_SQL_ERROR is raised. If a secondary database cannot be accessed, sy-subrc is set to 4.
The addition AS can be used to specify a name name for the connection. For name, a literal or a character-like host variable can be specified whose content is used as the name. A connection called name is not the same connection as a connection requested without using the addition AS. This makes it possible to open parallel connections with separate database LUWs for the same secondary connection or service connection within an internal session. In an internal session, only one active database session can be called name. Any attempt to activate a further connection with the same name produces a runtime error. A connection called name can only be specified in the statement SET CONNECTION using this name.
EXEC SQL.
SET CONNECTION ${conn$|DEFAULT$}
ENDEXEC.
This static Native SQL statement sets the current connection for all following static Native SQL statements. For conn, a literal or a character-like host variable can be specified that contains the name of connection activated in the current session.
All of these instances are case-sensitive. When an unknown connection is specified, the current connection remains unchanged and sy-subrc is set to 4.
EXEC SQL.
GET CONNECTION :conn
ENDEXEC.
This static Native SQL statement assigns the name of the current connection to conn. conn expects a character-like host variable. If the current connection was activated using the statement CONNECT TO and AS was used to give it a name at the same time, this name is assigned. If the connection is activated without being given a name, the name of the secondary connection or service connection is assigned. If the current connection is the standard connection, the value DEFAULT is assigned.
The current connection can be active or inactive after its database LUW is closed.
EXEC SQL.
DISCONNECT conn
ENDEXEC.
This static Native SQL statement closes the connection conn for the current work process, which discards all database changes not yet committed using a database commit. For conn, a literal or a character-like host variable can be specified that contains the name of a secondary connection or service connection activated in the internal session.
All other specifications, most specifically the value DEFAULT, produce a runtime error. If the closed secondary connection or service connection is the current connection, the standard connection is set as the new current connection implicitly. All of these instances are case-sensitive.
Opening of a connection to an SAP HANA database and importing of all entries of a column in the database table SCARR.
Leave us your contact details and we will call you back. Fields marked with * are mandatory.
We offer holistic SAP solutions from a single source to shape digital change and develop new business areas.
Switzerland
Schaffhausen
Germany
Mannheim, Düsseldorf, Munich
USA
Haverhill
Greece
Thessaloniki