Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

SAP PI Proxy to JDBC Scenario

 SAP Process Integration Add to favorites

Overview:
Requirement is to insert/update SAP records in non-sap system’s Oracle Table.

To achieve this, we create a Proxy-to-JDBC Asynchronous Outbound Scenario in SAP-PI.

In SAPEcc, one ABAP function module is required to extract data from sap-table and pass it to PI-Proxy-
structure and invoke the SAP-PI-Proxy.

Scenario creation steps:


Scenario is called as SAP-PI’s “Proxy-to-JDBC Asynchronous Outbound scenario”.

[I] Steps in “Enterprise Services Builder“: Repository objects


1. Create DataType/MessageType for Proxy Structure

1. Here include fields which are required to be fetch from SAP-Table

2. Create DataType/MessageType for JDBC Table Query Operations

1. For example JDBC query DataType would be like as below for Table ‘EmpTable’

2.

3. Based on our requirement, here can provide different action method as follows

1. INSERT

1. When record insertion into JDBC table is in scope

2. UPDATE

1. When record updation into JDBC table is in scope


3. UPDATE_INSERT

1. When record insertion/updation simultaneously required



4. DELETE

1. When we need to delete records from JDBC table

5. SELECT

1. When we need to fetch records from JDBC table

3. Create Service Interface Inbound Asynchronous

1. Here select message type designed for JDBC table querries

2. For e.g. SI_ProxyToJdbc_AI

4. Create Service Interface Outbound Asynchronous

1. Here select message type designed for Proxy

2. for. e.g. SI_ProxyToJdbc_AO

5. Create Message Mapping

1. Mapping to transform Proxy structured payload to JDBC-Querry specific structured payload

6. Create Operation Mapping

1. For e.g. OM_ProxyToJdbc
 

[II] Steps in “Configuration: Integration Builder“: Configuration objects 


1. Sender Communication Component

1. BS_SAP  (a configured business system of SAPR3 in SAP-PI)

2. Receiver Communication Component

1. BC_NonSAP (a business component on behalf of Receiver


JDBC system)

3. Sender Communication Channel

1. Its not required, because it’s a proxy scenario which class will be invoked from SAP-ECC.

4. Receiver Communication Channel

1. Select a JDBC Adapter with below connection details


2.

3. Channel Parameters are as follows:

4. JDBC Driver:  oracle.jdbc.driver.OracleDriver

5. Connection:    jdbc:oracle:thin:@<IP>:<PORT >:<DBNm>

6.  Where:

1. IP        is System IP where Oracle database resides

2. Port     is default oracle port 1521

3. DBNm is Oracle Database name

4. user credentials of Oracle database


5. Receiver Determination

1. Sender Communication Component =BS_SAP



2. Sender Interface                                =SI_ProxyToJdbc_AO

3. Sender Namespace                           =urn:ProxyToJdbc

4. Configured Receiver                          = BC_NonSAP

6. Interface Determination

1. Sender Communication Component  =BS_SAP

2. Sender Interface                                 =SI_ProxyToJdbc_AO

3. Sender Namespace                            =urn:ProxyToJdbc

4. Receiver Communication Component=BC_NonSAP

5. Receiver Interfaces

1. Operation Mapping   =OM_ProxyToJdbc

2. Name                        =SI_ProxyToJdbc_AI

3. Namespace              =urn:ProxyToJdbc

7. Sender Agreement

1. Its not required, because it’s a proxy scenario which class will be invoked from SAP-ECC.
8. Receiver Agreement

1. Create receiver agreement with below config details:



2. Sender Communication Component    =BS_SAP

3. Receiver Communication Component =BC_NonSAP

4. Receiver Interface                                =SI_ProxyToJdbc_AI

5. Receiver Namespace                           =urn:ProxyToJdbc

6. Receiver Communication Channel       =CC_JDBC_Receiver

JDBC Adapter’s Message formats for SQL query operations:


To perform table queries using JDBC adapter, we have to create DataType/MessageType for different
operation as shown below:

[I]           INSERT

To insert records into JDBC table, below SQL query is been used

INSERT INTO TableName  (col1, col2) VALUES(‘val1’, ‘val2’)


 and JDBC requires below message format for INSERT operation
<StatementName> <dbTableName action="INSERT"> <table>TableName</table> <access> <col1>val1</col1> <col2>val2</col2> </access> <access> <co

Enter the new column values in the <access> block.

The statement must have at least one <access> element

Example: if multiple employee records need to be inserted in single query, then message format should

be like below:
<?xml version="1.0" encoding="UTF-8"?> <ns0:MT_JdbcInsert xmlns:ns0="http://Test_01"> <StatementName> <dbTableName action="INSERT"> <table

[II]          DELETE

To delete records from JDBC table, below SQL query is been used

DELETE FROM TableName  WHERE ((col2=’val’ AND col4=’val’) OR (col2=’val’))

 and JDBC requires below message format for DELETE operation


<StatementName> <dbTableName action="DELETE"> <table>TableName</table> <key1> <col2>val</col2> <col4>val</col4> </key1> <key2> <col2>val</
Enter the condition under which the table values are to be deleted in one or more <key> elements.

