You are on page 1of 5

How to Configure JDBC Adapter in SAP PI

This article will help you understand how to configure the sender and receiver JDBC adapter in SAP PI/XI. We will discuss a simple example wherein we will use sender and receiver JDBC adapter to talk to an Oracle Database. The JDBC adapter is used to connect to different database systems via SAP PI. The adapter converts database content to XML messages and vice versa. Sender JDBC Adapter is used to read data from databases while the receiver JDBC adapter writes data from SAP PI to the relevant databases. Database content can be read with any SQL statement. To write data to database, a predefined XML format needs to be used. You can execute SQL INSERT, UPDATE, SELECT, DELETE, or stored procedure statements. Direct arbitrary SQL statement can as well be used. However, this should be used only for test purposes. Point to note is that a message is always processed in exactly one database transaction. To be able to use JDBC adapter with a particular database, you must install the corresponding JDBC drivers on your SAP PI server. The driver files can be obtained from the database vendor. Now let us configure a simple scenario to understand JDBC adapters. Lets say we have a simple table which stores employee details in an Oracle Database. The table has 4 fields corresponding to Employee Number, Name, Department and a status field to indicate new entries. Our aim is to read new entries from this table using SAP PI. After reading a record, the status field should be set appropriately so that the record is not picked up again. We will configure this using a JDBC sender adapter. Now whenever an employee is transferred from one department to other, this data should get updated back in the Oracle database. We will accomplish this using JDBC receiver adapter.

Configuring the Sender JDBC Adapter


The figure below shows a typical configuration for JDBC sender adapter. JDBC Driver and Connection parameters shown correspond to Oracle database. These parameters differ depending on the database you are using. The correct parameters for your database can be found out from the database vendor.

Poll Interval specifies how often JDBC adapter polls the database. Query SQL Statement should contain the actual SQL SELECT statement using which you want to query the database. e.g in our case
SELECT E_NO as Emp_Number, E_NAME as Emp_Name, DEPT as Emp_Dept from EMP_TAB where E_NEW = 'Y' order by E_NO

Corresponding to your SQL SELECT statements output, you need to create a data type and a message type in IR/ESR. In our case it would look something like below:

The standard format shown must be followed. The JDBC adapter always returns records in the XML format like one shown below. Note that <row> is in all lowercase.

<MessageType> <row> ... ... </row> <row> ... ... </row> ... ... </MessageType>

Document Name in the adapter configuration specifies the Message Type. Update SQL Statement should contain the UPDATE statement so that previously read data is not read again when the adapter polls the database next time. e.g. in our case
UPDATE EMP_TAB SET E_NEW = 'N' WHERE E_NEW = 'Y'

For test purposes, you might want to read the same data again and again. In this case, put the string <test> (including the angle brackets) in the Update SQL Statement field.

Configuring the Receiver JDBC Adapter


Now we want to update the database from PI. Following figure shows required configuration for JDBC receiver adapter.

When you use XML SQL Format as Message Protocol, the data type and message type created for sending the data through JDBC adapter must follow a standard XML format shown below.

When sending the message, the action attribute should contain the type of SQL statement e.g. INSERT, UPDATE, DELETE etc. The table field should contain the actual database table name.

The access node should be used to specify the fields that wish to insert/update in the database while the key node specifies the where criteria of SQL statement. When you use Native SQL String as Message Protocol, the above format is not necessary. In that case, the JDBC adapter expects the actual SQL formatted string as the payload. The Native SQL String protocol should be used only for test purposes however. Now simply create a new employee record in the Oracle database with E_NEW = Y and the sender JDBC adapter will pick it up when it polls the database. To test the receiver JDBC adapter, you might need to configure rest of the scenario or you can send an XML message in the above format from the Test Message tab of Runtime workbench.

You might also like