title: DB2 LUW version 10.5.0.10 - Get Warning (Not found) Line in Stored Procedure
body: <p>I'm trying to determine the line in a stored procedure or the last SQL-statement which is causing a warning / not found. As a workaround I'm using temporary variables which I manually set to determine in which part of my stored procedure a warning occurs.</p>
  <pre><code>-- Create an ErrorLog table
  Create Table SCHEMA.ErrorLog_lrc_test                                                        
    (                                 
     ErrSQLCODE     Integer ,                                   
     Codepart    Char(1),                             
     Type           Char(1) ,                                  
     MsgText        VarChar(1024));
  
  CREATE OR REPLACE PROCEDURE SCHEMA.test_warning(IN divisor INT)
  LANGUAGE SQL
  BEGIN
  -- Define variables
  DECLARE codepart_var Char(1);
  
  DECLARE test_INT INT;
  
  -- Define sqlcode
  DECLARE SQLCODE INTEGER;
         
  --Define Warning-Handler
  DECLARE CONTINUE HANDLER FOR SQLWARNING, NOT FOUND 
      BEGIN 
      INSERT INTO SCHEMA.ErrorLog_lrc_test(ErrSQLCODE, Codepart, TYPE, MsgText) 
          VALUES(SQLCODE, codepart_var, 'W', SYSPROC.SQLERRM(SQLCODE));
      END;
   
  -- Set temporary variable to 'a' to get part of code where warning occured
  SET codepart_var = 'a';
  
  -- Create Not Found (Sqlcode 100)
  INSERT INTO SCHEMA.ErrorLog_lrc_test
  SELECT NULL, NULL, NULL, NULL FROM &quot;SYSIBM&quot;.SYSDUMMY1
  WHERE 1 = 0 ;
  
  END 
  
  call SCHEMA.test_warning(0);
  
  SELECT *
  FROM SCHEMA.ErrorLog_lrc_test;
  </code></pre>
  <p>I get the following:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ERRSQLCODE</th>
  <th>CODEPART</th>
  <th>TYPE</th>
  <th>MSGTEXT</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>100</td>
  <td>a</td>
  <td>W</td>
  <td>SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I know that for errors there is a function DBMS_UTILITY.FORMAT_ERROR_BACKTRACE that you can use for tracing errors. Unfortunately that function doesn't trace warnings. Also there is a function DBMS_UTILITY.FORMAT_CALL_STACK, but this doesn't work neither.</p>
  <p>Is there another/better way to log the specific line or SQL-statement in a stored procedure which is causing a warning / not found?</p>