3. Embedded QUEL for COBOL : Precompiling, Compiling, and Linking an EQUEL Program : Incorporating Ingres into the Micro Focus RTS—UNIX : Procedure 2
 
Share this page                  
Procedure 2
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 step forces the external object to be loaded into your RTS and allows access to it through your EQUEL/COBOL program.Build and compile the form or forms in VIFRED.
When you compile a form in VIFRED, you are prompted for the name of the file, and VIFRED then creates the file in your directory describing the form in C.
1. Compile the C file into object code:
$ cc -c formfile.cWrite a small EQUEL/C procedure that just references and initializes the form(s) 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.
For example:
add_form1()

## extern int   *form1;
## ADDFORM form1
}  
add_form2()  

## extern int   *form2;
## ADDFORM form2
}Build the object code for the initialization of the compiled form(s):
$ eqc filename.qc
$ cc -c filename.c
where filename.qc is the name of the file containing the procedure written in Step 3.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 object code file resulting from Step 4, containing the initialization references to the forms "form1" and "form2."
2. 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:
## ADDFORM form1
becomes:
CALL "add_form1".
To illustrate this procedure, assume you have compiled two forms in VIFRED, "empform" and "deptform," and need to be able to access them from your EQUEL/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
Now create an EQUEL/C file, "addforms.qc", that includes a procedure (or two) that initializes each one using the addform statement:
add_empform()

## extern int *empform;
## ADDFORM empform 
}

add_deptform()

## extern int *deptform;
## ADDFORM deptform
}
Now build the object code for the initialization of these 2 compiled forms:
$ eqc addforms.qc
$ cc -c addforms.c
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 \
        ...
Finally, be sure to replace the appropriate addform statements in your source code with COBOL CALL statements.
Note, of course, that you may store all your compiled forms in an archive library that will not require the constant modification of a link script. The sample applications (see Sample Applications) were built using such a method that included a single file, "addforms.qc", and an archive library, "compforms.a", that included all the compiled forms referenced in the sample applications.
If, at a later time you are able to reference EXTERNAL data items directly from your COBOL source code, then the intermediate step of creating an EQUEL/C addform procedure can be skipped, and your compiled form is declared as an EXTERNAL PIC S9(9) COMP-5 data-item in your EQUEL/COBOL source code:
##  01   empform IS EXTERNAL PIC S9(9) USAGE COMP-5.
         ... 
##       ADDFORM empform
The external object code for each form must still be linked into the RTS but there is no need to write an EQUEL/C intermediate file, or call an external C procedure to initialize the compiled form for you.