Q: How to call SQR from SQL*Forms 3.0 on a UNIX platform (SQR v2.5.x/3.0.x - Oracle v6/7)

A: SQR programs can be called from SQL*Forms using either the USER_EXIT command or the HOST command. Either method allows starting the SQR program via the use of a form trigger. The fact that an SQR program was initiated by forms is transparent to the form user. There are advantages and disadvantages to both methods.

   Advantages:
   USER_EXIT: Shares the forms Login Data Area and does not create an
  		additional system process.
		Can pass data back to the form using the SQR PUTFORM module.
		Can call SQR programs with the -XC flag to delay doing a
		database commit.
   HOST: Easier to implement.
         Does not require re-linking of the runform30 and sqlforms30
   	 executables.
   Disadvantages:
   USER-EXIT: More difficult to implement.
             	Must re-link the runform30 and sqlforms30 executables to
		implement and when new versions of SQR are installed.
    HOST: Must create its own Login Data Area and thus creates an additional
		system process.
		Cannot pass data back to the form.
		Cannot be run with the -XC flag to delay doing
		a database commit.
   Requirements:
   USER_EXIT:	A C compiler and Oracle’s PRO*C pre-compiler.
	        7MB of disk storage space to re-link new runform30 and
		sqlforms30 executables.
   HOST: 	No additional requirements.

 The steps for calling an SQR program with the USER_EXIT command are:
		Compile the sqrexit.pc program.
		Create the Oracle IAPXTB table.
		Create the iapxtb.c program and compile it.
		Modify the sqlforms30.mk file and re-link the runform30x and
		sqlforms30x executables.
		Create a form to call SQR as a user exit.
		Run the form.
 Calling an SQR program with the HOST command only requires the last two steps
 above.

 Following is a step by step description of the above:

 Calling SQR from Oracle SQL*FORMS 3.0 with the user_exit command on unix:

1) Change to the FORMS30 directory.

	$ cd $ORACLE_HOME/forms30/lib

2) Create an environment variable called SQRLIB to point to the SQR lib
   directory. For example:

	$  SQRLIB=/sqr_install/ora/workbench/lib;export SQRLIB

3) The file sqrexit.pc is provided as an all purpose user exit for passing
   values from SQL*FORMS and calling SQR. Use it as is or alter it to suit your
   requirements. Copy it from the SQR lib directory and precompile using PROC.

        $ cp $SQRLIB/sqrexit.pc sqrexit.pc
	$ proc iname=sqrexit.pc ireclen=132 oreclen=132

    Compile the resulting C program.

	$ cc -c sqrexit.c

4) Create the table IAPXTB if it does not already exist. Use GENXTB to create
   it.

	$ genxtb username/password

    Insert the user exit name into the IAPXTB table.

	$ runform30 genxtb username/password

                                    ******** GENXTB ********
	User Exit     Type       Remarks                Creation         Modify
	SQREXIT       C          SQR User Exit

    Enter the name, type, and description of the user exit and press COMMIT to
    save it. Exit the form.

    Generate a C program (iapxtb.c) using genxtb.

	$ genxtb username/password iapxtb.c

    Compile the resulting C program.

	$ cc -c iapxtb.c
	
