0% found this document useful (0 votes)
1K views

Item Import Migration Oracle Apps

This procedure validates and creates items imported from a staging table. It performs several validation checks on the item attributes, including validating the organization, checking for duplicate items, and validating reference data values like unit of measures and categories. If validation fails, an error flag and message are set. Otherwise, the item is created in the application tables.

Uploaded by

priyanka532
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Item Import Migration Oracle Apps

This procedure validates and creates items imported from a staging table. It performs several validation checks on the item attributes, including validating the organization, checking for duplicate items, and validating reference data values like unit of measures and categories. If validation fails, an error flag and message are set. Otherwise, the item is created in the application tables.

Uploaded by

priyanka532
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

CREATE OR REPLACE PACKAGE BODY APPS.

xx_item_import_pkg
IS
-- +===================================================================+
-- |
-- +===================================================================+
-- | |
-- | XX_ITEM_IMPORT_PKG |
-- | |
-- |Description: Procedure to validate and create items |
-- | |
-- | |
-- | |
-- +===================================================================+
PROCEDURE xx_item_import_proc (errbuf OUT VARCHAR2, retcode OUT NUMBER)
IS
-- ===========================
-- Cursor declaration Starts
-- ===========================
CURSOR c1
IS
SELECT *
FROM xx_item_import_stg
WHERE status_flag = 'N';

v_start_auto_lot_number VARCHAR2 (20) := NULL;


