What's User Defined File Handler
Customers can build some kind of their own file handler, inner the handler you can change default operation behavior. For example you can change “OUTPUT” mode to “EXTEND” mode when some criteria matched.
How to Implement a File Handler
File handler can be written in COBOL or C, or else, if you like, but COBOL is preferred, because it’s more convenient, and our caller programs are written in COBOL either.
File handler is nothing but a general COBOL program with specific parameters, it should be compiled into a .gnt/or .so file using compiler.
An File Handle Sample
This sample is trying to change “OUTPUT” open-mode to “EXTEND” open-mode for all line sequential and sequential dataset, and forward all other dataset operation to default handler, i.e, “EXTFH”.
1 IDENTIFICATION DIVISION. 2 PROGRAM-ID. MYEXTFH. 3 DATA DIVISION. 4 WORKING-STORAGE SECTION. 5 6 LINKAGE SECTION. 7 01 Action-Code. 8 03 Action-Type PIC X(01). 9 03 Cobol-Op PIC X(01). 10 78 Open-Output value x'01'. 11 78 Open-Extend value x'03'. 12 01 FCD-Area. 13 COPY "XFHFCD.CPY". 14 01 FILE-DD-NAME PIC X ANY LENGTH. 15 16 PROCEDURE DIVISION USING Action-Code FCD-Area. 17 DISPLAY "IN MY FILE HANDLER". 18 IF Cobol-Op = Open-Output 19 AND (FCD-Organization = 0 OR *> Line sequential 20 FCD-Organization = 1 ) *> Sequential 21 22 SET ADDRESS OF FILE-DD-NAME TO FCD-FILENAME-ADDRESS 23 DISPLAY "DD=" FILE-DD-NAME(1:FCD-Name-Length) 24 25 MOVE Open-Extend TO Cobol-Op 26 END-IF. 27 28 CALL "EXTFH" USING ACTION-CODE FCD-AREA. 29 EXIT PROGRAM. 30
How to use a File Handler
The only thing we have to do is notifying caller that there is a new handler, please call me; this is implemented by add compiling option CALLFH(“HANDLENAME”) for Micro Focus compiler and xxx-extfh=HANDLENAME, and xxx-extfh-lib="HANDLELIBNAME" for COBOL-IT compiler (xxx can be isam or flat) while compiling caller application programs.