IBM removed the positioning issue with Declare Cursors a while ago.
I know it is no longer an issue in V7R1 and above.
Even then, the old issue was that all Declares for Cursors must be "found" in the source prior to the Open/Fetch/Close/Execute statements.
I've created a number of sub procedures that contain the declare/open/fetch/close for a cursor.
And I've had the declare entered into a Subroutine of the Sub procedure so that it can be executed multiple times if needed.
I've also created a single sub procedure to contains all Declares for a program. So I know that method works as well.
So if you are on v7r1, then whatever issue you are having probably has to do with how you are defining your data structures.
A lot of the time this has to do with trying to use newer definitions like "Extname(FILENAME:*INPUT)".
SQL-RPG is a little behind RPG, so it can only interpret data structures without the second part of the Extname. And it doesn't like "Template" at all.
Dcl-ds InDS Likeds(Filename) Qualified End-ds;
I've also seen instances where the issue is actually some other RPG complier error and the pre-compiler just can't get past it.
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Alan McKenzie
Sent: Thursday, May 11, 2017 5:08 AM
To: RPG/400 Discussions <rpg400-l@xxxxxxxxxxxx>
Subject: SQL Data Structure is Procedures and not in Main section - compilation unsuccessful
Hi,
I recently wrote a program that uses SQL to process all tables/files. The program has a very short main section, 4 statements, followed by all the Procedures. When compiling the program I am getting an horrendous number of errors, all associated with SQL. If I change the program to use Sub-routines instead of the Procedures, the compilation completes successfully.
Initially I thought that possibly the SQL Communication Area (SQLCA data structure) may not have been created in the correct section, but that is not the case. It appears that FETCH, SELECT, OPEN data structures are in the certain Procedures and can't be accessed from other procedures.
I can supply both compilation reports if required to assist.
Has anyone had a similar issue and could make some suggestions to remedy the situation.
Regards,
Alan McKenzie
XA Consultant
CBI electric Telecom Cables (Pty) Ltd.
Registration Number: 1967/005978/07
Office: +27 12 381 1405 | Switchboard: +27 12 381 1400
Mobile: +27 (0) 82 453 7990
E-mail: AMcKenzie@xxxxxxxxxxx<mailto:AMcKenzie@xxxxxxxxxxx>
NOTE:- This e-mail message and all attachments hereto contain confidential information intended for specific addressee and purpose. If you are not the addressee:
(a) You may not disclose, copy, distribute or take any action based on the contents hereof.
(b) Kindly inform the sender immediately and destroy all copies thereof.
(c) Any discloser, copying, distribution or any action taken or omitted in reliance on it, is prohibited and may be unlawful.
The views and opinions expressed in this e-mail message may not necessarily be those of the management of the company.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://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:
http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.