Topic
1 reply Latest Post - ‏2013-06-12T21:13:26Z by BillWoodger
NealB
NealB
3 Posts
ACCEPTED ANSWER

Pinned topic User Exits for Enterprise COBOL written in COBOL

‏2013-06-12T20:42:26Z |

I am trying to write a compiler exit in COBOL. The basic pattern for
this routine comes from:INEXIT example.

To this I have added a file to read the COBOL source deck:

       Input-Output Section.
       FILE-CONTROL.
           SELECT COBSRC ASSIGN COBSRC
                  ORGANIZATION SEQUENTIAL
                  ACCESS       SEQUENTIAL
                  FILE STATUS  COBSRC-STATUS.
       Data Division.
       FILE SECTION.
       FD COBSRC IS EXTERNAL
           RECORDING MODE F
           BLOCK CONTAINS 0 CHARACTERS.
       01                      Pic X(80).

and modified the EXIT-Open/Get paragraphs as follows:

       INEXIT-Open.
           SET COBSRC-STATUS-NORMAL TO TRUE
           OPEN INPUT COBSRC
           IF COBSRC-STATUS-NORMAL
              Move zero to Exit-ReturnCode
           ELSE
              Move 16 to Exit-ReturnCode
              DISPLAY 'Open BAD I/O: ' COBSRC-STATUS
           END-IF
           GOBACK
           .
       INEXIT-Get.
           SET COBSRC-STATUS-NORMAL TO TRUE
           Read COBSRC into Record-Variable
           EVALUATE TRUE
              WHEN COBSRC-STATUS-NORMAL   ; PERFORM TRANSLATE-TOKEN
              WHEN COBSRC-STATUS-EOF      ; PERFORM COBSRC-EOF
              WHEN OTHER
                   Move 16 to Exit-ReturnCode
                   DISPLAY 'Get BAD I/O: ' COBSRC-STATUS
           END-EVALUATE
           GOBACK
           .

The problem I have at the moment is keeping the source file open between
invocations of this routine. Actually, I think the file is open but I am
loosing the file handle between calls.

When the compiler invokes my INEXIT routine with an OPEN request the
EXIT-Inopen paragraph is performed and the source file is successfully opened.

Next the compiler comes back with a GET request but the file read in
INEXIT-Get fails with a '47' file status (attempt to read a closed file). The
INEXIT routine was not coded with INITIAL so I would have expected the
WORKING-STORAGE and FD's to have remained in their last used state between
calls.

After playing around a bit, it became clear to me that my INEXIT routine is
entered in its INITIAL state on every call. That would explain getting a '47'
file status on subsequent calls. Next I tried declaring the FD as EXTERNAL
in the hopes that its contents (and file state) would be preserved between
calls. No luck, even EXTERNALs appear to be re-initialized.

A return area is provided in the exit handler linkage to hold the adderss of
GETMAINed memory. This is to support for reentrancy. The appropriate "slot"
in the example code would be INEXIT-Slot of EXIT-Workarea. I suppose if I
could get my file handle allocated in heap memory and save its address in
INEXIT-Slot it might solve the problem.

Can someone tell me if this approach would work, and if so, how do I get the
file handle established in heap memory in COBOL - then get its address? Or,
is there a completely different approach that would work?

 

Updated on 2013-06-12T21:03:17Z at 2013-06-12T21:03:17Z by NealB
  • BillWoodger
    BillWoodger
    83 Posts
    ACCEPTED ANSWER

    Re: User Exits for Enterprise COBOL written in COBOL

    ‏2013-06-12T21:13:26Z  in response to NealB

    I think your program is being loaded from DASD each time it is called. It will look like IS INITIAL.

    There is a suggestion in the one sample program in the Programming Guide that the "compile performance" is enhanced by the method described (establishing a reusable runtime environment for COBOL), which I think will sort out your problem. p736 of the Programming Guide for 4.2.