Sebastien:
I have to disagree, the generated ESQL/C is producing the same result but that is because the generated code is faulty. Just look at and test the version that I sent you.
The generated code never fetches after the second OPEN but only after the third one. It works when you do not set OPTOFC because the FETCH after the third OPEN, the one without a USING clause, fetches the data from the second OPEN. That third OPEN just silently fails which is a bug in itself, but has nothing to do with the code not working when you set OPTOFC.
Here is what is actually happening: Remember that OPTOFC defers the OPEN until the FETCH and automatically closes the cursor when the last row is fetched. In the generated code, since there is not FETCH immediately after the OPEN the open is queued in the local library's memory but not executed. Then the third OPEN executes with not USING so it is completely ignored (I agree that it should generate an error) and probably clears the scheduled OPEN from the second OPEN call. Then the FETCH that follows the third OPEN also silently fails and the target host variables simply have retained their values from the first successful fetch.
When you comment out the first OPEN and FETCH, there is no data in the target host variables so you finally get an error.
In the correctly built code I send, where there is a second FETCH, the results are correct regardless of OPTOFC and regardless of whether you comment out the first fetch.
Now, not returning errors when the third OPEN is presented on top of the second one with no fetch? Maybe when OPTOFC is NOT set. It should not like either the back-to-back OPENs nor that the third OPEN does not present a value to use. On the other hand, if you OPEN a cursor again without first issuing a CLOSE, that is not an error and the OPEN executes a CLOSE internally first, so maybe not an error. In the OPTOFC case, I think not an ESQL compiler or engine bug but rather that the second OPEN was just NO-OP because of how OPTOFC works.
Nope, I maintain that the ONLY problem is the C4GL V7.51 compiler that has generated bad ESQL/C code (the 7.50 compiler gets it correct. I would like to see JC or Jonathan Leffler chime in on this one.