Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Getting SQLCODE -508 when updating the last record in table?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Thu Apr 03, 2008 11:35 am    Post subject: Getting SQLCODE -508 when updating the last record in table?
Reply with quote

In my program i am using two cursor and updating the same table based on conditions.Both cursor declarations having FOR UPDATE OF and WHERE CURRENT OF CURSOR in Update statement para.

Now i am fetching the records one by one and updating simulteniously.But at the time of Last record(End of Table),the update statement throws SQLCODE -508. Please tell me how to resolve this Problem?

Please see my code:

EXEC SQL DECLARE CNTL_TABLE_CSR1 CURSOR WITH HOLD FOR
SELECT CNTL_TBL_NME,
CNTL_DTE,
CNTL_FLAG
FROM ARW_CNTL_TABLE
WHERE CNTL_FLAG = 'A'
FOR UPDATE OF CNTL_FLAG
END-EXEC.

EXEC SQL
OPEN CNTL_TABLE_CSR1
END-EXEC.

IF SQLCODE NOT = +0
MOVE SQLCODE TO WS-DB2-CODE
DISPLAY ' ******************************************'
DISPLAY ' * ERROR ON OPEN CURSOR1 .'
DISPLAY ' * DB2 STATUS WAS ', WS-DB2-CODE
DISPLAY '******************************************'
MOVE '2' TO WS-ERROR-FLAG
MOVE +026 TO WS-RETURN-CODE
GO TO 2999-EXIT
END-IF.


PERFORM UNTIL END-OF-TABLE

EXEC SQL
FETCH CNTL_TABLE_CSR1
INTO :CNTL-TBL-NME,
:CNTL-DTE,
:CNTL-FLAG
END-EXEC

EVALUATE SQLCODE
WHEN +0
ADD +1 TO WS-CURSOR1-REC-COUNT
CONTINUE
WHEN +100
SET END-OF-TABLE TO TRUE
WHEN OTHER
DISPLAY 'ERROR IN FETCH'
MOVE +016 TO WS-RETURN-CODE
END-EVALUATE



MOVE 'H' TO WS-CNTL-FLAG

EXEC SQL
UPDATE ARW_CNTL_TABLE
SET CNTL_FLAG = :WS-CNTL-FLAG
WHERE CURRENT OF CNTL_TABLE_CSR1
END-EXEC


IF SQLCODE = +0
ADD +1 TO WS-UPDATE-CSR1-COUNT
END-IF


IF SQLCODE NOT = +0
MOVE SQLCODE TO WS-DB2-CODE
DISPLAY ' ******************************************'
DISPLAY '*** ERROR UPDATING ARW_CNTL_TABLE**********'
DISPLAY ' * DB2 STATUS WAS ', WS-DB2-CODE
DISPLAY ' * DB2 STATUS WAS ', WS-DB2-CODE
DISPLAY '******************************************'
MOVE '2' TO WS-ERROR-FLAG
MOVE +30 TO WS-RETURN-CODE
GO TO 4000-ROLLBACK
END-IF
END-PERFORM.

EXEC SQL
CLOSE CNTL_TABLE_CSR1
END-EXEC.

IF SQLCODE NOT = +0
DISPLAY '*** ERROR CLOSING THE CURSOR ***'
DISPLAY '*** FOR CNTL_TABLE_CSR1 ***'
GO TO 4000-ROLLBACK
END-IF.

Please tell me how to resolve this problem?
Back to top
View user's profile Send private message

Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 788
Location: Chennai, India

PostPosted: Thu Apr 03, 2008 11:45 am    Post subject:
Reply with quote

Have you looked into MVS QW for this?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Thu Apr 03, 2008 12:22 pm    Post subject:
Reply with quote

you have an evaluate to set certain flags after the fetch. when you get a +100 (end of table) you set the flag and then you go ahead and update the table without checking the status of the previous fetch.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Apr 03, 2008 2:27 pm    Post subject:
Reply with quote

you need to exit the perform loop when sqlcode =100 after the fetch ...
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts query to fetch record which has only ... maxsubrat DB2 2 Mon Dec 11, 2017 5:03 pm
No new posts Extract record for change in combinat... Trinadh DFSORT/ICETOOL 6 Thu Nov 23, 2017 3:32 pm
No new posts Extract Record using range of Data scorp_rahul23 DFSORT/ICETOOL 3 Wed Nov 15, 2017 11:54 pm
No new posts Squeeze record left so that zeroes ar... Vignesh Sid SYNCSORT 5 Fri Nov 10, 2017 1:40 pm
No new posts Formatting multiple records to a sing... Vignesh Sid SYNCSORT 3 Tue Nov 07, 2017 12:22 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us