Menu

THE MIDNIGHT CODE REVIEW / CASE 02

The cursor that
quit early.

Five orders. One missing promotion. A loop meant to process them all.
Follow the SQLRPGLE program to its next iteration.

SQLRPGLE · SQLCODAbout two minutesNo login. No timer.
cursor.sqlrpgleLOOP EXCERPT

The SQLRPGLE loop under review

dou SQLCOD = 100;
  exec sql fetch next from C1 into :orderId, :promoCode;

  if SQLCOD = 100;
    leave;
  elseif SQLCOD <> 0;
    // Report unexpected FETCH status, then stop.
    leave;
  endif;

  discount = 0;
  exec sql select DISCOUNT into :discount
    from EOICURSOR.PROMOS
    where PROMO_CODE = :promoCode;

  if SQLCOD = 100;
    discount = 0;  // Missing optional promotion is allowed.
  elseif SQLCOD <> 0;
    // Report unexpected lookup status, then stop.
    leave;
  endif;

  processed += 1;
  // Display this order. No further SQL before ENDDO.
enddo;
The full program includes declarations, checked OPEN and CLOSE, and saved statement diagnostics. This excerpt follows the same five-order path.
What does the program process before leaving the loop?
A nudge, without the answer

DOU tests its condition at the bottom. Which SQL statement most recently set SQLCOD when order 2 reaches ENDDO?