DECLARE
CURSOR stage
IS
SELECT *
FROM staging_pm_schedule_table
WHERE flag IS NULL;
l_stat VARCHAR2 (10);
l_count NUMBER;
l_data VARCHAR2 (100);
l_schedule eam_pmdef_pub.pm_scheduling_rec_type;
l_activity eam_pmdef_pub.pm_activities_grp_tbl_type;
l_day eam_pmdef_pub.pm_rule_tbl_type;
l_runtime eam_pmdef_pub.pm_rule_tbl_type;
l_list eam_pmdef_pub.pm_rule_tbl_type;
l_id NUMBER;
l_sch_id NUMBER;
v_active_assc NUMBER;
v_obj_id NUMBER;
v_obj_type NUMBER;
v_stat VARCHAR2 (1) := 'S';
v_tmpl_flag VARCHAR2 (30);
BEGIN
FOR i IN stage
LOOP
SELECT activity_association_id, maintenance_object_id,
maintenance_object_type, template_flag
INTO v_active_assc, v_obj_id,
v_obj_type, v_tmpl_flag
FROM mtl_eam_asset_activities_v
WHERE activity_association_id = i.activity_association_id;
SELECT eam_pm_schedulings_s.NEXTVAL
INTO l_sch_id
FROM DUAL;
l_schedule.pm_schedule_id := l_sch_id;
l_schedule.NAME := i.NAME;
l_schedule.activity_association_id := v_active_assc;
l_schedule.set_name_id := i.set_name_id;
l_schedule.maintenance_object_id := v_obj_id;
l_schedule.maintenance_object_type := v_obj_type;
l_schedule.from_effective_date := i.from_effective_date;
l_schedule.generate_wo_status := i.generate_wo_status;
l_schedule.current_cycle := 1;
l_schedule.current_seq := 0;
l_schedule.interval_per_cycle := i.interval_per_cycle;
l_schedule.generate_next_work_order := i.generate_next_work_order;
l_schedule.non_scheduled_flag := i.non_scheduled_flag;
l_schedule.rescheduling_point := i.rescheduling_point;
l_schedule.default_implement := i.default_implement;
l_schedule.whichever_first := i.whichever_first;
l_schedule.include_manual := i.include_manual;
l_schedule.scheduling_method_code := i.scheduling_method_code;
l_schedule.type_code := i.type_code;
l_schedule.auto_instantiation_flag := i.auto_instantiation_flag;
l_schedule.tmpl_flag := v_tmpl_flag;
l_schedule.attribute1 := i.description;
l_activity (1).activity_association_id := v_active_assc;
l_activity (1).interval_multiple := i.interval_multiple;
l_activity (1).allow_repeat_in_cycle := i.allow_repeat_in_cycle;
IF i.meter_id IS NULL
THEN
l_day (1).rule_type := i.rule_type;
l_day (1).day_interval := i.day_interval;
ELSE
l_runtime (1).rule_type := i.rule_type;
l_runtime (1).meter_id := i.meter_id;
l_runtime (1).runtime_interval := i.runtime_interval;
END IF;
eam_pmdef_pub.create_pm_def (p_api_version => 1.0,
p_init_msg_list => NULL,
p_commit => 'T',
p_validation_level => NULL,
x_return_status => l_stat,
x_msg_count => l_count,
x_msg_data => l_data,
p_pm_schedule_rec => l_schedule,
p_pm_activities_tbl => l_activity,
p_pm_day_interval_rules_tbl => l_day,
p_pm_runtime_rules_tbl => l_runtime,
p_pm_list_date_rules_tbl => l_list,
x_new_pm_schedule_id => l_id
);
UPDATE staging_pm_schedule_table
SET flag = l_stat,
note = SUBSTR (l_data, 5, LENGTH (l_data))
WHERE activity_association_id = i.activity_association_id AND ID = i.ID;
COMMIT;
IF l_stat <> 'S'
THEN
v_stat := 'E';
ROLLBACK;
EXIT;
END IF;
END LOOP;
IF v_stat <> 'E'
THEN
COMMIT;
END IF;
END;
No comments:
Post a Comment