title: Find a substring in a string in COBOL
body: <p>My problem is, given a variable which I read from a file, see if it contains or matches another string.</p>
  
  <p>In other words, find in a file all the records whose variable </p>
  
  <blockquote>
    <p>BRADD PIC X(30)</p>
  </blockquote>
  
  <p>matches or contains a string introduced by keyboard.</p>
  
  <p>I'm very confident this problem is resolved through the INSPECT instruction, and I've tried something like this in my code:</p>
  
  <pre><code>           READ BRANCHFILE NEXT RECORD 
               AT END SET EndOfFile TO TRUE
             END-READ.
             PERFORM UNTIL EndOfFile
                 INSPECT BBRADD 
                   TALLYING CONT for CHARACTERS
                     BEFORE INITIAL CITY
                 IF CONT&gt;1
                     DISPLAY " BRANCH CODE    :" BBRID
                     DISPLAY " BRANCH NAME    :" BBRNAME
                     DISPLAY " BRANCH ADDRESS :" BBRADD
                     DISPLAY " PHONE          :" BBRPH
                     DISPLAY " E-MAIL         :" BEMAIL
                     DISPLAY " MANAGER NAME   :" BMGRNAME
                     DISPLAY " ------------------"
                     DISPLAY " ------------------"
                 END-IF
                 READ BRANCHFILE NEXT RECORD 
                     AT END SET EndOfFile TO TRUE
                 END-READ
                 MOVE 0 TO CONT
             END-PERFORM.
  </code></pre>
  
  <p>Where CITY is the variable I introduce through keyboard.</p>
  
  <p>¿Anyone knows how to find a "substring" in a "string"?</p>
  
  <p>For example, if I introduced "Zaragoza" my program have to print all the records in the file which variable BBRADD contains "Zaragoza". </p>
  
  <pre><code>01 BRANCHREC. 
     88 EndOfFile VALUE HIGH-VALUE. 
     02 BBRID PIC X(6). 
     02 BBRNAME PIC X(15). 
     02 BBRADD PIC X(30). 
     02 BBRPH PIC X(10). 
     02 BEMAIL PIC X(20). 
     02 BMGRNAME PIC X(25). 
  </code></pre>