Call the Callable File Handler and Check the File Status

Add the following sections to include a generic call to the callable file handler; that way, you can perform this section a number of times to execute a number of different operations, depending on the value of opcode. It is also good practice to code a section that checks the file status after each file operation, in case there are problems accessing the intended file.
  1. In the procedure division, paste the following code:
               call-file-handler section.
               call "EXTFH" using opcode, fcd
               .

    This section will be performed a number of times during the demonstration, each time to perform a different operation.

  2. Beneath the previous section, paste the following code:
               display-file-status section.
               if fcd-status-key-1 = "9"
                  display "file-status = " fcd-status-key-1 "/" fcd-binary
               else
                  display "file-status = " fcd-status-key-1 "/" fcd-status-key-2
               end-if
               .

    After each operation, this section will be performed to check that the operation was successful.

Now that the working storage has been defined, and you have the code in place to call the file handler, you can create a file and start performing file handling operations on it.