Calling Cobol program from PL/SQL

What is the caling convention for PL/SQL to call a Cobol program?

You cannot do it directly from PL/SQL. PL/SQL is.. well, kind of abstract ito the actual platform it runs on. PL/SQL cannot talk directly to operating system. It cannot (itself) do socket calls, file I/O calls, use the printer, etc.
All this has to be done using a lower level implementation library - like UTL_FILE for example that wraps internal C written modules that does file I/O. PL/SQL can call these to do I/O on its behalf. Ditto for wrappers like UTL_TCP and others.
There is no default wrapper for calling external processes from PL/SQL. It can however be done indirectly using the external procedure (EXTPROC) feature, or using Java to do it.
The latter is the easiest. You create a Java stored proc that can access the operating system and run external programs and commands. You punch a big hole in the Oracle Java security to allow this Java stored proc access to the operating system. Next you create a PL/SQL wrapper for this Java proc which then in turn can be called from PL/SQL.
Just remember that you MUST secure this hole you've punched into Oracle security. If any Oracle user can access this PL/SQL wrapper, they can hack, compromise, trash or simply destroy your entire Oracle account on that server.
Here is the basic code:
create or replace and compile Java Source named "OSCommand" as
-- java:        OS COMMAND
-- descr:       Executes an Operating System Command using the JAVA RTS
-- IN parameter:        os command to execute (including fully qualified path names)
-- OUT parameter:       returncode [\nstring]
--                      where string a max of 32000 chars of the output of the command
--                      (note that \n is used as separators in the string)
--                      returncode=-1   Java RTS error occurred (e.g. command does not exist)
--                      returncode=255  o/s command failed (e.g. invalid command params)
import java.lang.*;
public class OSCommand{
        public static String Run(String Command){
                Runtime rt = Runtime.getRuntime();
                int     rc = -1;
                        Process p = rt.exec( Command );
                        int bufSize = 32000;
                        int len = 0;
                        byte buffer[] = new byte[bufSize];
                        String s = null;
                        BufferedInputStream bis = new BufferedInputStream( p.getInputStream(), bufSize );
                        len = buffer, 0, bufSize );
                        rc = p.waitFor();
                        if ( len != -1 ){
                                s = new String( buffer, 0, len );
                                return( s );
                        return( rc+"" );
                catch (Exception e){
                        return(  "-1\ncommand[" + Command + "]\n" + e.getMessage() );
show errors
create or replace function OSexec( cCommand IN string ) return varchar2 is
-- function:    OS EXEC
-- descr:       PL/SQL wrapper for the Java OSCOMMAND stored proc
language        JAVA
name            'OSCommand.Run(java.lang.String) return java.lang.String';
show errors
-- Punching a hole into the Java VM sandbox. The following must be run as
-- sysdba. Substitute SCOTT with the applicable schema that owns the OSEXEC
-- and OSCOMMAND stored procs.
        SCHEMA  varchar2(30) := 'SCOTT';
                '<<ALL FILES>>',
-- example: running the Unix/Linux date command to get the current date and time
SQL> select OSexec('/usr/bin/date') as STDOUT from dual;
Fri Sep  1 08:09:34 SAST 2006
1 row selected.
SQL>Edited by: Billy Verreynne on Sep 4, 2008 6:26 PM to make the code snippet readable with the new Jive forum s/w.

Similar Messages

  • Call C++ programs from PL/SQL

    Can someone give me an example of how to call C++ programs from PL/SQL ASAP please?

    You can use External Procedure facility of of PL/SQL (Assuming your DB is 8 or 8i)
    Please refer the doc at

  • Calling java program from PL/SQL code

    How to develop and call a java program from PL/SQL code?
    What about if this program will call other java programs?

    Perhaps the Java Developer's Guide would be a good place to start

  • Calling java program from PL/SQL

    I already have a java program that encrypts/decrypts data.
    How can I use or rather call this program in PL/SQL?

    Please refer [url]Calling External Subprograms on PL/SQL User's Guide and Reference.

  • Issue while calling COBOL program from Component Interface in PeopleSoft HRMS 9.2

    In HRMS 9.2, I am facing problem while calling the remote call function through component interface. In GP_ABS_EESS_REQ (Navigation Main Menu > Self Service > Time Reporting > Report Time > Absence Request) component, we have “Forecast Balance” button as shown below:
    This button checks for eligibility for leave being applied. While using component interface, it executes FORCAST_PB field change event peoplecode which contains a remote call to a cobol program as below:
    I am getting following error while executing it via component interface:
    (2,148) - Think-time PeopleCode event (RemoteCall), but a SQL update has occurred in the commit interval. (2,148) FUNCLIB_GP_ABS.FCST_PB.FieldFormula Name:Abs_ForecastExec  PCPC:5311  Statement:60
    Called from:GP_ABS_EESS_REQ.GBL.DERIVED_ABS_SS.FCST_PB.FieldChange  Statement:26
    (91,34) - Error changing value. {Z_GP_ABS_EESS_REQ_CI.FCST_PB} (91,34)
    (18,2) - Data being added conflicts with existing data. (18,2)
    (91,37) - Error saving Component Interface. {Z_GP_ABS_EESS_REQ_CI} (91,37)
      After commenting out this line of code, I was able to save the CI successfully. But I need to execute this statement before saving CI so that I can check the eligibility for leave being applied. Can anyone help me on this issue?

    When I tried to read the file using `CAT -vt <filename>`, I could see that the file contains special characters such as ^M and ^I. This may be because of the file transfer mode(but I transferred in ASCII mode, still the special characters where appearing).
    I opened a VI editor and pasted the same script. Save the file, tried to run the script, It was working fine.
    I still didn't get how the special characters appeared. I used notepad++ as my editor.

  • Calling external program from PL/SQL

    Does anyone know whether it's possible to call an external program living outside of Oracle from PL/SQl eg. a from a stored procedure?
    Specifically i want to call back into my java appserver (ejb server) when a trigger/stored proc. is executed.
    The call does not have to be synchronous, some sort of queue will do - eg JMS??
    Any help greatly appreciated.

    Which version of oracle you are using.
    If it 8i, you can use external procedures/libraries. REfer to ORacle PLSQL documentation.
    If you are using Oracle 7+ you can use dbms pipes to post your command string and a cron job to read the pipe and execute the string.
    An alternate ugly way is to write to a file and some process reading the file at a regular interval.
    Arvind Balaraman

  • Scenario to call c programs from pl/sql

    I know that c routines can be called from Oracle pl/sql. But, I would like to know that anybody has the realtime scenario where it is unavoidable.
    Please let me know if anybody has any specific scenarios.
    Thanks in advance

    There are numerous scenarios - as Oracle is operating system agnostic (mostly) and do not provide numerous 3rd party interfaces.
    For example, you want to use MAPI (Microsoft's <i>Mail API</i>). You can write a C dll that provides an easy and basic interface into MAPI - and then define this C dll as external procedure that enables you to perform PL/SQL calls to logon to a Microsoft Exchange Server, verify and get users, send mail, enumerate the contents of a mail box's folder, read a mail, and so on.
    Or something more complex. Oracle is used by an application server that provides automated telephonic call centre support. You know - the automated system that answers your support call, asks numerous questions, gets input from you and attempts to troubleshoot your problem. Modern systems like these use speech recognition interfaces - where the caller can (using plain English) state the problem, instead of pushing tone buttons on the phone.
    Such a system will need XML templates defining the speech recognition interface context - these templates with define the basic sentence structures the caller will use, words used, assign values to the words for processing and so on. These XML templates (together with the troubleshooting data and rules) can be stored in Oracle.
    One function needed will be to verify the XML template with the speech recognition system used. Again, this can be done from PL/SQL. When a new template is entered into the database, PL/SQL can make an external proc call to a C dll that interfaces with SAPI v5 (Microsoft's <i>Speech API</i>) to compile the XML template and determine whether it is valid or not.
    There are literally 1000's upon 1000's of such scenarios that requires one to call external services and interfaces from PL/SQL - and the external proc feature of Oracle is often the technical solution that can be used to address the requirement.

  • How to call VB program from PL/SQL ?

    hi, i use oracle8i and i would like to call program VB from Stored procedur or PL/SQL program.
    Is it possible and how?

    If you are trying to invoke a WebService, it shouldn't matter what under what platform that WebService compiled or where it is executing, as long as it is on a shared network. That is the very "definition" of a WebService. You should be able to invoke the webservice via TCP sockets, streaming XML message content.
    If your VB WebService isn't, in reality, a WebService and you need to invoke it as an ActiveX dll that is possible with Oracle COM Automation. The 8i/9i data server must be running on the win32 platform that has the ActiveX dll installed. I'm not sure if there is any DCOM possibilities (though I suspect not). In all circumstances, if you data server is running on a non-win32 platform, you are out of luck.
    If you are trying to invoke an ActiveX application (not a dll) from the 8i/9i data server, you are pretty much out of luck, too.
    Hope that helps,

  • Running COBOL programs from java

    I am on a project at the moment where we want the client-server to be written in Java on Solaris Sparc UNIX machines. The thing is we want the server to start a COBOL program and the output from the COBOL program will be the reply to the client. Is this possible and if so how?
    Any help gratefully received
    PS We are not looking to buy expensive tools

    JNI would be necesssary if you want to call cobol routines from your java program or vice versa. If you want to communicate with another process then JNI is not really necessary. Indeed it is a very difficult API to master and unnecessary complexity. Well the way I was thinking was that your cobol program can accept input from standard input and write to standard output (if there is such a thing in cobol). You can then read the inputstream of the process which you spawned using runtime.getRuntime.exec("mycobolprogram) mechanism...This should work fairly realiably. I am not sure if this is what you are looking for but give it a try by writing a small cobol program which outputs "Hello World" to standard output and then try reading it from a test java program...

  • Converting Cobol Programs to PL/SQL Packages/Procedures

    Our company is trying to move away from Cobol and code all new projects and begin to convert old code to pl/sqlpackages/procedures. I was wondering if anyone in here had any experience in converting Cobol programs to Pl/sql. Any help would be greatly appreciated.

    user8697075 wrote:
    Our company is trying to move away from Cobol and code all new projects and begin to convert old code to pl/sqlpackages/procedures.JOY!! ;-)
    I have written a lot of Cobol and converted a lot of Cobol (not to PL/SQL though). But the mere thought of it, brings a song to my heart. :D
    PL/SQL will be significantly faster and more scalable than using Cobol. It is also a lot simpler to design and code than using Cobol. Always found Cobol development very boring - except for the odd occasions when we had to design and write re-entrant Cobol code..
    Just do not make the mistake of attempting a straight port - rewriting a Cobol program essentially line by line into a PL/SQL unit. Implementing row-by-row slow-by-slow processing into PL.SQL.
    Without rethinking the process flow, the program design and so on, the resulting code unit will be little better than the original Cobol unit. Which begs the question, why bother and why use the new code then? In fact, seen this first hand back in the 80's when this approach was used to convert a pretty large system from Cobol to Natural. After many man years of development (and lots of money), the new system had all the problems of the old.. and was canned during the testing phase. Money, time and resources utterly and totally wasted.

  • Calling Java programs from Oracle Stored Procedure

    Is it possible to call Java programs from Oracle stored procs? If possible Can this be used to exchange data from other applications? Is there a better method/feature in oracle for doing data exchange with other apps?

    If what you mean by Oracle stored procedures is pl/sql then yes.
    You can create a "wrapper" this way:
    in_mapUrl IN VARCHAR2,
    in_inputUrl IN VARCHAR2
    RETURN java.lang.String';
    Then load the java as:
    loadjava -user youruser/youruserpasswd -resolve -verbose lib/xmlparserv2.jar classes/com/yourcompany/xform.class classes/com/yourcompany/xml2any.class
    The java, given the correct permissions, can do anything java can do including communicate with outside applications.
    Is this the "best" way... depends on what you are trying to accomplish.

  • Call HOST cmd from PL/SQL Block

    Hi ,
    I'm trying to call the HOST command from stored procedure
    cmd varchar2(100):='c:\file.bat';
    execute immediate 'host('c:\file.bat')';
    but,It gives an error msg on execute immediate stmt.
    Plz resolve this problem.

    You are confusing SQL*Plus's command (a client) with that of PL/SQL.
    Just as you cannot code C# commands, or Perl commands, or PHP commands in PL/SQL, you cannot code SQL*Plus commands in PL/SQL.
    SQL*Plus runs on your client platform. It has a couple of commands.
    PL/SQL is a server side programming language. This runs inside the Oracle server process servicing the client.
    This server process does not know your client language commands. Nor can this server process hack across the network, break into your computer, and access your local file called c:\file.bat.
    Yes, you can execute server o/s commands and execute server programs from PL/SQL via a Java stored procedure or via the EXTPROC interface. Refer to the sample code in [url]this thread on how to call server o/s commands and server programs.

  • I want to submit a concurrent program from pl/sql. Please help me.

    Dear all,
    I want to submit a concurrent program from pl/sql. But I failed. Please help me.
    I create a concurrent program in 'Cash Management, Vision Operations (USA)' responsibility. <strong>And it be submitted success in EBS</strong>.
    I create a test script in pl/sql. And use 'FND_GLOBAL.APPS_INITIALIZE' to initialize ebs, then use 'FND_REQUEST.SUBMIT_REQUEST' to submit
    the consurrent program, But the procedure aways return <strong>0</strong>.
    I cannot found the reason. Please help me.Thanks.
    <em>Attached informations may describe the problem:
    1.The concurrenct submitted success in EBS.</em>
    request_id = 4750655 (Sorry, I dont know how to add pictures.)
    <em>2.The initialize informations which from SQL</em>.
    AND FCR.REQUEST_ID = 4750655;
    Result: user_id = 1318;
    responsibility_id = 50579;
    application_id = 260;
    application_short_name = 'CE';
    program_short_name = 'CALLK009';
    <em>3.The test script code.</em>
    -- Created on 2008/10/22 by ERIC
    -- Local variables here
    Wv_conc_req_id VARCHAR2(10) DEFAULT NULL;
    Wv_conc_req_id := FND_REQUEST.SUBMIT_REQUEST(
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    , CHR(0), CHR(0), CHR(0), CHR(0), CHR(0)
    <em>4.The concurrent program code.</em>
    create or replace package body CALLTEST is
    ,PvO_retcode OUT VARCHAR2)
    FND_FILE.PUT_LINE(fnd_file.log, 'TEST');
    end CALLTEST;

    Can you check from which schema you are executing FND_REQUEST? You can try as follows;
    Connect to your required schema, create a synonym on apps.fnd_request, connect from apps and finally execute grant all on apps.fnd_request to all.
    You can check for relevance from Doc ID: Note:147495.1
    Please do keep in the mind the soultion above should be applied to a test/dev EBS instance first.
    I hope this would be of help.

  • Calling a report from pl/sql

    Is it possible to call a report from pl/sql. I want to create a package which when invoked by dbms_jobs will create parameters and then call a report.
    Thanks in advance,


  • How to call a program from FM which acts as popup?

    I need to call a program from FM and once the program is called it needs to be opened as a popup. Maybe we need to assign size when we call from FM or do we need to give size in the program it self?
    I know i can either use the Submit command or Call Transaction command. But that it self will open a full screen which i dont want. It needs to be of a smaller size.
    Any help will be appreciated.

    Try this,
    * Table Declaration
    * Start of Selection
    * Display the screen
             ENDING   AT 40 25.

Maybe you are looking for