You are on page 1of 3

EXEC SQL

UPDATE table-name
SET column-1 = value [, column-2 = value] ...
WHERE CURRENT OF cursor-name
END-EXEC.

EXEC SQL
DECLARE THISEMP CURSOR FOR
SELECT EMPNO, LASTNAME,
WORKDEPT, JOB
FROM aaA.EMPLOYEE
FOR UPDATE OF JOB
END-EXEC.

Step 1: Defining the cursor.


EXEC SQL
OPEN THISEMP
END-EXEC.
Step 2: Opening the cursor.
EXEC SQL
WHENEVER NOT FOUND
GO TO CLOSE-THISEMP
END-EXEC.
Step 3: Specifying what to do when the end of data is reached.
EXEC SQL
FETCH THISEMP
INTO :EMP-NUM, :NAME2,
:DEPT, :JOB-CODE
END-EXEC.
Step 4: Retrieving a row using a cursor.
... for all employees
in department D11, update
the JOB value:

EXEC SQL
UPDATE aaA.EMPLOYEE
SET JOB = :NEW-CODE
WHERE CURRENT OF THISEMP
END-EXEC.

... then print the row.


Step 5a: Updating the current row.
... for other employees,
delete the row:

EXEC SQL
DELETE FROMaaa.EMPLOYEE
WHERE CURRENT OF THISEMP
END-EXEC.
Step 5b: Deleting the current row.
Branch back to fetch and process the next row.
CLOSE-THISEMP.
EXEC SQL
CLOSE THISEMP
END-EXEC.
Step 6: Closing the cursor.
For the scrollable cursor example, the program uses the RELATIVE position option to
obtain a representative sample of salaries from department D11.

Table 2. A scrollable cursor example Scrollable cursor SQL statement Described in


section
EXEC SQL
DECLARE THISEMP DYNAMIC SCROLL CURSOR FOR
SELECT EMPNO, LASTNAME,
SALARY
FROM aaa.EMPLOYEE
WHERE WORKDEPT = 'D11'
END-EXEC.
Step 1: Defining the cursor.
EXEC SQL
OPEN THISEMP
END-EXEC.
Step 2: Opening the cursor.
EXEC SQL
WHENEVER NOT FOUND
GO TO CLOSE-THISEMP
END-EXEC.
Step 3: Specifying what to do when the end of data is reached.
...initialize program summation
salary variable
EXEC SQL
FETCH RELATIVE 3 FROM THISEMP
INTO :EMP-NUM, :NAME2,
:JOB-CODE
END-EXEC.
...add the current salary to
program summation salary
...branch back to fetch and
process the next row.

-------------------------

EXEC CICS STARTBR


FILE(new PATH file)
RIDFLD(alternate key)
GTEQ
RESP(WSV-RESP)
END-EXEC

EXEC CICS READPREV


FILE(new PATH file)
INTO((record layout of base file))
LENGTH((record length of base file))
RIDFLD(alternate key)
RESP(WSV-RESP)
END-EXEC

EXEC CICS READNEXT


FILE(new PATH file)
INTO((record layout of base file))
RIDFLD(alternate key)
LENGTH((record length of base file))
RESP(WSV-RESP)
END-EXEC
========

IMHO S522 stands for too long waiting for mounting a required device like tape or
disk.

============

You might also like