Establish a connection with the SAP server.
1 sap.connection
<sap.connection
function='function'
client='client'
user='user'
password='password'
lang='lang'
ip='ip'
number='number'
host='host'
service='service'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Afunction | string | Name of the function to execute. | |||
Aclient | string | Client identifier. | |||
Auser | string | Connection user. | |||
Apassword | string | User password. | |||
Alang | string | Language. | |||
Aip | string | IP address or name of the SAP server with which the connection will be established. | |||
Anumber | string | SAP system identifier. | |||
Ahost | string | Link server with the SAP server. | |||
Aservice | string | Link port with the SAP server. |
Returns | |
---|---|
Type | Description |
SAPConnection | Object of SAPConnection type. |
Example
This example shows how a sap connection opens with the host sapserver.
Copy
<xsql-script name = 'sap_connection_test'> <body> <set name = 'sapcon'> <sap.connection function='Z_BAPI_TEST' client='200' user='usuariosap' password='userpass' lang='ES' ip='sapserver' number='00' /> </set> <sap.connection.close><sapcon/></sap.connection.close> </body> </xsql-script>
Example
This example shows how execute a sap function with two input parameters.
Copy
<xsql-script name = 'sap_connection_example'> <body> <!-- Establish the connection with SAP to execute the function Z_BAPI_TEST1 --> <set name = 'sapcon'> <sap.connection function='Z_BAPI_TEST1' client='200' user='usuariosap' password='userpass' lang='ES' ip='sapserver' number='00' /> </set> <try> <body> <!-- DATE parameter --> <sap.connection.setInputParameter> <sapcon/> <string>DATE</string> <string>20130130</string> <!-- Date format YYYYMMDD --> </sap.connection.setInputParameter> <!-- CONSIGNMENT parameter --> <sap.connection.setInputParameter> <sapcon/> <string>CONSIGNMENT</string> <string>X125</string> </sap.connection.setInputParameter> <!-- Execute the function --> <sap.connection.execute> <sapcon/> </sap.connection.execute> </body> <catch> <println><error.message/></println> </catch> </try> <sap.connection.close><sapcon/></sap.connection.close> </body> </xsql-script>
Example
This example is equal than the previous but instead of pass the parameters one by one, they are all passed in an Array.
Copy
<xsql-script name = 'sap_connection_example'> <body> <!-- Establish the connection with SAP to execute the function Z_BAPI_TEST1 --> <set name = 'sapcon'> <sap.connection function='Z_BAPI_TEST1' client='200' user='usuariosap' password='userpass' lang='ES' ip='sapserver' number='00' /> </set> <try> <body> <array name = 'm_parnames'> <string>DATE</string> <string>CONSIGNMENT</string> </array> <array name = 'm_parvalues'> <string>20130130</string> <!-- Date formaat YYYYMMDD --> <string>X125</string> </array> <sap.connection.setInputParameters> <sapcon/> <m_parnames/> <m_parvalues/> </sap.connection.setInputParameters> <!-- Execute the function --> <sap.connection.execute> <sapcon/> </sap.connection.execute> </body> <catch> <println><error.message/></println> </catch> </try> <sap.connection.close><sapcon/></sap.connection.close> </body> </xsql-script>
Example
This example shows how to pass to a SAP function a entry table.
Copy
<xsql-script name = 'sap_connection_example'> <body> <!-- Establish the connection with SAP to execute the function Z_BAPI_TEST2 --> <set name = 'sapcon'> <sap.connection function='Z_BAPI_TEST1' client='200' user='usuariosap' password='userpass' lang='ES' ip='sapserver' number='00' /> </set> <try> <body> <!-- Tha table has the following structure --> <!-- apteid|empcode|fecha --> <array name = 'm_parvalues'> <string>12|01|20130130</string> <string>13|02|20130131</string> </array> <sap.connection.setInputTable> <sapcon/> <string>MOVIMIENTOS</string> <m_parvalues/> </sap.connection.setInputTable> <!-- Execute the function --> <sap.connection.execute> <sapcon/> </sap.connection.execute> </body> <catch> <println><error.message/></println> </catch> </try> <sap.connection.close><sapcon/></sap.connection.close> </body> </xsql-script>
Example
This example shows how execute a SAP function and pass as argument a rank between two values.
Copy
<xsql-script name = 'sap_connection_example'> <body> <!-- Establish the connection with SAP to execute the function Z_BAPI_TEST3 --> <set name = 'sapcon'> <sap.connection function='Z_BAPI_TEST3' client='200' user='usuariosap' password='userpass' lang='ES' ip='sapserver' number='00' /> </set> <try> <body> <!-- The table has the following structure --> <!-- All the registers with accounts between 000 and 201 --> <array name = 'm_parvalues'> <string>I|BT|000|201</string> </array> <sap.connection.setInputTable> <sapcon/> <string>ACCOUNT</string> <m_parvalues/> </sap.connection.setInputTable> <!-- Execute the function --> <sap.connection.execute> <sapcon/> </sap.connection.execute> </body> <catch> <println><error.message/></println> </catch> </try> <sap.connection.close><sapcon/></sap.connection.close> </body> </xsql-script>
Example
This example shows how execute a SAP function and recuperate two output parameters.
Copy
<xsql-script name = 'sap_connection_example'> <body> <!-- Establish the connection with SAP to execute the function Z_BAPI_TEST3 --> <set name = 'sapcon'> <sap.connection function='Z_BAPI_TEST3' client='200' user='usuariosap' password='userpass' lang='ES' ip='sapserver' number='00' /> </set> <try> <body> <!-- The table has the following structure --> <!-- All the registers with accounts between 000 and 201 --> <array name = 'm_parvalues'> <string>I|BT|000|201</string> </array> <sap.connection.setInputTable> <sapcon/> <string>ACCOUNT</string> <m_parvalues/> </sap.connection.setInputTable> <!-- Execute the function --> <sap.connection.execute> <sapcon/> </sap.connection.execute> <!-- Recuperate the parameter ERROR --> <set name = 'err'> <sap.connection.getOutputTable delimiter='false'> <sapcon/> <string>ERROR</string> </sap.connection.getOutputTable> </set> <if><expr><eq><array.size name = 'err'/>0</eq></expr> <then> <!-- Recuperate the parameter ACCOUNTS with the columns separated by pipe --> <set name = 'accounts'> <sap.connection.getOutputTable delimiter='true'> <sapcon/> <string>ACCOUNTS</string> </sap.connection.getOutputTable> </set> </then> </if> </body> <catch> <println><error.message/></println> </catch> </try> <sap.connection.close><sapcon/></sap.connection.close> </body> </xsql-script>