v_tracking_quantity_ind VARCHAR2 (20) := NULL;
v_lot_control VARCHAR2 (20) := NULL;
v_lot_divisible_flag VARCHAR2 (20) := NULL;
v_secondary_default_ind VARCHAR2 (20) := NULL;
v_organization_id NUMBER;
v_err_msg VARCHAR2 (4000) := NULL;
v_err_flag VARCHAR2 (1) := NULL;
v_template_id NUMBER;
v_p_uom_code VARCHAR2 (20) := NULL;
v_s_uom_code VARCHAR2 (20) := NULL;
v_category_set_id NUMBER;
v_category_id NUMBER;
v_seg_count NUMBER;
v_seg_count_int NUMBER;
v_ass_category_id NUMBER;
v_template_name VARCHAR (30) := NULL;
v_planning_make_buy_code NUMBER;
l_bom_enabled_flag VARCHAR (3);
BEGIN -- Main block validation
FOR items_rec IN c1
LOOP -- Loop for validation
v_err_flag := 'Y';
v_err_msg := NULL;
DBMS_OUTPUT.put_line ('ITEM DESCRIPTION ' || items_rec.description);
-- ====================================
-- Inventory organization validation
-- ===================================
BEGIN
SELECT organization_id
INTO v_organization_id
FROM org_organization_definitions
WHERE organization_code = TRIM (items_rec.organization_code);
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Organization Code for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line
( 'Invalid Organization Code for the item -- '
|| items_rec.item_segment
);
END;
-- ===========================
-- Checking for Duplicates
-- ===========================
SELECT COUNT (segment1)
INTO v_seg_count
FROM mtl_system_items_b
WHERE UPPER (segment1) = TRIM (UPPER (items_rec.item_segment))
AND organization_id = v_organization_id;
SELECT COUNT (segment1)
INTO v_seg_count_int
FROM mtl_system_items_interface
WHERE TRIM (UPPER (segment1)) =
TRIM (UPPER (items_rec.item_segment))
AND organization_id = 84;
IF (v_seg_count = 0 AND v_seg_count_int = 0)
THEN
NULL;
ELSE
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| '/'
|| 'Duplicate item number : '
|| items_rec.item_segment;
END IF;
-- ====================================
-- Validation for the Template name
-- ===================================
BEGIN
SELECT template_name
INTO v_template_name
FROM mtl_item_templates
WHERE UPPER (template_name) =
TRIM (UPPER (items_rec.template_name));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Template name for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line ('Invalid Template name for the item');
END;
-- ========================================
-- Validation for primary unit of measure
-- ========================================
BEGIN
SELECT uom_code
INTO v_p_uom_code
FROM mtl_units_of_measure
WHERE UPPER (uom_code) =
TRIM (UPPER (items_rec.primary_uom_code));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Primary Unit of Measure for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line
('Invalid Primary Unit of Measure for the item');
END;
-- ========================================
-- Validation for Secondary unit of measure
-- ========================================
IF items_rec.secondary_uom_code IS NOT NULL
THEN
BEGIN
SELECT uom_code
INTO v_s_uom_code
FROM mtl_units_of_measure
WHERE UPPER (uom_code) =
TRIM (UPPER (items_rec.secondary_uom_code));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Secondary Unit of Measure for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line
('Invalid Secondary Unit of Measure for the item');
END;
END IF;
-- ========================================
-- Validation for Category set name
-- ========================================
BEGIN
SELECT category_set_id
INTO v_category_set_id
FROM mtl_category_sets
WHERE (category_set_name) = 'CBL Item Category Set';
--TRIM(UPPER(items_rec.category_set_name));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Category Set Name for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line ('Invalid Category Set Name for the item');
END;
DBMS_OUTPUT.put_line ('Item Category Set ID is ' || v_category_set_id);
-- ========================================
-- Validation for Category name
-- ========================================
BEGIN
SELECT category_id
INTO v_category_id
FROM mtl_categories
WHERE UPPER (segment1) = TRIM (UPPER (items_rec.major_category))
AND UPPER (segment2) = TRIM (UPPER (items_rec.minor_category));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Category Name for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line ('Invalid Category Name for the item');
END;
-- ========================================
-- Validation for START_AUTO_LOT_NUMBER
-- ========================================
BEGIN
IF items_rec.lot_control IS NULL
THEN
v_start_auto_lot_number := NULL;
ELSE
v_start_auto_lot_number := '01';
END IF;
END;
--========================================
-- Validation for TRACKING_QUANTITY_IND
-- ========================================
BEGIN
IF items_rec.secondary_uom_code IS NULL
THEN
v_tracking_quantity_ind := 'P';
ELSE
v_tracking_quantity_ind := 'PS';
l_bom_enabled_flag := 'N';
END IF;
END;
--========================================
-- Validation for LOT_CONTROL_CODE
-- ========================================
BEGIN
IF items_rec.lot_control IS NULL
THEN
v_lot_control := '1'; -- No Lot Control
ELSE
v_lot_control := '2'; -- Full Lot Control
END IF;
END;
--dbms_output.put_line('insert partout');
BEGIN
IF v_lot_control = '1'
THEN
v_lot_divisible_flag := 'N';
ELSE
v_lot_divisible_flag := 'Y';
END IF;
END;
BEGIN
IF items_rec.secondary_uom_code IS NULL
THEN
v_secondary_default_ind := '';
ELSE
v_secondary_default_ind := 'D';
END IF;
END;
BEGIN
IF UPPER (items_rec.make_buy) = 'MAKE'
THEN
v_planning_make_buy_code := 1;
ELSE
v_planning_make_buy_code := 2;
END IF;
END;
IF v_err_flag <> 'E'
THEN
INSERT INTO mtl_system_items_interface
(segment1,
description,
primary_uom_code,
secondary_uom_code,
template_name,
organization_id,
lot_control_code,
shelf_life_days,
auto_lot_alpha_prefix,
start_auto_lot_number,
planning_make_buy_code,
list_price_per_unit,
min_minmax_quantity,
max_minmax_quantity,
minimum_order_quantity,
maximum_order_quantity,
tracking_quantity_ind,
bom_enabled_flag,
ont_pricing_qty_source,
secondary_default_ind,
lot_divisible_flag,
process_flag,
transaction_type,
set_process_id,
creation_date,
created_by,
last_update_date,
last_updated_by
--SERIAL_NUMBER_CONTROL_CODE
)
VALUES (TRIM (items_rec.item_segment),
TRIM (items_rec.description),
v_p_uom_code,
TRIM (items_rec.secondary_uom_code),
v_template_name,
84, -- Master Org --v_organization_id,
v_lot_control, -- lot Control
(items_rec.shelf_life_days),
TRIM (items_rec.lot_prefix),
v_start_auto_lot_number,
v_planning_make_buy_code, -- Buy
items_rec.list_price,
(items_rec.min_stock),
(items_rec.max_stock),
0,
(items_rec.re_order_level),
v_tracking_quantity_ind,
l_bom_enabled_flag,
'P',
v_secondary_default_ind,
v_lot_divisible_flag,
1, -- Process flag
'CREATE', -- Transaction type
1, -- Set process id
SYSDATE, -- Creation date
1110, --fnd_profile.value('user_id'),
SYSDATE,
1110 -- fnd_profile.value('user_id')
--5 --l_serial_number_code -- define a variale
);
INSERT INTO mtl_item_categories_interface
(organization_id, process_flag, set_process_id,
transaction_type, item_number,
category_set_id, category_id, creation_date,
created_by, last_update_date, last_updated_by
)
VALUES (84, -- Master Org --v_organization_id ,
1, -- Process flag
1, -- Set process id
'CREATE', -- Transaction type
TRIM (items_rec.item_segment),
v_category_set_id, v_category_id, SYSDATE,
1110, --fnd_profile.value('user_id') ,
SYSDATE, 1110 --fnd_profile.value('user_id')
);
COMMIT;
UPDATE xx_item_import_stg
SET status_flag = 'P'
WHERE item_segment = items_rec.item_segment;
ELSE
UPDATE xx_item_import_stg
SETstatus_flag = 'E',
error_messege = v_err_msg
WHERE item_segment = items_rec.item_segment;
fnd_file.put_line (fnd_file.LOG, v_err_msg);
-- Inserting errors into log file.
COMMIT;
END IF;
END LOOP; -- Loop for validation
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
fnd_file.put_line (fnd_file.LOG,
' Error occured in the item validation process'
);
END; -- Main block Validation
END xx_item_import_pkg;
/

