3. Embedded SQL for COBOL : Preprocessor Operation : How to Incorporate Ingres into the Micro Focus RTS—UNIX : How to Include External Compiled Forms in the RTS
 
Share this page                  
How to Include External Compiled Forms in the RTS
The description of how to build an Ingres RTS that can access the Ingres forms system does not include a method with which to include compiled forms into the RTS. Recall that compiled forms are precompiled form objects that do not need to be retrieved from the database. Since the compiled forms are externals objects (in object code) you must link them into your RTS.
Because some UNIX platforms allow you to use the Micro Focus EXTERNAL clause to reference objects linked into your RTS and some do not, two procedures are given here. The first procedure describes how to include external compiled forms in the RTS on a platform that does permit the use of the EXTERNAL clause. The second procedure describes how to perform this task on a platform that does not allow EXTERNAL data items to reference objects linked to the RTS.
Procedure for Platforms that Accept the EXTERNAL Clause
Use this procedure if your platform accepts the EXTERNAL clause to reference objects linked into your RTS.
To include external compiled forms in the RTS
1. Build and compile the form in VIFRED.
When you compile a form in VIFRED, you are prompted for the name of the file, and VIFRED then creates the specified file in your directory, describing the form in C.
2. Compile the C file into object code:
% cc -c formfile.c
3. Link the compiled form(s) into your RTS by modifying the cob command line to include the object files for the forms. List the files before listing the system libraries that will be linked.
For example:
cob -x -e "" -o ingfrs \
        iimfdata.o iimflibq.o iimffrs.o \
        form1.o form2.o \
        ...
Procedure for Platforms that Do Not Accept the EXTERNAL Clause
Use this procedure if your platform does not allow you to use the Micro Focus EXTERNAL clause to reference objects linked into your RTS. The extra steps force the external object to be loaded into your RTS and allow access to it through your ESQL/COBOL program.
To include external compiled forms in the RTS
1. Build and compile the form in VIFRED.
When you compile a form in VIFRED, you are prompted for the name of the file, and VIFRED then creates the specified file in your directory, describing the form in C.
2. Compile the C file into object code:
% cc -c formfile.c
3. Write a small embedded SQL/C procedure that just references the form and initializes it to the Ingres FRS using the addform statement.
Make sure that the name of the procedure follows conventions allowed for externally called names. For example, external names may be restricted to 14 characters on some versions of COBOL.
Example: addform statement usage
EXEC SQL BEGIN DECLARE SECTION;
  extern int *form1;
  extern int *form2;
EXEC SQL END DECLARE SECTION;
 add_form1()
{
EXEC FRS ADDFORM :form1;
}
add_form2()
{
EXEC FRS ADDFORM :form2;
}
4. Build the object code for the initialization of the compiled forms:
% esqlc filename.sc
% cc -c filename.c
where filename.sc is the name of the file containing the procedure written in Step 3.
5. Link the compiled form(s) and the initialization references to the form(s) into your RTS by modifying the cob command line to include the object files for the forms and the procedure. Specify the object files before the list of system libraries.
For example:
cob -x -e "" -o ingfrs \
  iimfdata.o iimflibq.o iimffrs.o \
filename.o form1.o form2.o \
...
where filename.o is the name of the object file resulting from Step 4, containing the initialization references to the forms form1 and form2.
6. Replace the addform statement in your source program with a COBOL CALL statement to the appropriate C initialization procedure. For example, what would have been:
EXEC FRS ADDFORM :form1 END-EXEC.
becomes:
CALL "add_form1".
7. To illustrate this procedure, assume you have compiled two forms in VIFRED, empform and deptform, and need to access them from your embedded SQL/COBOL program without incurring the overhead (or database locks) of the forminit statement. After compiling them into C from VIFRED, turn them into object code:
% cc -c empform.c deptform.c
8. Now create an embedded SQL/C file, for example, addforms.sc, that includes a procedure (or two) that initializes each one using the addform statement:
EXEC SQL BEGIN DECLARE SECTION;
extern int *empform;
extern int *deptform;
 
EXEC SQL END DECLARE SECTION;
 
add_empform()
{
    EXEC FRS ADDFORM :empform;
add_deptform()
{
    EXEC FRS ADDFORM :deptform;
   }
9. Now build the object code for the initialization of these 2 compiled forms:
esqlc addforms.sc
cc -c addforms.c
10. Then link the compiled forms and the initialization references to those forms into your RTS:
cob -x -e "" -o ingfrs \
iimfdata.o iimflibq.o iimffrs.o \
addforms.o empform.o deptform.o \
...
11. Finally, be sure to replace the appropriate addform statements in your source code with COBOL CALL statements.
You can store all your compiled forms in an archive library so that the constant modification of a link script will not be required. The sample programs near the end of this section were built using such a method that included a single file, addforms.sc, and an archive library, compforms.a, that included all the compiled forms referenced in the sample programs.
If, at a later time you are able to directly reference EXTERNAL data items from your COBOL source code then the intermediate step of creating an embedded SQL/C ADDFORM procedure can be skipped, and your compiled forms declared as EXTERNAL PIC S9(9) COMP-5 data-items in your embedded SQL/COBOL source code:
01 empform IS EXTERNAL PIC S9(9) USAGE COMP-5.
...
EXEC FRS ADDFORM :empform END-EXEC.
The external object code for each form must still be linked into the RTS but there is no need to write an embedded SQL/C intermediate file, or call an external C procedure to initialize the compiled form for you.