COBOL Define Your Own File Handler



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.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值