The %NOTFOUND attribute is used to exit a loop during a FETCH operation. When the value of the %NOTFOUND attribute is evaluated to TRUE, the loop will exit. However, you should also note that the value of the %NOTFOUND attribute is evaluated to NULL before the first FETCH operation is executed. Therefore, if the first fetch is not successful, the %NOTFOUND attribute remains NULL and the loop will not exit. To prevent this situation, you should check the value of the %NOTFOUND variable as NULL to exit the loop, as shown in the following code:
