Code Listing 4: Logic in stepwise refinement

 1  CREATE OR REPLACE PROCEDURE assign_workload (department_in IN emp.deptno%TYPE)
 2  IS
 3    case# INTEGER;
 4
 5    CURSOR emps_in_dept_cur
 6    IS
 7       SELECT * FROM emp
 8        WHERE deptno = department_in;
 9
10    PROCEDURE assign_next_open_case (emp_id_in IN emp.empno%TYPE, case_out OUT NUMBER)
11    IS BEGIN NULL; END assign_next_open_case;
12
13    FUNCTION next_appointment (case_id_in IN NUMBER)
14        RETURN DATE
15    IS BEGIN RETURN SYSDATE; END next_appointment;
16
17    PROCEDURE schedule_case (case_in IN NUMBER, date_in IN DATE)
18    IS BEGIN NULL; END schedule_case;
19     END;
20  /* MAIN ASSIGN_WORKLOAD */
21  BEGIN
22    FOR emp_rec IN emps_in_dept_cur
23    LOOP
24       IF analysis.caseload (emp_rec.empno) <
25           analysis.avg_cases (department_in)
26       THEN
27          assign_next_open_case (emp_rec.empno, case#);
28          schedule_case (case#, next_appointment (case#));
29       END IF;
30    END LOOP;
31* END assign_workload;