home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l360 / 3.ddi / STATUS.@BL / STATUS.CBL
Encoding:
Text File  |  1991-04-08  |  2.6 KB  |  68 lines

  1.       $set mf noosvs ans85
  2.       *****************************************************************
  3.       *                                                               *
  4.       *              (C) Micro Focus Ltd. 1989                        *
  5.       *                                                               *
  6.       *                     STATUS.CBL                                *
  7.       *                                                               *
  8.       * This program demonstrates how to interpret values returned    *
  9.       * in the second of the two status bytes.  Status bytes are set  *
  10.       * up after EVERY file operation (assuming that you have declared*
  11.       * them in the select clause) and it is important to check the   *
  12.       * values returned after every operation.  This program shows how*
  13.       * to do this.                                                   *
  14.       *                                                               *
  15.       * The program tries to open and close a file called INPUT.FIL.  *
  16.       * If the operations fail it displays the corresponding file     *
  17.       * status bytes                                                  *
  18.       *                                                               *
  19.       *****************************************************************
  20.  
  21.        identification division.
  22.        program-id.    check-file-status.
  23.  
  24.        select input-file assign "input.fil"
  25.        organization sequential
  26.        status stat.
  27.  
  28.        fd input-file.
  29.        01 input-record pic x(80).
  30.  
  31.        working-storage section.
  32.  
  33.       * define status bytes and redefinition as follows
  34.       * (note that the picture clauses are important)
  35.        01 stat.
  36.            03 s1   pic x.
  37.            03 s2   pic x.
  38.            03 s2-bin redefines s2
  39.                    pic 9(2) comp-x.
  40.  
  41.       * have a display item too.
  42.        01 stat-display.
  43.            03 s1-display pic x.
  44.            03 filler     pic x.
  45.            03 s2-display pic 9(3).
  46.  
  47.        procedure division.
  48.            open input input-file.
  49.            perform check-status.
  50.  
  51.            close input-file.
  52.            perform check-status.
  53.  
  54.            stop run.
  55.  
  56.        check-status.
  57.       * a value of "00" indicates a successful operation
  58.            if stat not = "00" then
  59.                move s1 to s1-display
  60.                if s1 = "9" then
  61.                    move s2-bin to s2-display
  62.                else
  63.                    move s2 to s2-display
  64.                end-if
  65.                display "operation fails - current status = "
  66.                        stat-display
  67.            end-if.
  68.