5) Modify the sqlforms30.mk file.

     Change the IAPXIT variable to include sqrexit.o. For example:

	IAPXIT=iapxtb.o sqrexit.o

     Define an SQRCALL variable after the above line. Choose the definition that
     matches your SQR and Oracle versions.

     SQR   Oracle			SQRCALL defintion							

     2.5.x   6 	SQRCALL=$(SQRLIB)/dbcalxl6.o $(SQRLIB)/sqr.a

     2.5.x   7	SQRCALL=$(SQRLIB)/dbcalxl7.o $(SQRLIB)/sqr.a

     3.0.x   6	SQRCALL=$(SQRLIB)/dbcalxl6.o $(SQRLIB)/sqrv6.0 $(SQRLIB)/sqr.a \
                $(SQRLIB)/bcl.a $(SQRLIB)/libsti.a

     3.0.x   7 	SQRCALL=$(SQRLIB)/dbcalxl7.o $(SQRLIB)/sqrv7.0 $(SQRLIB)/sqr.a \
                $(SQRLIB)/bcl.a $(SQRLIB)/libsti.a

     Change the sqlforms30x/runform30x make portion of the sqlforms30.mk file
     to include $(SQRCALL) after $(IAPXIT), and -lm after $(CLIBS).
	
      Before:
      sqlforms30x: $(IAPXIT)
                   @$(ECHO) $(CC) $(LDFLAGS) -o $& ... $(IAPXIT) ...\
                   ... \
                   ... $(CLIBS)

                   @$(ECHO) $(CC) $(LDFLAGS) -o runform30x ... $(IAPXIT) ...\
                   ... \
                   ... $(CLIBS)

      After:
      sqlforms30x: $(IAPXIT)
                   @$(ECHO) $(CC) $(LDFLAGS) -o $& ... $(IAPXIT) $(SQRCALL) ...\
                   ... \
                   ... $(CLIBS) -lm

           @$(ECHO) $(CC) $(LDFLAGS) -o runform30x ... $(IAPXIT) $(SQRCALL) ...\
                   ... \
                   ... $(CLIBS) -lm

6) Create both the sqlforms30x executable and the runform30x executable with
   the folowing command:

	$ make -f sqlforms30.mk sqlforms30x

7) In order to use the user exit, you need to create a form using sqlforms30x,
   and use the package procedure USER_EXIT to run the SQR program.
   For example:

          In KEY-COMMIT trigger:

	user_exit('sqrexit test.sqr -eout.err -xc');

     Compile the form with the following command:

   	$ iag30 -ot formname username/password

8) Run the form with the new runform30x executable.

	$ runform30x formname username/password

9) A version of ucall.c (called ucallfrm.pc) includes an SQR CALL routine
   named PUTFORM for copying data back to SQL*FORMS from SQR. Should you want
   to use PUTFORM, copy ucallfrm.pc and precompile using PROC.

	$ cp $SQRLIB/ucallfrm.pc ucallfrm.pc
	$ proc iname=ucallfrm.pc ireclen=132 oreclen=132

     Compile the resulting C program.

	$ cc -c ucallfrm.c

     The SQRCALL line in sqlforms30.mk (step 5) becomes:
			
     SQR    Oracle			SQRCALL defintion							

     2.5.x    6      SQRCALL=$(SQRLIB)/dbcalxl6.o ucallfrm.o $(SQRLIB)/sqr.a

     2.5.x    7      SQRCALL=$(SQRLIB)/dbcalxl7.o ucallfrm.o $(SQRLIB)/sqr.a

     3.0.x    6      SQRCALL=$(SQRLIB)/dbcalxl6.o ucallfrm.o $(SQRLIB)/sqrv6.0 \
                     $(SQRLIB)/sqr.a $(SQRLIB)/bcl.a $(SQRLIB)/libsti.a

     3.0.x    7      SQRCALL=$(SQRLIB)/dbcalxl7.o ucallfrm.o $(SQRLIB)/sqrv7.0 \
                     $(SQRLIB)/sqr.a $(SQRLIB)/bcl.a $(SQRLIB)/libsti.a

     Relink the sqlforms30x and runforms30x executables as described in step 6.

     The SQR command for placing data back on the form is:

	CALL PUTFORM USING {block.field} {$var}

     Where block.field is the name of the field in SQL*FORMS you want to
     replace. The value to replace must be a string variable. For example:

	CALL PUTFORM USING 'reports.rows' $rows-processed

		-----------------------------------------

   Calling SQR from Oracle SQL*FORMS 3.0 with the host command on unix

1) In order to use the host command, you need to create a form using sqlforms30,
   and use the package procedure HOST to run the SQR program. For example:

          In KEY-COMMIT trigger:

	host('sqr test.sqr -eout.err');

     Compile the form with the following command:

   	$ iag30 -ot form_name user/password

2) Run the form with the runform30 executable.

	$ runform30 formname username/password