DB2 embedded SQL in RPGLE
<p>Lets assume we have this query:</p>

<pre><code>SELECT T1.*, T2.* INTO :DS1, :DS2 FROM FILE1 AS T1
LEFT JOIN FILE2 AS T2 ON T1.KEY = T2.KEY
FETCH FIRST 1 ROW ONLY
</code></pre>

<p>Everything comes up okay if both records are found. But what happens if FILE2 record is not present?</p>

<pre><code>SQLCOD -305 THE NULL VALUE CANNOT BE ASSIGNED TO OUTPUT HOST VARIABLE
</code></pre>

<p>And even if the record from FILE1 is found, both DS are empty! That's a problem.<br>
A way to overcome this is to use <code>COALESCE</code> on every field, but what if I've got hundreds of them?!<br>
Another way is to use two distinct queries. But that's ugly if I want a cursor.</p>

<p>Is there a better way?</p>