× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I am sorry but but the code above is absolutely horrible code. You must
error check everything in SQL. What happens in the code above when you have
an error?

Exec Sql Declare CursorABC Cursor For
Select ABC1,
ABC2
From ABCFILE;

Exec Sql Declare CursorDEF Cusror For
Select DEF1,
DEF2
From DEFFILE;

Exec Sql Open CursorABC;
If SqlState <> SQL_STATE_OK; // '00000'
// Log error, stop processing.
EndIf;

DoW TRUE; // Outer Loop
Exec Sql Fetch Next
From CursorABC
Into :dsRecordInABC;
Select;
When SqlState = SQL_STATE_NO_ROW; // '02000'
Exec SQL Close CursorABC;
Leave;
When SqlState = SQL_STATE_OK;
// Process inner loop;
Exec Sql Open CursorDEF;
If SqlState <> SQL_STATE_OK;
// Log error, stop processing
EndIf;
DoW TRUE;
Fetch Next
From CursorDEF
Into :dsRecordInDEF;
Select;
When SqlState = SQL_STATE_NO_ROW;
Exec Sql Close CursorDEF;
Leave;
When SqlState = SQL_STATE_OK;
// Process DEF record
Other;
// Log error, stop processing.
EndSl;
EndDo;
Other;
// Log Error. Stop processing.
EndSl;
EndDo;

In any case, it is extremely important to check for errors. SQL will not
stop if an error occurs!!

I use a standard error logger that I call after each SQL statement except
Declare and Close. Logs the error and terminates processing.

I just cannot emphasize enough how important it is to error each SQL
statement. Setting up loops and breaking if non-zero just does not cut it.



On Thu, Apr 18, 2019 at 1:45 PM B Stone <bvstone@xxxxxxxxx> wrote:

On Thu, Apr 18, 2019 at 3:39 PM Michael Schutte <mschutte369@xxxxxxxxx>
wrote:

The positioning of your fetch is important.
When you get to the bottom EndDo and go back to the top, the SQLCODE
being
checked with be from your c2 fetch, not the c1. So you may exit out
prematurely.

Personally, I do primary fetches with my next fetch right before the end.

fetch c1
Dow sqlcode = 0
open c2
fetch c2
dow sqlcode = 0
fetch c2
enddo
close c2
fetch c1
enddo


^^^^^^^^^^^^^

This is why priming reads are a good habit.


Bradley V. Stone
www.bvstools.com
MAILTOOL Benefit #6 <https://www.bvstools.com/mailtool.html>: Easily send
group emails with Distribution Lists
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.