how do i define the locator for cursor returned by SP

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
Db2hero
Member
Posts: 6
Joined: Fri Apr 10, 2009 9:04 am

how do i define the locator for cursor returned by SP

Post by Db2hero » Fri Apr 10, 2009 9:07 am

HI.
My DB2 stored procedure will return a cursor to calling COBOL program.
How do I defince the host variable to access the cursor?

Thanks.

Db2hero
Member
Posts: 6
Joined: Fri Apr 10, 2009 9:04 am

Post by Db2hero » Fri Apr 10, 2009 9:33 am

EXEC SQL CONNECT TO SITE2; EXEC SQL CALL MYSCHEMA.P1; EXEC SQL ASSOCIATE RESULT SET LOCATORS (:LOC1, :LOC2) WITH PROCEDURE MYSCHEMA.P1;

I need to know how :LOC1 and :LOC2 is defined in the working storage.
Any help will be greatly appreciated.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

cobol db2 stored procedure

Post by Natarajan » Fri Apr 10, 2009 2:54 pm

Here is some example to call db2 stored procedure from cobol program

Code: Select all

EXEC SQL
 01 LOC1 SQL TYPE IS RESULT-SET-LOCATOR VARYING
END-EXEC.

.
.

PROCEDURE DIVISION.

.
.
EXEC SQL 
CALL MYSCHEMA.P1
END-EXEC


EXEC SQL 
ASSOCIATE LOCATOR (:LOC1) WITH PROCEDURE MYSCHEMA.P1; 
END-EXEC.
..
..
EXEC SQL
 ALLOCATE CURSOR1 CURSOR
 FOR RESULT SET :LOC1
END-EXEC.

.
.
FETCH LOC1 INTO :XXX


Natarajan
Chennai

Db2hero
Member
Posts: 6
Joined: Fri Apr 10, 2009 9:04 am

Post by Db2hero » Fri Apr 10, 2009 11:20 pm

Thanks for you reply.

The precompiler does not like 01 in
EXEC SQL
LOC1 SQL TYPE IS RESULT-SET-LOCATOR VARYING
END-EXEC.

so I took it out and it worked. However the ASSOCIATE and ALLOCATE statements expect a host variable. The statements below fails at precompile since :LOC1 is not defined.

EXEC SQL
ASSOCIATE LOCATOR (:LOC1) WITH PROCEDURE MYSCHEMA.P1;
END-EXEC.
..
..
EXEC SQL
ALLOCATE CURSOR1 CURSOR
FOR RESULT SET :LOC1
END-EXEC.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others