​A selection of topics on IT and its application to finance. 
​Send me your comments, questions ​or suggestions by clicking
h​ere


elmama
Running back-end host commands from a PC based FORMS Application 


A common forms problem is how to run back-end host commands from a front-end
application. Typically your FORMS app will be running on a PC with NT as the O/S and accessing data held on a server running something like UNIX or Open VMS. There are a couple of ways of running remote server commands from your FORMS app. The first is to use the local DOS command rash and the second is to use the DB MS_PIPE built-in package. In the discussions below I'm assuming the back-end server is running Open VMS.

1) Using rsh

I'm assuming at this stage that the TCP/IP connections between the PC and the remote server are set up correctly. The first thing to do is to set up proxies so that RSH knows which machines can use its services. Then we tell RSH which of the proxies can access it. (for UNIX 'ers these two steps are equivalent to setting up a .RHOSTS file). The third command is required only if RSH loses its command file association which can happen occasionally, but I don't know why. So, login in as system, and at the UCX> prompt first disable the RSH service if its running, then use the commands :

$ add proxy pr oxy_name /re mote_user=pc _username /host=yourpc.ip .number

where pr oxy_name is the OPENVMS proxy name chosen, pc _username is the username used to login to the  PC (this can be the wildcard *) and yourpc.ip .number is the IP address of the PC.

$ set service rash/accept=host=(list of PC dip addresses goes here).
$ set service rash/file=TCPIP$SYSTEM:TCPIP$RSH_RUN.COM


Test the setup from a DOS prompt and if it works correctly you can now call the HOST built-in from your FORMS app and use rash to run a system command on your back-end server. You should note that, in general, programs that require user input will not work correctly using this method but its great for batch jobs and the like.


2) Using DB MS_PIPE

I'm going to present a bare-bones example of how you would use DB MS_PIPE to communicate between a FORMS app and a back-end server. I'm assuming that the package is already created and that the necessary execute permissions are set-up on the database. Essentially you need two programs, one from the FORMS app which sends a system command to the pipe and one on the back-end which continually reads the pipe for in-coming system commands and executes any that are found. The FORMS code could look something like this:-

declare
status number;
sys_command varchar2(100) := 'type sys$login:login.com';
timeout number = 100;
begin
    dbms_pipe.pack_message(sys_command);
    status := dbms_pipe.send_message('pipename',timeout);
end;



The OPENVMS ProC code might look something like:-

#include <stdio.h>
#include <processes.h>
void db_connect();
main()
{
    EXEC SQL BEGIN DECLARE SECTION;
        int status;
        int ret_val = 0;
        char command[200];
    EXEC SQL END DECLARE SECTION;

    db_connect();

    while(1)
    {
        EXEC SQL EXECUTE
        BEGIN
                :status := DBMS_PIPE.RECEIVE_MESSAGE('tom');
                if :status = 0 then
                    dbms_pipe.unpack_message(:command);
                end if;
        END;
        END-EXEC;
        if(status == 0)
        {
            ret_val = system(command);
        }
        if (status > 1)
             break;
    }
}


void db_connect()
{
        EXEC SQL BEGIN DECLARE SECTION;
                char *username = "myuser";
                char *password = "mypass";
        EXEC SQL END DECLARE SECTION;
        // Connect to database
        EXEC SQL CONNECT :username IDENTIFIED BY :password;
}



Run the back-end server code with the command $ pipe run pipe_exe &
and you're now ready to run the FORMS side of things.