BAPI method execution with stateful connection

The SAP JCo 3.x connection between SAP R3 and ISIM, by default, is not stateful. The stateful connection is also required in case of transactional BAPIs. To make the connection stateful between Business Application Programming Interfaces (BAPIs) method execution, add the following tags to the XSL files according to your requirement.

To begin a stateful connection, add this tag to your XSL:
<CONTEXT_BEGIN> & </CONTEXT_BEGIN> or <CONTEXT_BEGIN/>
To end a stateful connection, add this tag to your XSL:
<CONTEXT_END> & </CONTEXT_END> or <CONTEXT_END/>

It is not necessary to have both <CONTEXT_BEGIN/> and <CONTEXT_END/> tags in the same XSL. Nested <CONTEXT_BEGIN/> and <CONTEXT_END/> tags can also be implemented, provided that the tags are nested correctly, else unexpected result can occur. Stateful connection started by each <CONTEXT_BEGIN/> tag gets ended by its associated <CONTEXT_END/> tag.

Note: Stateful connection that is started by each <CONTEXT_BEGIN/> tag gets ended by its associated <CONTEXT_END/> tag. If the <CONTEXT_BEGIN/> tag does not have its associated <CONTEXT_END/> tag, the stateful connection gets terminated at the end of JCo connection.
For example, the <CONTEXT_BEGIN/> and <CONTEXT_END/> tags are added to the following files:
  • sapnw_bapi_charact_create.xsl file
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       version="1.0"
       xmlns:xalan="http://xml.apache.org/xslt">
    …..
    …..
    <BAPI_CHARACT_CREATE>
    <CONTEXT_BEGIN/>
    …..
    …..
    </BAPI_CHARACT_CREATE>
    …..
    …..
    </xsl:stylesheet>
  • sapnw_bapi_transaction_commit.xsl file
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       version="1.0"
       xmlns:xalan="http://xml.apache.org/xslt">
    …..
    …..
    <BAPI_TRANSACTION_COMMIT>
    …..
    …..
    <CONTEXT_BEGIN/>
    </BAPI_TRANSACTION_COMMIT>
    …..
    …..
    </xsl:stylesheet>