Column values within a <key> element are combined with a logical AND.

different <key> elements are combined with a logical OR.

Note:  If no condition is specified, then entire table gets deleted.

Example:

if we want to delete all record from ‘EmpTable’, which have

Grade ‘X’

EmployeeId 3722188032001 of Department ‘IT’

then its message format is as below


<?xml version="1.0" encoding="UTF-8"?> <ns0:MT_JdbcDelete xmlns:ns0="http://Test_01"> <StatementName> <dbTableName action="DELETE"> <table

[III]         UPDATE

To change records into JDBC table, below SQL query is been used
UPDATE TableName SET col1=’val’, col2=’newVal’ WHERE ((col2=’oldVal’ AND col4=’val’) OR
(col2=’oldVal’))

 and JDBC requires below message format for INSERT operation
<StatementName> <dbTableName action="UPDATE"> <table>TableName</table> <access> <col1>val</col1> <col2>newVal</col2> </access> <key> <col2

Enter the new column values in the <access> element.

In the <key> element, enter the condition that can find the data records whose column values are to be
changed.

Example:

If we want to update Department & Grade for all the records which has

Department as ‘IT’

EmployeeId ‘3722188032002’ with Department ‘AC’

then below message format is required


<?xml version="1.0" encoding="UTF-8"?> <ns0:MT_JdbcUpdate xmlns:ns0="http://Test_01"> <StatementName> <dbTableName action="UPDATE"> <table

 
[IV]        UPDATE_INSERT

We use an UPDATE_INSERT statement to change and add table values. 


JDBC requires below message format for UPDATE_INSERT operation
<StatementName> <dbTableName action="UPDATE_INSERT"> <table>TableName</table> <access> <col1>newVal</col1> <col2>newVal</col2> </access> <

Enter the new column values in the <access> element.

In the <key> element, enter the condition that can find the data records whose column values are to be

changed.

Example:

Here, if we have a case like,

Check in table, if record found with respect to key details, then update same record

else, if record not found, then insert record

for e.g., if we want update Department & Grade of those records which:

ManagerId=5064

has Department=IT and Grade= X


if no such case found then insert Department and Grade in table ‘DeptTable’
<?xml version="1.0" encoding="UTF-8"?> <ns0:MT_JdbcUpdateInsert xmlns:ns0="http://Test_01"> <StatementName> <dbTableName action="UPDATE_IN

[V]         SELECT

If we need to perform SELECT query with JDBC Receiver Adapter, then we need to design a Synchronous
scenario. Here, two maps are required,

1. Request-Map will help to convert Dynamic-data-query into and message format of SELECT query

supported by JDBC-Adapter.

2. Response-Map will help to convert JDBC-returned message output into custom-business-format.

SELECT Query operation:

To fetch specific column records from table based on conditions, below SQL query is been used

SELECT col1, col2, col3 FROM TableName WHERE ((col2 = ‘val’ AND col2 <> ‘val’) OR (col3 > ‘val’))

 and equivalent JDBC adpater requires below request message format for SELECT operation
<StatementName> <dbTableName action="SELECT"> <table>EmpTable</table> <access> <col1/> <col2/> <col3/> </access> <Key1> <col1>val</Departmen


and JDBC returns output response in below message format
<StatementName_response> <row> <col1>val</col1> <col2>val</col2> <col3>val</col3> </row> <row> <col1>val</col1> <col2>val</col2> <col3>val</c

For Example:

If we need to fetch all records from table ‘EmpTable’ which is

of ‘IT’ department which grade is not equal to X

having AGE greater than 55

Then my SQL select query would be as

And JDBC Adapter requires below request message format


<?xml version="1.0" encoding="UTF-8"?> <ns0:MT_JdbcSelect xmlns:ns0="http://Test_01"> <StatementName> <dbTableName action="SELECT"> <table

and as a output JDBC adapter returns below message format data


<?xml version="1.0" encoding="UTF-8"?> <ns1:MT_JdbcSelect_response xmlns:ns1="http://Test_01"> <StatementName_response> <row> <EmployeeId>
Note: JDBC Adapter returns above message format having Message-type-name same as of request with
postFix ‘_response’.

 

About <Key> element:


<Key> elements are equivalent to ‘WHERE’ conditions of sql query’

Column values within a <key> element are combined with a logical AND.

Different <Key> elements are combined with a logical OR.

Attribute ‘compareOperation’ can have values as given in following table for different comparison-

operator:

Attribute Description (comparison-operator)

EQ Equals (default value)

NEQ Does not equal

LT Less than

LTEQ Less than or equal to


GT Greater than

GTEQ Greater than or equal to 

Like (strings). In the corresponding value, the SQL placeholders “%” or “_” can
LIKE
then also be used.

To avoid query operations without conditions, then select ‘Key Tags Mandatory’ in the adapter configuration.

Would you like to access Full Article?


If you are already a member in this website, Please Click here to login If you are not yet a member, Please

Click here to Sign up  



if you have any questions don't hesitate to contact us from the Button bellow

 Contact US

New NetWeaver Information at SAP.com


Very Helpfull

User Rating: Be the first one !

You might also like