View previous topic :: View next topic
|
Author |
Message |
venktv
New User
Joined: 29 Mar 2006 Posts: 59 Location: Montreal
|
|
|
|
Hi All,
I have a cursor in my program,
Fetch operation is not throwing the SQLCODE +100, when it reaches the end of the table, instead it is fetching the first row again, what may be the reason, if anyone knows, please let me know..
cursor defnitiion:
EXEC SQL
DECLARE VQ18-CSR CURSOR FOR
SELECT A.WK_TEL_NO,
A.DUE_DT
FROM VQ1801 A, VS05 B
WHERE ( A.DUE_DT >= :WS-DUE-DATE ) OR
( A.SODB_INTRNL_KY = B.SODB_INTRNL_KY
AND
B.DUE_DT_RC NOT IN (' ', 'OK' ))
FOR FETCH ONLY
END-EXEC.
PERFORM OPEN-CURSOR.
PERFORM UNTIL NO-MORE-ORDERS
PERFORM 2020-FETCH-CSR THRU 2020-EXIT
END-PERFORM
2020-FETCH-CSR.
EXEC SQL
FETCH VQ18-CSR
INTO :BDVQ18-WK-TEL-NO,
:BDVQ18-DUE-DT
END-EXEC
IF SQLCODE = 0
CONTINUE
ELSE
IF SQLCODE = +100
SET NO-MORE-ORDERS TO TRUE
ELSE
CALL ABEND ROUTINE
END-IF.
END-IF
I am not get the SQL code +100, after fetching all the records, instead it is fetching the first record again, please let me know the reason if anybody knows
Thannks and Regards
Venkat |
|
Back to top |
|
|
nuthan
Active User
Joined: 26 Sep 2005 Posts: 146 Location: Bangalore
|
|
|
|
Hi,
Can you please check whether you have coded any where else the statement "PERFORM 2020-FETCH-CSR THRU 2020-EXIT" apart from the above mentioned Inline perform. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
well this is crap:
Code: |
IF SQLCODE = 0
CONTINUE
ELSE
IF SQLCODE = +100
SET NO-MORE-ORDERS TO TRUE
ELSE
CALL ABEND ROUTINE
END-IF.
END-IF
|
what else are you doing in your program? are you doing anything that would reposition the cursor pointer?
and performing thru exits is also bad code.
don't see a close cursor. what else is dropping thru.
how do you know that it is starting again? have you spufi'd this sql to see how many rows the cursor should return? |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
The structure of your program is not so clear with the data provided.
Can you be more detailed... |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
There appears no problem after looking into your code ...
If you could try and answer dick's questions i think you shud be able to find out the error ...
change ur code for better readability ... and make sure your flag is not set on before the perform ...
Code: |
PERFORM OPEN-CURSOR.
PERFORM 2020-FETCH-CSR UNTIL NO-MORE-ORDERS
PERFORM CLOSE-CURSOR
2020-FETCH-CSR.
EXEC SQL
FETCH VQ18-CSR
INTO :BDVQ18-WK-TEL-NO,
:BDVQ18-DUE-DT
END-EXEC
EVALUATE SQLCODE
WHEN 0
CONTINUE
WHEN 100
SET NO-MORE-ORDERS TO TRUE
WHEN OTHER
CALL ABEND ROUTINE
END-EVALUATE.
|
|
|
Back to top |
|
|
|