IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Getting SQLCODE -508 when updating the last record in table?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 792
Location: Chennai, India

PostPosted: Thu Apr 03, 2008 11:45 am
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: 6966
Location: porcelain throne

PostPosted: Thu Apr 03, 2008 12:22 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Load new table with Old unload - DB2 DB2 6
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top