CREATE OR REPLACE PACKAGE BODY APPS.xx_item_import_pkg


IS
-- +===================================================================+
-- | |
-- +===================================================================+
-- | |
-- | XX_ITEM_IMPORT_PKG |
-- | |
-- |Description: Procedure to validate and create items |
-- | |
-- | |
-- | |
-- +===================================================================+
PROCEDURE xx_item_import_proc (errbuf OUT VARCHAR2, retcode OUT NUMBER)
IS
-- ===========================
-- Cursor declaration Starts
-- ===========================
CURSOR c1
IS
SELECT *
FROM xx_item_import_stg
WHERE status_flag = 'N';

v_start_auto_lot_number VARCHAR2 (20) := NULL;


v_tracking_quantity_ind VARCHAR2 (20) := NULL;
v_lot_control VARCHAR2 (20) := NULL;
v_lot_divisible_flag VARCHAR2 (20) := NULL;
v_secondary_default_ind VARCHAR2 (20) := NULL;
v_organization_id NUMBER;
v_err_msg VARCHAR2 (4000) := NULL;
v_err_flag VARCHAR2 (1) := NULL;
v_template_id NUMBER;
v_p_uom_code VARCHAR2 (20) := NULL;
v_s_uom_code VARCHAR2 (20) := NULL;
v_category_set_id NUMBER;
v_category_id NUMBER;
v_seg_count NUMBER;
v_seg_count_int NUMBER;
v_ass_category_id NUMBER;
v_template_name VARCHAR (30) := NULL;
v_planning_make_buy_code NUMBER;
l_bom_enabled_flag VARCHAR (3);
BEGIN -- Main block validation
FOR items_rec IN c1
LOOP -- Loop for validation
v_err_flag := 'Y';
v_err_msg := NULL;
DBMS_OUTPUT.put_line ('ITEM DESCRIPTION ' || items_rec.description);
-- ====================================
-- Inventory organization validation
-- ===================================
BEGIN
SELECT organization_id
INTO v_organization_id
FROM org_organization_definitions
WHERE organization_code = TRIM (items_rec.organization_code);
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Organization Code for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line
( 'Invalid Organization Code for the item -- '
|| items_rec.item_segment
);
END;
-- ===========================
-- Checking for Duplicates
-- ===========================
SELECT COUNT (segment1)
INTO v_seg_count
FROM mtl_system_items_b
WHERE UPPER (segment1) = TRIM (UPPER (items_rec.item_segment))
AND organization_id = v_organization_id;
SELECT COUNT (segment1)
INTO v_seg_count_int
FROM mtl_system_items_interface
WHERE TRIM (UPPER (segment1)) =
TRIM (UPPER (items_rec.item_segment))
AND organization_id = v_organization_id;
IF (v_seg_count = 0 AND v_seg_count_int = 0)
THEN
NULL;
ELSE
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| '/'
|| 'Duplicate item number : '
|| items_rec.item_segment;
END IF;
-- ====================================
-- Validation for the Template name
-- ===================================
BEGIN
SELECT template_name
INTO v_template_name
FROM mtl_item_templates
WHERE UPPER (template_name) =
TRIM (UPPER (items_rec.template_name));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Template name for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line ('Invalid Template name for the item');
END;
-- ========================================
-- Validation for primary unit of measure
-- ========================================
BEGIN
SELECT uom_code
INTO v_p_uom_code
FROM mtl_units_of_measure
WHERE UPPER (uom_code) =
TRIM (UPPER (items_rec.primary_uom_code));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Primary Unit of Measure for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line
('Invalid Primary Unit of Measure for the item');
END;
-- ========================================
-- Validation for Secondary unit of measure
-- ========================================
IF items_rec.secondary_uom_code IS NOT NULL
THEN
BEGIN
SELECT uom_code
INTO v_s_uom_code
FROM mtl_units_of_measure
WHERE UPPER (uom_code) =
TRIM (UPPER (items_rec.secondary_uom_code));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Secondary Unit of Measure for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line
('Invalid Secondary Unit of Measure for the item');
END;
END IF;
-- ========================================
-- Validation for Category set name
-- ========================================
BEGIN
SELECT category_set_id
INTO v_category_set_id
FROM mtl_category_sets
WHERE (category_set_name) = 'CBL Item Category Set';
--TRIM(UPPER(items_rec.category_set_name));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Category Set Name for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line ('Invalid Category Set Name for the item');
END;
DBMS_OUTPUT.put_line ('Item Category Set ID is ' || v_category_set_id);
-- ========================================
-- Validation for Category name
-- ========================================
BEGIN
SELECT category_id
INTO v_category_id
FROM mtl_categories
WHERE UPPER (segment1) = TRIM (UPPER (items_rec.major_category))
AND UPPER (segment2) = TRIM (UPPER (items_rec.minor_category));
EXCEPTION
WHEN OTHERS
THEN
v_err_flag := 'E';
v_err_msg :=
v_err_msg
|| ','
|| 'Invalid Category Name for the item -- '
|| items_rec.item_segment;
DBMS_OUTPUT.put_line ('Invalid Category Name for the item');
END;
-- ========================================
-- Validation for START_AUTO_LOT_NUMBER
-- ========================================
BEGIN
IF items_rec.lot_control IS NULL
THEN
v_start_auto_lot_number := NULL;
ELSE
v_start_auto_lot_number := '01';
END IF;
END;
--========================================
-- Validation for TRACKING_QUANTITY_IND
-- ========================================
BEGIN
IF items_rec.secondary_uom_code IS NULL
THEN
v_tracking_quantity_ind := 'P';
ELSE
v_tracking_quantity_ind := 'PS';
l_bom_enabled_flag := 'N';
END IF;
END;
--========================================
-- Validation for LOT_CONTROL_CODE
-- ========================================
BEGIN
IF items_rec.lot_control IS NULL
THEN
v_lot_control := '1'; -- No Lot Control
ELSE
v_lot_control := '2'; -- Full Lot Control
END IF;
END;
--dbms_output.put_line('insert partout');
BEGIN
IF v_lot_control = '1'
THEN
v_lot_divisible_flag := 'N';
ELSE
v_lot_divisible_flag := 'Y';
END IF;
END;
BEGIN
IF items_rec.secondary_uom_code IS NULL
THEN
v_secondary_default_ind := '';
ELSE
v_secondary_default_ind := 'D';
END IF;
END;
BEGIN
IF UPPER (items_rec.make_buy) = 'MAKE'
THEN
v_planning_make_buy_code := 1;
ELSE
v_planning_make_buy_code := 2;
END IF;
END;
IF v_err_flag <> 'E'
THEN
INSERT INTO mtl_system_items_interface
(segment1,
description,
primary_uom_code,
secondary_uom_code,
template_name,
organization_id,
lot_control_code,
shelf_life_days,
auto_lot_alpha_prefix,
start_auto_lot_number,
planning_make_buy_code,
list_price_per_unit,
min_minmax_quantity,
max_minmax_quantity,
minimum_order_quantity,
maximum_order_quantity,
tracking_quantity_ind,
bom_enabled_flag,
ont_pricing_qty_source,
secondary_default_ind,
lot_divisible_flag,
process_flag,
transaction_type,
set_process_id,
creation_date,
created_by,
last_update_date,
last_updated_by
--SERIAL_NUMBER_CONTROL_CODE
)
VALUES (TRIM (items_rec.item_segment),
TRIM (items_rec.description),
v_p_uom_code,
TRIM (items_rec.secondary_uom_code),
v_template_name,
83, -- Master Org --v_organization_id,
v_lot_control, -- lot Control
(items_rec.shelf_life_days),
TRIM (items_rec.lot_prefix),
v_start_auto_lot_number,
v_planning_make_buy_code, -- Buy
items_rec.list_price,
(items_rec.min_stock),
(items_rec.max_stock),
0,
(items_rec.re_order_level),
v_tracking_quantity_ind,
l_bom_enabled_flag,
'P',
v_secondary_default_ind,
v_lot_divisible_flag,
1, -- Process flag
'CREATE', -- Transaction type
1, -- Set process id
SYSDATE, -- Creation date
1110, --fnd_profile.value('user_id'),
SYSDATE,
1110 -- fnd_profile.value('user_id')
--5 --l_serial_number_code -- define a variale
);
INSERT INTO mtl_item_categories_interface
(organization_id, process_flag, set_process_id,
transaction_type, item_number,
category_set_id, category_id, creation_date,
created_by, last_update_date, last_updated_by
)
VALUES (83, -- Master Org --v_organization_id ,
1, -- Process flag
1, -- Set process id
'CREATE', -- Transaction type
TRIM (items_rec.item_segment),
v_category_set_id, v_category_id, SYSDATE,
1110, --fnd_profile.value('user_id') ,
SYSDATE, 1110 --fnd_profile.value('user_id')
);
COMMIT;
UPDATE xx_item_import_stg
SET status_flag = 'P'
WHERE item_segment = items_rec.item_segment;
ELSE
UPDATE xx_item_import_stg
SETstatus_flag = 'E',
error_messege = v_err_msg
WHERE item_segment = items_rec.item_segment;
fnd_file.put_line (fnd_file.LOG, v_err_msg);
-- Inserting errors into log file.
COMMIT;
END IF;
END LOOP; -- Loop for validation
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
fnd_file.put_line (fnd_file.LOG,
' Error occured in the item validation process'
);
END; -- Main block Validation
END xx_item_import_pkg;
/

You might also like