Problem:
Problems encountered while using C routines to access the Micro Focus filehandler using the EXTFH API
Resolution:
Debugging a C language calls to EXTFH
The API for calling the Micro Focus filehandler is well documented and it's possible to create C language applications which use the Micro Focus filehandler to access and update COBOL data files. The interface to the filehandler consists of a call to the function EXTFH which passes two arguments, 1) a pointer to the Operation Code and 2) a pointer to a Micro Focus File Control Descriptor (FCD). When the interface between your C language routine and the filehandler fails the problem is frequently caused by a errors in the contents of one or both of these arguments.
There is a fairly straight forward means available to debug and troubleshoot the interaction between your C language application and the Micro Focus filehandler,
Create a COBOL program that contains a Linkage Section and Procedure Division which accepts two items (The opcode and the pointer to the FCD). This code would look something like this:
*DebugStub.cbl
LINKAGE SECTION.
01
FCD.
COPY "XFHFCD.cpy".
* The copybook XFHFCD.cpy can be found in the cpylib subdirectory of the Server * * * Express product.
01
OP-CODE.
03 OP-CODE-PART-1 PIC X.
03 OP-CODE-PART-2 PIC X.
PROCEDURE DIVISION USING OP-CODE FCD.
START-1.
CALL "EXTFH" using OP-CODE, FCD.
EXIT PROGRAM.
STOP RUN.
Now modify the C language program to call this COBOL program instead of EXTFH. In this example we would change all of the calls to EXTFH in the C applications to calls to DebugStub. For example:
Original CALL to EXTFH
EXTFH(action, &fcd);
Change for debugging to:
DebugStub(action, &fcd);
As you can see this is a fairly trivial modification, which could be implemented using the C language #ifdef operator so that when debugging is needed you could simply recompile the application for troubleshooting.
When compiling, and linking your C language application use the 'cob' command and specify -d [program-name] (where program-name is the name of this little COBOL stub program.) . If the C application is named demo1main.c and the COBOL program is named DebugStub.cbl the compilation commands needed would look like the following:
cob -iav DebugStub.cbl
cob -xv -d DebugStub demo1main.c
To execute your C language application and debug the filehandler interface, set the COBSW environment variable equal A and then execute the application. For Example:
./demo1main
The C language application will execute at full speed until a call to DebugStub is encountered, at that point the Micro Focus Animator screen will appear and you can use the QUERY capability, both before and after the call to EXTFH, to look at or even modify either the Operation Code or the contents of the FCD.
DebugStub.cbl can be enahanced to provide the ability to work with the record contents and or the Key Definitions (For Indexed file) by adding Definitions for these items to DebugStub.cbl and setting the Addresses of these items using the pointers that are passed in the FCD. Refer to the accompanying example code.
Attachments:
#COBOL
#AcuCobol
#ServerExpress
#RMCOBOL
#netexpress