MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cursor Fetch Issue

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
sri50131
Beginner


Joined: 07 Oct 2004
Posts: 38
Topics: 15

PostPosted: Fri Oct 15, 2004 4:52 pm    Post subject: Cursor Fetch Issue Reply with quote

Hello,

I have an SQL that looks into 2 tables A and B. Based on the condition, the SQL will insert rows of A into B.

When I execute the SQL of my cursor in SPUFI, I get 47 rows that will be inserted into B, which is correct.

When I run my program with the same SQL declared in a cursor, it is looping.

The following is the code that I have in my program.

I have delcared CURSOR1 with "WITH HOLD FOR" option
EXEC SQL
OPEN CURSOR1
END-EXEC.

IF SQLCODE = 0
MOVE 'YES' TO WS-ROWS
PERFORM C210-PROCESS-CURSOR1-DATA THRU
C210-PROCESS-CURSOR1-DATA-EXIT
UNTIL WS-ROWS = 'NO'

In C210-PROCESS-CURSOR1-DATA para, I do the following:

EVALUATE SQLCODE
WHEN 0
PERFORM D210-ADD-DWH-ROWS THRU
D210-ADD-DWH-ROWS-EXIT
WHEN +100
MOVE 'NO' TO WS-ROWS
PERFORM Z005-CLOSE-CURSOR1 THRU
Z005-CLOSE-CURSOR1-EXIT

What is wrong with this code?

I ran the program in Xpeditor and the FETCH CURSOR is going in a loop?

Thanks.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Fri Oct 15, 2004 4:56 pm    Post subject: Reply with quote

sri50131,

Where is the fetch after the first row fetch? is it in the D210-ADD-DWH-ROWS paragraph?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sri50131
Beginner


Joined: 07 Oct 2004
Posts: 38
Topics: 15

PostPosted: Fri Oct 15, 2004 4:59 pm    Post subject: Reply with quote

Kolusu,

Sorry for not mentioninn it, I do the fetch in C210-PROCESS-CURSOR1-DATA.

The process is as follows:

In C210-PROCESS-CURSOR1-DATA para, I do the following:
I fetch the cusor, then do the following:

EVALUATE SQLCODE
WHEN 0
PERFORM D210-ADD-DWH-ROWS THRU
D210-ADD-DWH-ROWS-EXIT
WHEN +100
MOVE 'NO' TO WS-ROWS
PERFORM Z005-CLOSE-CURSOR1 THRU
Z005-CLOSE-CURSOR1-EXIT

Thanks.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Fri Oct 15, 2004 5:13 pm    Post subject: Reply with quote

sri50131,

This is how a sample to load another table fetching from another table.

Code:


PERFORM 1000-OPEN-CURSOR
PERFORM 1200-FETCH-CURSOR
PERFORM 1400-LOAD-TABLE-B UNTIL WS-ROWS = 'NO'


1000-OPEN-CURSOR

 EXEC SQL
      OPEN CURSOR
 END-EXEC
 EVALUATE SQLCODE
     WHEN +0
          CONTINUE
     WHEN +100
          MOVE 'NO ' TO WS-ROWS           
     WHEN OTHER
          DISPLAY 'PARAGRAPH 1000-OPEN ABENDING'
          PERFORM INHOUSE-ABEND
 END-EVALUATE
 .
 

1200-FETCH-CURSOR.

 EXEC SQL
       FETCH CURSOR
        INTO :WS-WORKING-FIELDS 
 END-EXEC
 
 EVALUATE SQLCODE
     WHEN +0
          MOVE 'YES' TO WS-ROWS
     WHEN +100
          MOVE 'NO ' TO WS-ROWS
     WHEN OTHER
          DISPLAY 'PARAGRAPH 1200-FETCH ABENDING'
          PERFORM INHOUSE-ABEND
 END-EVALUATE
 .
1400-LOAD-TABLE-B.
 
   EXEC SQL
        INSERT INTO TABLE_B
          (COL LIST)
          VALUES
          (HOST VARIABLES)
   END-EXEC.

   EVALUATE SQLCODE
       WHEN +0
            PERFORM 1200-FETCH-CURSOR
       WHEN OTHER
           DISPLAY 'PARAGRAPH 1500-LOAD ABENDING'
           PERFORM INHOUSE-ABEND
   END-EVALUATE
   .



Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sri50131
Beginner


Joined: 07 Oct 2004
Posts: 38
Topics: 15

PostPosted: Fri Oct 15, 2004 6:06 pm    Post subject: Reply with quote

Kolusu,

I changed my code as you suggested. It is still going in a loop.

The Following is my code:

PERFORM B210-DECLARE-CURSOR1
THRU B210-DECLARE-CURSOR1-EXIT.

PERFORM B211-FETCH-CURSOR1
THRU B211-FETCH-CURSOR1-EXIT.

PERFORM B212-LOAD-DWH-TABLE
THRU B212-LOAD-DWH-TABLE-EXIT UNTIL WS-ROWS = 'NO'.

However, it is still going in a loop. I just came to know that the target table (DWH tabe) is defined with no indexes and no keys. Does this have any thing to do with the looping of the code? If not declaring keys is an issue, I wonder how am I able to run this SQL in SPUFI with not problems (the SQL when run in SPUFI gives me 47 rows).

Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group