Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1572

"FILE STATUS" should be checked after IO operations when it is available

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Legacy Key:
      COBOL.FileStatusUsageCheck
    • Covered Languages:
      Cobol
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1h

      Description

      When a FILE STATUS is declared on a file, it should be tested immediately after IO operations.

      Noncompliant Code Example

             IDENTIFICATION DIVISION.
             PROGRAM-ID. foo.
      
             ENVIRONMENT DIVISION.
             INPUT-OUTPUT SECTION.
             FILE-CONTROL.
               SELECT TEST-FILE
                 ASSIGN TO 'foobar.txt'
                 ORGANIZATION IS SEQUENTIAL
                 FILE STATUS WS-TEST-FILE-STATUS.
      
             DATA DIVISION.
             FILE SECTION.
             FD TEST-FILE
               LABEL RECORDS ARE STANDARD.
               01 TEST-RECORD.
               05 USERNAME PIC XX.
      
             WORKING-STORAGE SECTION.
               01 WS-TEST-FILE-STATUS PIC X(42).
      
             PROCEDURE DIVISION.
      
            * Non-Compliant, TEST-FILE has a FILE STATUS variable which must be used
              OPEN INPUT TEST-FILE.
      
             END PROGRAM foo.
      

      Compliant Solution

             IDENTIFICATION DIVISION.
             PROGRAM-ID. foo.
      
             ENVIRONMENT DIVISION.
             INPUT-OUTPUT SECTION.
             FILE-CONTROL.
               SELECT TEST-FILE
                 ASSIGN TO 'foobar.txt'
                 ORGANIZATION IS SEQUENTIAL
                 FILE STATUS WS-TEST-FILE-STATUS.
      
             DATA DIVISION.
             FILE SECTION.
             FD TEST-FILE
               LABEL RECORDS ARE STANDARD.
               01 TEST-RECORD.
               05 USERNAME PIC XX.
      
             WORKING-STORAGE SECTION.
               01 WS-TEST-FILE-STATUS PIC X(42).
      
             PROCEDURE DIVISION.
      
            * Compliant, errors of the IO operation are propery handled
              OPEN INPUT TEST-FILE.
              IF WS-TEST-FILE-STATUS <> "00" THEN
                DISPLAY "Error while opening foobar.txt as input.".
      
             END PROGRAM foo.
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            freddy.mallet Freddy Mallet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: