Skip to Content
Author's profile photo Former Member

Stored Procedure Execution and Database Insert, Update with Lookup Option


Sometimes the stored procedure call is necessary in the data processing or data translation. Also sometime it is required to execute DML statement in database and it is important to know the status of execution for subsequent step. So the requirement is to insert or update the database table rows or to execute the stored procedure within the mapping.


The database Insert, Update and Execute is possible with System Accessor Java APIs of SAP PI. It is required to go with Java Mapping or to write an UDF.

Below is the code snippet for the same:


// String Variable to hold the Request XML

String strDBSysRequest = “”;

// Channel Object with JDBC Receiver Channel

Channel channelDBSys = LookupService.getChannel(“BC_XYZ”, “JDBC_R_XYZ_LOOKUP”);

// System Accessor Object with JDBC Receiver Channel Object

SystemAccessor accessorDBSys = LookupService.getSystemAccessor(channelDBSys);

// Convert the Request XML String to Input Stream

InputStream isDBLookup = new ByteArrayInputStream(strDBSysRequest.getBytes());

// Create XML Payload object with request input stream

XmlPayload payload = LookupService.getXmlPayload(isDBLookup);

// Call System Accessor to process the Request data and return the response as XML Payload

XmlPayload result = (XmlPayload);

// Convert the XML Payload into Response XML String

String strDBSysResponse = convertStreamToString(result.getContent());


The String strDBSysRequest need to be prepared as below in case of Stored Procedure execution (exactly same as that of the one which is created for stored procedure execution through normal JDBC Receiver Channel):

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<ns2:SPValidate xmlns:ns2=”“>


        <SP_VALIDATE action=”EXECUTE”>


            <i_id isInput=”1″ type=”string”>JY4UbMhBkoP0501W</i_id>

            <i_card isInput=”1″ type=”string”>123123123123</i_card>

            <i_timestamp isInput=”1″ type=”TIMESTAMP”>14-07-2015 13:13:52.031</i_timestamp>

            <o_res_code isOutput=”1″ type=”integer” />

            <o_res_msg isOutput=”1″ type=”string” />




The sample response XML caputured in strDBSysResponse is as below:

<?xml version=”1.0″ encoding=”utf-8″?>

<ns2:SPValidate_response xmlns:ns2=”“>



        <o_res_msg>Valid Data</o_res_msg>



In case of database update and insert, corresponding XML structure need to prepared and pass as request XML Payload. Refer the link below for more information on SQL XML request structure:

The method convertStreamToString is used in above snippet and the code in this method is as below for the quick reference.


public String convertStreamToString(InputStream in) {

      StringBuffer sb = new StringBuffer();

      try {

            InputStreamReader isr = new InputStreamReader(in);

            Reader reader = new BufferedReader(isr);

            int ch;

            while ((ch = > -1)

                  sb.append((char) ch);


      } catch (Exception exception) {


      return sb.toString();




So here the database interaction is with use of System Accessor and JDBC receiver channel. It is also possible to execute select statement with System Accessor and it is not required to create separate Database Accessor in case if select is also required to be executed in addition to insert/update/execute.


  • Avoid using of multiple Integration Flows
  • Avoid writing java code to create java.sql.Connection and then doing the insert/update/execute


  • There is no control over database commit
  • Not possible to rollback the database updates

Appreciate your feedback and comments on the usage of System Accessor for database interaction.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      great work......appreciate your efforts in sharing this information....

      good luck and happy blogging