Absent Member.
Absent Member.
854 views

SQL cursors in Visual COBOL

Jump to solution

Hi,

I'm trying to understand about SQL cursors.

Are cursor names used at run-time i.e. passed to ODBC/SQL engine or just used internally at compile time to associate various EXEC SQL statements.

What I'm wondering is... If a COBOL program, 'A' calls two other programs, 'B' and 'C', alternately, to fetch rows from tables T1 and T2, can programs B and C use the same cursor name i.e. such that both programs have the same-named open cursor?

I'm asking because I'm switching a system from MF native files to MySQL and I'd like to use copybooks of standard procedures. 

Thanks, Linden.

   

Linden Rowland - IT Consultant
Owner/Developer, www.SchoolReportWriter.com
IT Consultant to Tindle Newspaper Group

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Hi Linden,

Cursor names are used internally by the OpenESQL precompiler and do not mean anything at run-time. The actual code generated will be for that of a dynamic SQL statement which will return a result set to the program and bind the columns to the appropriate host variables.

Cursors cannot be shared between programs. All statements that refer to a particular open cursor must be within the same compiled program.

If you declare and open CURSOR1 in prog1 and then call prog2 which declares and opens CURSOR1 these are treated as two distinct cursors.

So once you open a cursor you must perform all of your row fetches within that same program.

Thanks.

View solution in original post

0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert

Hi Linden,

Cursor names are used internally by the OpenESQL precompiler and do not mean anything at run-time. The actual code generated will be for that of a dynamic SQL statement which will return a result set to the program and bind the columns to the appropriate host variables.

Cursors cannot be shared between programs. All statements that refer to a particular open cursor must be within the same compiled program.

If you declare and open CURSOR1 in prog1 and then call prog2 which declares and opens CURSOR1 these are treated as two distinct cursors.

So once you open a cursor you must perform all of your row fetches within that same program.

Thanks.

View solution in original post

0 Likes
Absent Member.
Absent Member.

Thanks Chris. Great! That's what I was hoping.

Linden Rowland - IT Consultant
Owner/Developer, www.SchoolReportWriter.com
IT Consultant to Tindle Newspaper Group

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.