Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
I decided to write this blog after regularly seeing forum questions about accessing external databases
from ABAP.
I will try my best to describe how to connect to non-SAP databases from ABAP, and also encourage you
to try it yourself using an example I built with the SAP NetWeaver 7.01 ABAP Trial Version.
You can obtain the SAP NetWeaver 7.01 ABAP Trial Version from here
(https://www.sdn.sap.com/downloads/netweaver/abap/disclaimer.html). If you need help installing the
ABAP Trial Version refer to this blog (ABAP Trial Version for Newbies: Part 1 ' Download and installation
of the Trial Version ') by Manfred Lutz.
DB MultiConnect Overview
The SAP NW Web Application Server ABAP (NW-ABAP) is built on a 3-tiered architecture: presentation,
application and database. The database layer of a SAP system is a central database with a database
management system (DBMS) and the database storage and content.
The work processes of the SAP application layer have a database interface that communicates with the
database layer. When a SAP application server is started the default database connection to the
central database of the SAP instance is opened.
This default database connection makes life very easy for the ABAP developer because there is always
a database connection ready and available for them. They do not need to worry about opening,
administrating and closing database connections as you do in many other programming languages.
NW-ABAP also has the capability to connect to DBMS's other than the one that SAP is actually running
on. SAP calls this "DB MultiConnect", but I have also seen them write it as "Multiconnect", "Multiconnect" and "Connect".
For the remainder of this blog I will use the terms "SAP database" and "non-SAP database" to refer to
these two different types of database connections.
Non-SAP databases may or may not be running on the same server as the SAP database. They may or
may not be running on the same DBMS platform as the SAP database. In fact the non-SAP database
could actually be physically located on the same database instance as the SAP database if you wanted
- as in the example I describe later in this blog.
For DB MultiConnect to work the non-SAP database must be a DBMS that is supported by the SAP ABAP
kernel. Currently this means DB2, Informix, MS SQL Server, Oracle or SAP DB.
Importantly, the running SAP kernel must also support the non-SAP DBMS. This means, for example,
that to connect to a MS SQL Server non-SAP database the NW-ABAP application server must be running
Windows. This is because the only SAP ABAP kernel that supports MS-SQL is the windows kernel. On
the other hand if the non-SAP database is running on Oracle, DB2, SAP DB or Informix you will find that
most SAP kernels support these DBMS platforms. It does not matter what OS platform the non-SAP
database is running on, as long as the DBMS is supported by the SAP kernel you are running.
Platform availability can be checked on the SAP Product Availability Matrix
at http://service.sap.com/pam (http://service.sap.com/pam)
DB Connectivity
To access a non-SAP database we first need to establish technical connectivity from our NW-ABAP
application server(s) to the Remote-DB.
Depending upon the specifics of the database platform this may require the installation of some DB
Client Tools. For example in the case of a non-SAP database running on Oracle you would need to setup
Oracle Net8 (SQL*Net V2) on the SAP application server so it can connect to the database.
There are a series of SAP notes that explain DB specific requirements. You can find a list of them in this
section
(http://help.sap.com/saphelp_nw04/helpdata/en/50/63d6b37bda7f4a92e2dec21b14ceee/frameset.htm)
of the SAP Help.
Database Library
Each SAP kernel includes a database specific library that it uses to connect to database management
systems.
Many of you will be familiar with the process of downloading and installing ABAP kernel updates. The
SAP kernel includes a set of database-independent components and a set of database-specific
components. When downloading a kernel update from the SAP Service Marketplace you need to obtain
the database-independent archive and the database-specific archive that relates to your database
platform. Both these archives are extracted and combined to form the complete ABAP kernel.
When you need to connect to multiple databases you must ensure you include the relevant databasespecific components for all the databases you connect to. For example if you are running your SAP
application server on an Oracle database and you also want to connect to a MS SQL Server database
you would need to combine the database-independent, Oracle database-specific and MS SQL Server
database-specific components to form your complete SAP kernel. If you wanted to also connect to an
Informix database then you need to include the Informix database-specific kernel components as well.
System Configuration
Once technical connectivity to the non-SAP database is in place the next step is to configure in the SAP
system the specific configuration and authentication details of the non-SAP database. This is so the
ABAP runtime environment knows how to access the database.
This information is held in table DBCON which can be maintained with transaction DBCO.
Again you will need to refer to the specific SAP Note for the database platform to determine the exact
format of the details to place in this table. You may also need assistance from your database
administrator to verify the specific details for your database.
Let's do it!
Okay let's try it for ourselves. As mentioned, this example was built using the SAP NetWeaver 7.01
ABAP Trial Version (NSP) but if you wish you could try this with any SAP NW-ABAP system. You will just
need to modify the platform-specific parts of the example if your non-SAP database is not on the
MaxDB platform.
In this example we are going to do a "loopback" connection to the same MaxDB database that NSP is
running on. This saves us having to find another database to connect to and makes the example
simpler to implement.
Now let's have a look at the sample database. Start SQL Studio and connect to the database using
username "MONA" and password "RED".
Use the tree navigation to expand the "Tables" branch and then the "HOTEL" schema. You will see
several objects in here including the view called "CUSTOMER_ADDR". If you right-click on this view and
select "Open Object Definition" you can see it is a join of the CUSTOMER and CITY tables.
In the SQL Dialog window to the right enter "*select * from hotel.customer_addr" and click the
execute (!*) button. This will show you the contents of the CUSTOMER_ADDR view.
I have called my connection "MONA". The DBMS is "ADA" for MaxDB (or SAP DB if you prefer). Enter
"MONA" for the username and "RED" for the password. Yes it is case-sensitive.
Referring to the SAP Help link I mentioned earlier
(http://help.sap.com/saphelp_nw04/helpdata/en/50/63d6b37bda7f4a92e2dec21b14ceee/frameset.htm)
you will see that the connection information for SAP DB should be of the format <server_name><db_name>. So for us "localhost-NSP" will do the job. This points the new connection at the local
NSP database and connects us as the user MONA.
If you are not using the NSP database as your non-SAP database you will need to adjust these settings
to suit your specific requirements.
1.
REPORT zmona_read_customer_addr.
2.
3.
cno(4)
4.
title(7)
5.
name(40)
6.
zip(5)
TYPE c,
7.
city(3)
TYPE c,
8.
state(2)
9.
address(40) TYPE c,
10.
TYPE n,
TYPE c,
TYPE c,
TYPE c,
END OF mona_cust_addr_type.
mona_cust_addr_type,
25.
26. ENDEXEC.
27. * Fill customer itab
28. DO.
29. EXEC SQL.
30.
31.
:ls_custaddr-title,
32.
:ls_custaddr-name,
33.
:ls_custaddr-zip,
34.
:ls_custaddr-city,
35.
:ls_custaddr-state,
36.
:ls_custaddr-address
37. ENDEXEC.
38. IF sy-subrc <> 0.
39.
EXIT.
40. ELSE.
41.
42. ENDIF.
43. ENDDO.
44. * Close connection to MONA
45. EXEC SQL.
46. CLOSE dbcur
47. ENDEXEC.
48. * Reset to "default connection"
49. EXEC SQL.
50. SET CONNECTION DEFAULT
51. ENDEXEC.
52. * Print 20 records
53. LOOP AT lt_custaddr INTO ls_custaddr.
54. WRITE: /,
55.
ls_custaddr-cno,
56.
ls_custaddr-title,
57.
ls_custaddr-name,
58.
ls_custaddr-zip,
59.
ls_custaddr-city,
60.
ls_custaddr-state,
61.
ls_custaddr-address.
EXIT.
64. ENDIF.
65. ENDLOOP.
When you run this program you should see the same data that we found in the
CUSTOMER_ADDR view when we used the SQL Studio select statement.
Connecting to External
Database from SAP
created by Venkateswaran Krishnamurthy on Jun 3, 2012 11:38 AM, last modified
by Venkateswaran Krishnamurthy on Jun 3, 2012 8:52 PM
Version 1
inShare
Tweet
Scenario
In today's business scenario, at the time of SAP implementation, it is
required that we need to fetch data from the customer's existing third party
application. For example the customer is having some websites where the
enquiries are being stored. Or The company employees who are on tour log
their requests for leave in the portal. In such case we may have to provide
an interface between their existing application to the upcoming SAP system.
It is possible that the system is using a differetn database altogather. So in
that situation how a connectivity is established between the SAP database
and External Application database.
1.
2.
3.
4.
DISCONNECT :'MYCONNECTION'
ENDEXEC.
WRITE: / l_record.
This should work and you should be able to fetch data from the external database.
That scenario is required that we need to fetch data from the customers existing third party
application. For example the customer is having some websites where the enquiries are being
stored. Or The company employees who are on tour log their requests for leave in the portal. In
such case we may have to provide an interface between their existing application to the
upcoming SAP system. It is possible that the system is using a different database altogather. So
in that situation how a connectivity is established between the SAP database and External
Application database.
You can create connection to external database with below processes.
1 Connection check from SAP to External Database
You have to access external database from SAP network. You can check firewall, telnet configuration.
During a recent bit of consulting I was asked to connect SAP to various External
Databases. SAP impressed me with its Multi-Connect feature and I thought it
worthy of a couple of quick videos.
If youre already running SAP on Oracle then you can skip to Step 5
Step 1: Download the database library. Under Kernel Patches and make sure
you select the database version you want to connect to in this example Oracle.
Step 2: Unpack and copy the library itself dboraslib.dll to your application
instances kernel folders. In the video I leveraged the instance.lst file to get SAP
to do this for me as part of the SAP startup sapcpe process.
Step 3: Download and unpack the Oracle Client Tools
Step 5: Configure Oracle Net Manager to point to our External Oracle Server
As the client tools are installed its very simple to test the connection
using tnsping
Step 6: In SAP transaction SM30 table maintenance for DBCON. Add the
connection using the connection name we just created in Oracle Net Manager.
Step 7: Code away. You can download my sample ABAP program here.
If youre looking for this the other way around connecting from Oracle to
Microsoft SQL see http://www.mattbartlett.co.uk/connecting-sap-on-oracle-toan-external-microsoft-sql-db
During a recent bit of consulting I was asked to connect SAP to various External
Databases. SAP impressed me with its Multi-Connect feature and I thought it
worthy of a couple of quick videos.
If youre already running SAP on Microsoft SQL then you can skip Steps 2 and 3.
Step 1: Make sure your SQL server is setup to support SQL Server
Authenticationas the default is Windows Authentication Mode only.
If in any doubt of your SQL configuration try using the standard Windows ODBC
data source wizard. If youre not getting a connection dont forget your listeners.
Step 2: Download the database library. Under Kernel Patches and make sure
you select the database version you want to connect to in this example MS SQL
Server.
Step 3: Unpack and copy the library itself dbmssslib.dll to your application
instances kernel folders. In the video I leveraged the instance.lst file to get SAP
to do this for me as part of the SAP startup sapcpe process.
Step 4: In SAP transaction SM30 table maintenance for DBCON. Add the
connection. MSSQL_DBNAME is optional and you can use named pipes if you
Step 5: Code away. You can download my sample ABAP program here.
Quite often someone asks me how an external SQL Server database can be accessed by an SAP
system, e.g. to:
Access data in an external SQL Server database with the SAP system
Report against data in an external SQL Server database with Business Intelligence / Business
Warehouse
Use DBACockpit to monitor an external SQL Server instance
Depending on:
Which type of SAP application servers (ABAP, Java, Dual-stack) are available in the SAP system
There are different connection types, technical requirements and restrictions. This blogpost clarifies
the possibilities and restrictions and covers frequently asked questions:
1.
2.
3.
4.
5.
The SAP standard ways to connect an external SQL Server instance with an SAP system are:
Multiconnect (DBCON)
DBCON / Multiconnect
DBCON / Multiconnect uses the Microsoft SQL Server Native Client Software (SNAC) to establish a
connection to the remote SQL Server instance. The Microsoft SQL Server Client Software for Windows
consists of several *.dll files. For long time it was available for Windows platforms only. Recently,
Microsoft ported its ODBC SQL Native Access driver to Linux. For this reason heterogeneous
Linux/Windows scenarios are now possible. DBCON utilizes the SAP ABAP stack to access the external
databases so your system requires at least one ABAP-stack-based SAP Application Server running on
Windows or Linux x86_64.
UDConnect
UDConnect uses a JDBC (Java Database Connectivity) driver to establish a connection to the remote
SQL Server instance. The JDBC driver consists of one or more *.jar files and can be used on Windows,
Unix and Linux operating systems. As UDConnect utilizes the J2EE engine of the SAP Application server
to access the external databases you need to have at least one Java-Stack-based SAP Application
Server in your SAP system in order to use UDConnect.
Connectivity Matrix
Windows
Linux x86_64
Unix
UDConnect
UDConnect
UDConnect
DBCon
DBCon
none
UDConnect
DBCon
UDConnect
UDConnect
Java Stack
ABAP Stack
Dual Stack
Remarks:
If your system comprises solely of ABAP stack-based servers running on Unix platforms you
can neither use UDConnect nor DBCON. Why? Because UDConnect requires at least one Java-stack
based SAP Application Server (regardless of the operating system) and DBCON requires at least one
Windows- or Linux x86_64-based SAP Application Server.
Using DBCon on a Linux x86_64 based application server can only be used to connect to SQL
Server versions 2005 and higher. Predecessor releases are not supported by the Microsoft driver.
Furthermore, the driver is only supported for Red Hat Enterprise Linux 5.x and higher and for Suse
SLES11 SP2 and higher.
UDConnect cannot be used for remote monitoring a SQL Server based system. However, you can use it
to access data in an external SQL Server database.
Setting up UDConnect in order to access data in an external SQL Server Database with BW/BI requires
four steps:
Configure the connection URL for the external database on Java-stack side
For step-by-step instructions please see the configuration guide available under:
SAP Netweaver '04: How to configure UD Connect on the J2EE Server for JDBC Access to External
Databases
SAP Netweaver 7.1: see attached guide (UDConnect_for_710.pdf)
To access data in an external SQL Server Database with DBCON / Multiconnect three steps are
required:
Determine which kernel your SAP system is using (32 bit / 64 bit, Unicode / Non-Unicode,
Kernel Release, Operating System)
kernel release: go to ransaction SM51 place the cursor on the SAP instance click
o
"Release Info"
Download the archive containing the most recent SAP DBSL for SQL Server matching your
kernel
Copy the unpacked dbmssslib.dll file into the kernel directory of all SAP application servers
which you want to use to establish the connection.
SAP DBSL for Linux x86_64
Please see SAP note 1644499 if you need to download and install the SAP DBSL for Linux x85_64based servers. The note describes how to request the DBSL and also explains in detail which steps are
required to properly set it up.
DBCON entry
The DBCON entry informs the ABAP-stack where to find the external SQL Server Database and how to
authenticate. Please see SAP note 178949 to learn how to create a DBCON entry for an external SQL
Server Database.
To monitor an SQL Server database with DBACockpit you first need to configure a DBCON connection to
the external database. Please refer to section 3 for details.
If your local system is running on SQL Server as well you can skip installing the Microsoft SQL Server
Native Client (SNAC) and SAP DBSL for SQL Server as both will already be in place. Then, proceed with
the DBACockpit-related configuration steps. You can find detailed guides attached to SAP
note 1027512 (sqldba_cockpit.pdf) and in SAP note1316740.
UDConnect cannot be used for remote monitoring - the only way you can monitor a remote system is
by using DBCon.
5. Troubleshooting
No shared library found for the database with ID <DBCON_entry_name> or Unable to find
library <kernel_directory>/dbmssslib.sl'. ->
DLENOACCESS (0,Error 0) or ERROR => DlLoadLib()==DLENOACCESS - dlopen ("/usr/sap/<SID>/DVEBMGS00/exe/dbmssslib.so") FAILED
or could not load library for database connection <DBCON_entry_name> or cannot open shared object
This error indicates that the ABAP stack could not find the SAP DBSL for SQL Server (dbmssslib.dll) in
the kernel directory. If you encounter this error on a Unix - based server the root cause is clear: the
DBSL does not exist for other platforms than Windows or Linux x84_64. In this case use a Windowsbased or a Linux x86_64-based SAP Application Server to establish the connection. If your system does
not contain a Windows-based or a Linux x86_64-based Application Server you need to setup a small
one as workaround. If you encounter this error on a Windows Application Server or a Linux x86_64
based Application Server make sure that the DBSL is properly installed in the kernel directory as
explained in point 3.
the file from scratch as explained in point 3. If the error remains afterwards please check the OS Log
for further errors at the time of the error.
You want to update the JDBC driver used by your UDConnect connection
Follow the instructions in SAP Note 1009497.