Skip to main content

C$REDIRECT HANDLER-FILE-HANDLE

  • July 14, 2011
  • 2 replies
  • 0 views

[Migrated content. Thread originally posted on 14 July 2011]

Hi, i use the C$REDIRECT function in HANDLER-FUNCTION-REPLACE modality. In the handler i want to use the I$IO functions set.

In the handler, the OPEN-FUNC goes well and i move the handler of the open file to the HANDLER-FILE-HANDLE linkage item (i also tried without moving it in the linkage).

When i perform a READ on the file, my custom handler needs to perform the I$IO READ-FUNC but the HANDLER-FILE-HANDLE
points to an invalid location, not to the location of the just open file.

It follows a sample code:

THE I/O OPERATIONS:

open input myfile
move "OP" to myfile-key
read myfile key is myfile-key


THE HANDLER:
procedure division using HANDLER-INFO
                         HANDLER-FILE-INFO
                         HANDLER-STATE-INFO
                         HANDLER-RETURN-STATUS.
       inizio-programma.
           move 100 to werr-tbl-cod(w78err-inner-file-err).

           initialize werr-return-code.
           evaluate true
              when handler-op-open
                 perform open-file thru open-file-ex
              when handler-op-read
              when handler-op-read-lock
                 perform read-file thru read-file-ex
           end-evaluate.

       fine.                                 
           perform set-error-status thru set-error-status-ex.
           if werr-return-code > 0
              move "io" to handler-status-code
           end-if.
           exit program returning werr-return-code.

       open-file.
           evaluate true
              when handler-organization-indexed
                 set open-function to true
                 call "i$io" using io-function
                                   handler-file-name
                                   handler-open-mode
                                   handler-logical-params
                            giving handler-file-handle
                 if handler-file-handle = null
                    move handler-open-mode to w-str
                    string "open " w-str into w-except-params-arr(1)
                    move handler-file-name to w-except-params-arr(2)
                    move w78err-inner-file-err to werr-return-code
                 end-if
           end-evaluate.
       open-file-ex.
           exit.

       read-file.
           evaluate true
              when handler-organization-indexed
                 set read-function to true
                 call "i$io" using io-function
                                   handler-file-handle
                                   handler-record-area
                                   handler-key-number
                            giving werr-return-code
                 if werr-return-code = 0 | se non ha letto nessun byte
                    move "read "           to w-except-params-arr(1)
                    move handler-file-name to w-except-params-arr(2)
                    move w78err-inner-file-err to werr-return-code
                 else
                    initialize werr-return-code
                 end-if
           end-evaluate.
       read-file-ex.
           exit.

2 replies

Stephen Hjerpe
  • Participating Frequently
  • 1100 replies
  • July 14, 2011

[Migrated content. Thread originally posted on 14 July 2011]

Hi, i use the C$REDIRECT function in HANDLER-FUNCTION-REPLACE modality. In the handler i want to use the I$IO functions set.

In the handler, the OPEN-FUNC goes well and i move the handler of the open file to the HANDLER-FILE-HANDLE linkage item (i also tried without moving it in the linkage).

When i perform a READ on the file, my custom handler needs to perform the I$IO READ-FUNC but the HANDLER-FILE-HANDLE
points to an invalid location, not to the location of the just open file.

It follows a sample code:

THE I/O OPERATIONS:

open input myfile
move "OP" to myfile-key
read myfile key is myfile-key


