Do you like my blog? Add me to your Circles X

How to Configure JDBC Adapter in SAP PI

Learn how to configure sender and receiver JDBC adapter to integrate database systems with 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.

Let’s 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.

Typical Configuration of SAP PI JDBC Sender Adapter

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 statement’s output, you need to create a data type and a message type in IR/ESR. In our case it would look something like below:

Standard XML structure for Sender JDBC Adapter

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.

Typical Configuration of SAP PI 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.

Standard XML structure for Receiver JDBC Adapter

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.

Comments

  1. BobC says:

    Nice Blog…but I have a few questions;
    1/ If an update of the database were to occur after the select but before the update would entries be lost or is there some type of locking procedure on the record?
    2/ Do you have and example of how to execute an Oracle stored procedure from the Communication Channel configuration?

  2. suryakanth says:

    Hi Riyaz,

    Nice blog and it is very helpful. Could you please tell me the procedure to integrate sybase with SAP PI. I am searching for this document from past 5 days but couldn’t find any. It will be a great favor.

    Regards,
    Suryakanth

  3. Manikandan says:

    Hi Riyaz,

    How to insert the JPEG file in to Databse…..explain each step plz also wanted to know about how to use the stored procedure in sender and receiver JDBC channel

  4. suhas kundu says:

    Hi All,
    I created a scenario of File-To-JDBC. In where JDBC adapter will be used in the receiver end. I have created a virtual Database through the OpenOfficeOrg Base in my local machine. Now I do not know what should be the credentials for the option “JDBC Driver” and “Connection” in the receiver channel connection parameter.

    Kindly help me out .
    Regards

  1. Nagender says:

    Do you have an example of configuring a stored procedure for sender adapter?

  2. neeraj says:

    The source got converted to html, am reposting it:

    The Central Bank of the Russian Federation has set from 09.12.2010 the following exchange rates of foreign currencies against the ruble without assuming any liability to buy or sell foreign currency at the above rate


    Num сodeChar ‘сodeUnitCurrencyRate
    ’036
    ‘  AUD
    ’1
    ‘  Australian Dollar
    ’30.6275

    ’944
    ‘  AZN
    ’1
    ‘  Azerbaijan Manat
    ’39.0635

    thanks

    • Riyaz Sayyad says:

      If the website provides web services related to your requirement, you can make use of those. Alternatively, you may consider writing a java snippet that would parse the html and provide you the required XML. You can make this java snippet available as a local web service in your environment.

  3. neeraj says:

    Hi,

    We need to pick exchange rates from a website, which contains a fixed html table format. How do we do this from PI.
    The sample source for the html page is as below:
    The Central Bank of the Russian Federation has set from 09.12.2010 the following exchange rates of foreign currencies against the ruble without assuming any liability to buy or sell foreign currency at the above rate

    Num сodeChar сodeUnitCurrencyRate
    036
      AUD
    1
      Australian Dollar
    30.6275

    944
      AZN
    1
      Azerbaijan Manat
    39.0635

    thanks

    neeraj

  4. Quick Facts says:

    You you should change the page name title How to Configure JDBC Adapter in SAP PI | riyaz.net to something more better for your blog post you create. I loved the post all the same.

  5. Anu says:

    Hi Riyaz,
    Thanx for the quick reply.
    How to use the EXECUTE statement.Below are the arguments to be passed..how to give these details ?
    Function Name; FN_ATTENDANCE_DATA_SAP

    Arguments:
    PERNR – Number type
    Flag – Number type
    swipe_in – String type
    swipe_out – String type
    d_date – String type

    Returns:
    Result – Number type

    • Riyaz says:

      As described in the above article, you need to create data types/message types as per the document formats given in the link I shared earlier. Map the input/output parameters to these message types as usual. You need to map a constant value ‘EXECUTE’ to the attribute named action.

      • premdesai says:

        I have tried as you suggested by I see the following error message stating that it is not a stored procedure. I think we can use it with Stored procs not with functions,

        Error

        com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. ‘SAP_PI_TEST’ (structure ‘Statement’): java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00221: ‘SAP_PI_TEST’ is not a procedure or is undefined ORA-06550: line 1, column 7: PL/SQL: Statement ignored

  6. Anu says:

    Hi,

    There is an interface which is currently fetching data from a table.
    Instead of table, there needs to be a jdbc call on oracle function.
    The team wants to fetch the details by a function call.How to do this..

  7. Merhej Mati says:

    Hi Riyaz

    Thank you for your help

    best regards.

  8. Merhej Mati says:

    Hi Riyaz

    Thanks for the quick reply and sorry about the miss

    I have to map a data from oracle to an invoice Idoc

    I have to fetch data form 2 tables , one for the header and one for the details
    the structur in the tables is as the following

    Header 1 — 1
    f1
    f2
    f3
    /Header
    Item1–n
    f1
    f2
    f3
    /Item

    how should the Data type for JDBC sender look like .

    and plz bear with me with also this question.
    suppose there are more than one records (including header and items), how can do the mapping that
    the same number of Idocs is created .

    do I have ti change the occurrence in message mapping in both source and target structures.

    I really apreciate you help and thanks once more

    • Riyaz says:

      To fetch data from multiple tables, you can use joins in the database query. The data type should be exactly as described above in the article. The fields returned by database should be under row node in the same sequence as returned by the query.

  9. Merhej Mati says:

    Sorry , I try again

    Invoice
    Header 1 — 1
    f1
    f2
    f3
    /Header
    Item1–n
    f1
    f2
    f3
    /Item
    /Invoice

    The sender JDBC will probably return r
    Invoice
    row
    f1
    f2
    f3
    /row
    /Invoice

  10. Merhej Mati says:

    Hi Riyaz

    Thanks for you effort .

    I have a question an hope you can help me with it.

    Suppose I have the following structure

    1 — 1

    1–n

    The sender JDBC returns

    How can I replicate it in the Data type for the JDBC sender
    .

    Thanks

  11. Anandh says:

    Nice Blog, I would expect more information on the receiver JDBC channel parameters like “Key Tags” and database transaction levels.

    Regards
    Anandh.B

Speak Your Mind

*