Академический Документы
Профессиональный Документы
Культура Документы
This blog intends to write on IBM Mainframe Technologies and cover key concepts in Cobol,DB2,CICS,JCL,VSAM and more..
Blog Posts
There are two types of cursor:
1.Row-set positioned cursor : Here the result table are stored into Host variable arrays. DB2 (34) JCL (25)
2.Row-positioned cursor : This type points to the current row/particular row in the result set. COBOL (15) SORT (11) ISPF
It points to the next row to be passed to the application program. (10) SAS (9) VSAM (8) CA7 (3) CICS
(3) REXX (1) SQL (1)
The primary steps for using any cursor are as follows:
Step1. Declare the cursor Followers
Step2 Open the Cursor. This causes Db2 to build the result set.
Followers (35) Next
Step3. Fetch each row ,one at a time, and pass it onto application program
Step4: Close the cursor.
ready to be processed to be used to the application program in subsequent steps. ► 2013 (25)
EXEC SQL
▼ 2014 (34)
OPEN EMP_CURSOR
► February (4)
END-EXEC.
► March (8)
Once the open is done, we need to fetch the data
► April (3)
FETCH the cursor: ▼ May (4)
EXEC SQL SAS in Mainframes(z/Os)
FETCH EMP_CURSOR Tutorial : Use of symbolic...
INTO :EMPNAME,:EMPID CURSORS in DB2 and how to
END-EXEC. use CURSOR in DB2?
Scrollable Cursor in DB2 :
Sensitive cursor,insens...
FETCH is the only way to get the result into application program Host variable. We fetch each row into
the Host variable and process the data. We can continue fetching of the data until we get a SQLCODE Static cursors and Dynamic
cursors in DB2
of +100 which implies END of the result table.
CLOSE the CURSOR ► June (4)
Once we are done with fetching of the records, we need to close the cursor.
► July (1)
EXEC SQL
► August (4)
CLOSE EMP_CURSOR
END-EXEC. ► September (1)
► October (2)
http://mframes.blogspot.com/2014/05/normal-0-false-false-false.html 1/3
9/24/2018 IBM MAINFRAME FORUM: CURSORS in DB2 and how to use CURSOR in DB2?
How to UPDATE AND DELETE records in cursor. ► December (3)
There can be instances where we need to modify the data in db2 table based on some values in a
programmatic way. Had it been a spufi or QMF we have our update and delete statements ready to run ► 2015 (23)
and modify. But we are in cobol program. Nevertheless we can do the same modifications using ► 2016 (9)
cursors again.!! We need to add special clause while declaring the cursor with 'FOR UPDATE OF'. ► 2017 (1)
Even if we want to delete, we need to mention 'FOR UPDATE OF' in declare statement and we
need to delete the entire row. Also we need to use WHERE CURRENT OF to update or delete the last
row fetched.
Lets see the below example where we will update and delete some row in the cursor :
EXEC SQL
DECLARE EMP_CURSOR CURSOR FOR
SELECT EMP_NAME,EMP_ID
FROM EMP
WHERE EMP_JOIN_DATE > '20000101'
FOR UPDATE OF NAME <== DECLARE THE CURSOR WITH THIS CLAUSE
END-EXEC.
...............................
EXEC SQL
UPDATE EMP
SET EMP_NAME=:EMPNAME
WHERE CURRENT OF EMP_CURSOR
END-EXEC
EXEC SQL
DELETE FROM EMP
WHERE CURRENT OF EMP_CURSOR
END-EXEC.
****Important point Regarding the Usage of 'FOR UPDATE OF' in CURSOR.****
If the select statement defining the cursor contains ORDER BY,GROUP BY, DISTINCT, SET
OPERATORS ( UNION,EXCEPT, INTERSECT), JOIN, FOR FETCH ONLY/FOR READ ONLY, then the
usage of 'FOR UPDATE OF' is NOT permitted. The above keywords make the cursor READ ONLY
cursor.
2 comments:
Reply
http://mframes.blogspot.com/2014/05/normal-0-false-false-false.html 2/3
9/24/2018 IBM MAINFRAME FORUM: CURSORS in DB2 and how to use CURSOR in DB2?
Powered by Blogger.
http://mframes.blogspot.com/2014/05/normal-0-false-false-false.html 3/3