How to Call PL/SQL or Batch file from siebel escript

Calling PL/SQL or Batch file from Siebel is always fun, it gives end users added flexibility to generate report by themself. Here we will see how to use Clib function in Siebel escript to call PL/SQL or batch file.
Suppose, we have to fetch Opportunities which start with Opportunity Name like ‘Test’ and write it in to a file. So our first task is to write one batch file which will have SQL statement with spooling option to fetch opportunities and next step, call batch file from siebel browser script.

Step 1:
Write all sql statements into a file, including the query “SELECT A.ROW_ID, A.NAME FROM SIEBEL.S_OPTY A WHERE A.NAME LIKE ‘Test%’; ” and save the file with .sql extension. We have saved it as opty.sql. The SELECT SQL statement will fetch all opportinities where name starts with ‘Test’ and spool it in opty.txt. Our opty.sql file looks like below.

Set heading off
Set echo off
Set feedback off
Set pagesize 0
Set inlinesize 256
Set serveroutput off

Spool “D:Runsqlopty.txt”
Spool off

Step 2:
As we can not call SQL statement directly from Siebel script, we will put it in one batch file. So we have created one batch file opty.bat which will be used in script. Batch file should look like below:
Absolute path of Sqlplus.exe Database_UserName/[email protected] @absolute path of the sql file

Step 3:
Now write one client side business service which will call opty.bat. Go to Administration – Business Service and create a new BS ‘Generate Report’ with method name as ‘Generate Report’.
In PreInvokeMethod, use Clib function to call the bat file.

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
        Clib.system(“D:\Runsql\opty.bat”); //give the absolute path of the file location.
        retunr (CancelOperation);

Now verify the bisuness service, go to Administration – Business Service > Simulator and create a record with Service name and Method name and click on Run. It will create an output file ‘opty.txt’ with opportunity details where Opportunity name starts with ‘Test’.

If you have any doubt or question, feel free to comment here. To get more updates on recent activities, follow ‘TechOneStop on Facebook/Twitter/LinkedIn or join our website as followers.

SBL-EAI-04397 / SBL-BPR-00162: No user key can be used for Integration Component
Siebel Configuration Interview Questions & Answers

Speck Your Mind