title: What's the correct way to check sql found condition in ILE RPG?
body: <p>When working with embedded SQL in RPG, you often end up with a cursor and a <code>dow</code>-loop for processing all rows in your result. The condition in the loop is somehow dependent on <code>SQLCOD</code> and/or <code>SQLSTT</code>, some globally available variables in an SQLRPGLE-program?</p>
  
  <p>But what is the correct way of checking these values? Some suggest <code>SQLCOD = 0</code> others <code>not (SQLCOD = +100 or SQLSTT = '02000')</code>. One fails on all warnings, the other does not fail on some errors, so I'm not content.</p>
  
  <p>To illustrate what I do with some code:</p>
  
  <pre><code>Pmain             B
  D                 PI
  Dmy_ds          E DS                  extname(SOME_TABLE)
  D                                     qualified
   /free
    exec sql
      DECLARE cur CURSOR FOR
        SELECT *
        FROM some_table;
    exec sql 
      OPEN cur;
    exec sql
      FETCH cur
       INTO :my_ds;
    dow sql_found();
        exec sql
          FETCH cur
           INTO :my_ds;
    enddo;
    exec sql
      CLOSE cur;
   /end-free
  Pmain             E
  
  
  Psql_found        B
  D                 PI              N
   /free
    // insert return statement here...
   /end-free
  Psql_found        E
  </code></pre>
  
  <p>I'm looking for the correct return statement here, that will make me go through all rows if no error occurs and lets me leave when an error occurs. Bonus points for some decent way to check for errors.</p>