Sourcing Rule
Query to Assign Items to Sourcing rule:
--SET SERVEROUTPUT ON;
DECLARE
V_ASSIGNMENT_ID MRP_SR_ASSIGNMENTS.ASSIGNMENT_ID%TYPE;
V_ASSIGNMENT_SET_ID MRP_SR_ASSIGNMENTS.ASSIGNMENT_SET_ID%TYPE := 1;
V_ASSIGNMENT_TYPE MRP_SR_ASSIGNMENTS.ASSIGNMENT_TYPE%TYPE := 1;
V_SOURCING_RULE_ID MRP_SR_ASSIGNMENTS.SOURCING_RULE_ID%TYPE := 1001;
V_SOURCING_RULE_TYPE MRP_SR_ASSIGNMENTS.SOURCING_RULE_TYPE%TYPE :=1;
V_organization_id MRP_SR_ASSIGNMENTS.organization_id%TYPE;
CURSOR C1 IS
select msib.inventory_item_id,msib.segment1 ITEM_NUM,msib.organization_id
from mtl_system_items_b msib
where msib.organization_id = 12
AND msib.segment1 in ('2017');
BEGIN
FOR SR IN C1 LOOP
V_organization_id := SR.organization_id ;
IF V_organization_id = 12 THEN
BEGIN
V_ASSIGNMENT_ID := MRP_SR_ASSIGNMENTS_S.NEXTVAL ;
INSERT INTO MRP_SR_ASSIGNMENTS MSRA
( msra.ASSIGNMENT_ID,
msra.assignment_set_id,
msra.assignment_type,
msra.sourcing_rule_type,
msra.sourcing_rule_id,
msra.organization_id,
msra.inventory_item_id,
msra.last_update_date,
msra.last_updated_by,
msra.creation_date,
msra.created_by
)
VALUES
(V_ASSIGNMENT_ID,
V_ASSIGNMENT_SET_ID , --ASSIGNMENT_SET_ID
V_ASSIGNMENT_TYPE,
V_SOURCING_RULE_TYPE,
V_SOURCING_RULE_ID , --sourcing_rule_id
SR.organization_id,
SR.inventory_item_id,
SYSDATE, --last_update_date
1, -- last_updated_by
SYSDATE, -- creation_date
1 -- created_by opera,
);
DBMS_OUTPUT.PUT_LINE ('ITEMS INSERTED'||'-'||SR.ITEM_NUM);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Inseration failed'||'-'||SQLERRM);
END;
ELSE
DBMS_OUTPUT.PUT_LINE ('Organization id is not org'||'-'||V_organization_id);
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Procedure failed'||'-'||SQLERRM);
END;
Comments
Post a Comment