THE HANDLER:
procedure division using HANDLER-INFO
                         HANDLER-FILE-INFO
                         HANDLER-STATE-INFO
                         HANDLER-RETURN-STATUS.
       inizio-programma.
           move 100 to werr-tbl-cod(w78err-inner-file-err).

           initialize werr-return-code.
           evaluate true
              when handler-op-open
                 perform open-file thru open-file-ex
              when handler-op-read
              when handler-op-read-lock
                 perform read-file thru read-file-ex
           end-evaluate.

       fine.                                 
           perform set-error-status thru set-error-status-ex.
           if werr-return-code > 0
              move "io" to handler-status-code
           end-if.
           exit program returning werr-return-code.

       open-file.
           evaluate true
              when handler-organization-indexed
                 set open-function to true
                 call "i$io" using io-function
                                   handler-file-name
                                   handler-open-mode
                                   handler-logical-params
                            giving handler-file-handle
                 if handler-file-handle = null
                    move handler-open-mode to w-str
                    string "open " w-str into w-except-params-arr(1)
                    move handler-file-name to w-except-params-arr(2)
                    move w78err-inner-file-err to werr-return-code
                 end-if
           end-evaluate.
       open-file-ex.
           exit.

       read-file.
           evaluate true
              when handler-organization-indexed
                 set read-function to true
                 call "i$io" using io-function
                                   handler-file-handle
                                   handler-record-area
                                   handler-key-number
                            giving werr-return-code
                 if werr-return-code = 0 | se non ha letto nessun byte
                    move "read "           to w-except-params-arr(1)
                    move handler-file-name to w-except-params-arr(2)
                    move w78err-inner-file-err to werr-return-code
                 else
                    initialize werr-return-code
                 end-if
           end-evaluate.
       read-file-ex.
           exit.

There is a C$REDIRECT example on supportline.microfocus.com/.../GeneralProgTechniques.asp


  • Author
  • Rocketeer
  • 19312 replies
  • July 15, 2011

[Migrated content. Thread originally posted on 14 July 2011]

Hi, i use the C$REDIRECT function in HANDLER-FUNCTION-REPLACE modality. In the handler i want to use the I$IO functions set.

In the handler, the OPEN-FUNC goes well and i move the handler of the open file to the HANDLER-FILE-HANDLE linkage item (i also tried without moving it in the linkage).

When i perform a READ on the file, my custom handler needs to perform the I$IO READ-FUNC but the HANDLER-FILE-HANDLE
points to an invalid location, not to the location of the just open file.

It follows a sample code:

THE I/O OPERATIONS:

open input myfile
move "OP" to myfile-key
read myfile key is myfile-key


THE HANDLER:
procedure division using HANDLER-INFO
                         HANDLER-FILE-INFO
                         HANDLER-STATE-INFO
                         HANDLER-RETURN-STATUS.
       inizio-programma.
           move 100 to werr-tbl-cod(w78err-inner-file-err).

           initialize werr-return-code.
           evaluate true
              when handler-op-open
                 perform open-file thru open-file-ex
              when handler-op-read
              when handler-op-read-lock
                 perform read-file thru read-file-ex
           end-evaluate.

       fine.                                 
           perform set-error-status thru set-error-status-ex.
           if werr-return-code > 0
              move "io" to handler-status-code
           end-if.
           exit program returning werr-return-code.

       open-file.
           evaluate true
              when handler-organization-indexed
                 set open-function to true
                 call "i$io" using io-function
                                   handler-file-name
                                   handler-open-mode
                                   handler-logical-params
                            giving handler-file-handle
                 if handler-file-handle = null
                    move handler-open-mode to w-str
                    string "open " w-str into w-except-params-arr(1)
                    move handler-file-name to w-except-params-arr(2)
                    move w78err-inner-file-err to werr-return-code
                 end-if
           end-evaluate.
       open-file-ex.
           exit.

       read-file.
           evaluate true
              when handler-organization-indexed
                 set read-function to true
                 call "i$io" using io-function
                                   handler-file-handle
                                   handler-record-area
                                   handler-key-number
                            giving werr-return-code
                 if werr-return-code = 0 | se non ha letto nessun byte
                    move "read "           to w-except-params-arr(1)
                    move handler-file-name to w-except-params-arr(2)
                    move w78err-inner-file-err to werr-return-code
                 else
                    initialize werr-return-code
                 end-if
           end-evaluate.
       read-file-ex.
           exit.

The example does not fit my needs. I need to handle any file in handler, not a specific one, then i need to use the I$IO. The problem in using it is explained in my first question.