Skip to main content

How to call a new callable file handler from COBOL

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

There is an own callable file handler available and have built it as a DLL.

Trying to work out how to get a COBOL program to use it?

Resolution:

If there is a callable file handler available, the need to do is to recompile the programs with the CALLFH directive:

    CALLFH (myhandler)

It is as simple as that.

By default, programs are compiled with CALLFH (EXTFH).  So any I/O sentences are compiled to calls to "EXTFH".  EXTFH is well documented in the help as it can be called explicitly within your programs.

Considering to compile the programs with CALLFH (myhandler), then "myhandler" has to be able to resolve the same type of calls that EXTFH is able to resolve, that is why the EXTFH documentation can be very useful.

Another example of an alternative file handler is Fileshare.  To be able to use Fileshare (that allows to access files in other platforms in the network -please check the documentation for more info-) the need to do is to re-compile programs with CALLFH (FHREDIR).  This makes I/O sentences to be compiled into calls to FHREDIR instead of to EXTFH. FHREDIR needs some configuration side files, but that is just part of the way FHREDIR has been designed.  Your own file handler may need this or not depending on your design.

A very simple way of checking how things work is to write a file handler that simply calls EXTFH in turn.  Then animate the program and when the own file handler gets loaded, there is an ability to check the values getting in each parameter by querying them each time it is called.  Obviously, there is also a need to compile with CALLFH (myhandler) even though it is EXTFH the one that it is ultimately doing all the work.

Attached to this article is a very simple demo that shows this.  Please ensure to build the file handler (mfhandler.cbl) before building the sample COBOL program (write.cbl) as it will need the file mfhandler.imp that is generated after building mfhandler.cbl. Once having built both programs, just to animate write.exe and seeing how mfhandler is called for each I/O statement.

Attachments:

customfilehandler.zip

Old KB# 4301

#RMCOBOL
#netexpress
#AcuCobol
#ServerExpress
#COBOL