Sie sind auf Seite 1von 38

In the previous versions we use below steps to create WEBADI :

1. Create package procedure and use that while registering the webadi.
2. Based on the no of parameters of the procedure, columns will be displayed in the webadi.
3. Basic validations will be done by package and in case of any error ,it will be shown in the
WEBADI
4. For doing any complex process (eg calling API) ,a concurrent program was provided that
validate all the unprocessed records from the table and provide the status in the output and log
files.
Limitation of previous version of WEBADI
Only single record validation is possible
In case of group of record validation , only concurrent program functionality can be used. In case
of any validation error for group of record validation it cant be shown on the WEBADI.
User need to manually run the concurrent program to validate the records.
There is no provision to validate only records of a specific session through concurrent program.
Concurrent program picks all the unprocessed record and processed.
WHO columns needs to be populate manually using code.

To resolve most of these issues below is the approach :


Lets take an example to upload EAM assets using WEBADI.
1. Create table XXINDUS_E269_EAM_WEBADI_TAB .Below is the detail.

CREATE TABLE XXINDUS.XXINDUS_E269_EAM_WEBADI_TAB


(
RECORD_ID NUMBER,
GROUP_ID NUMBER,
ASST_GRP_ITEM VARCHAR2(30 BYTE),
ASST_GRP_ITEM_ID NUMBER,
ASSET_SERIAL VARCHAR2(30 BYTE),
ORGANIZATION_CODE VARCHAR2(3 BYTE),
ORGANIZATION_ID NUMBER,
ASSET_COST NUMBER,
PARENT_ASSET VARCHAR2(30 BYTE),
PORGANIZATION_CODE VARCHAR2(3 BYTE),
PORGANIZATION_ID NUMBER,
PASST_GRP_ITEM_ID NUMBER,
PASSET_SERIAL VARCHAR2(30 BYTE),
LOCATION_CODE VARCHAR2(60 BYTE),
LOCATION_ID NUMBER,
FA_NUMBER VARCHAR2(100 BYTE),
FA_ID NUMBER,
CREATION_DATE DATE,
CREATED_BY NUMBER,
LAST_UPDATE_LOGIN NUMBER,
LAST_UPDATE_DATE DATE,
LAST_UPDATED_BY NUMBER,
STATUS VARCHAR2(10 BYTE),
REQUEST_ID NUMBER(15),
ERROR_NUM VARCHAR2(20 BYTE),
ERROR_MSG VARCHAR2(2000 BYTE),
STATUS_FLAG CHAR(1 BYTE),
ASSET_CATEGORY_ID NUMBER,
ITEM_TYPE VARCHAR2(240 BYTE),
FA_SYNC_FLAG VARCHAR2(10 BYTE),
TRX_ID NUMBER
)

Below is the details of some of the fields of the table :


a. RECORD_ID : Primary key of the table.Populated using trigger.
b. GROUP_ID : Populated from WEBADI.Same group_id for group of records.
c. TRX_ID : Populated from WEBADI.Key for WEBADI. Different for each and every record.

2. Register the table and its columns in the oracle application using AD_DD API.Below is the
sample code

CREATE OR REPLACE PACKAGE BODY APPS.xxindus_application_api_pkg --


--
-- **************************************************************************************
-- * *
-- * PL/SQL Package : APPS.XXINDUS_APPLICATION_API_PKG *
-- * Date : 12-MAY-2016 *
-- * Purpose : Package is used to register table and columns in application *
-- * *
-- *------------------------------------------------------------------------------------*
-- * Modifications : *
-- * *
-- * Version DD-MON-YYYY Person Changes Made *
-- * ---------- ------------- ------------ ----------------------------------------- *
-- * DRAFT1A 12-MAY-2016 Harsh Kansal Initial Draft Version *
-- * *
-- **************************************************************************************
--
--
IS
g_appl_short_name VARCHAR2 (30) := 'XXINDUS';

PROCEDURE xxindus_add_table (p_table VARCHAR2)


IS
CURSOR c_tabl
IS
SELECT *
FROM all_tables
WHERE table_name = p_table;

r_tabl c_tabl%ROWTYPE;
BEGIN
OPEN c_tabl;

FETCH c_tabl INTO r_tabl;

IF c_tabl%FOUND
THEN
ad_dd.register_table (p_appl_short_name => g_appl_short_name,
p_tab_name => r_tabl.table_name,
p_tab_type => 'T');
END IF;

CLOSE c_tabl;
END xxindus_add_table;

PROCEDURE xxindus_add_columns (p_table VARCHAR2,


p_column VARCHAR2 DEFAULT NULL)
IS
CURSOR c_tabl_column
IS
SELECT *
FROM all_tab_columns
WHERE table_name = p_table
AND column_name = NVL (p_column, column_name)
ORDER BY column_id;

ln_cnt NUMBER;
BEGIN
ln_cnt := 0;

FOR r_tabl_column IN c_tabl_column


LOOP
ln_cnt := ln_cnt + 1;
ad_dd.register_column (
p_appl_short_name => g_appl_short_name,
p_tab_name => r_tabl_column.table_name,
p_col_name => r_tabl_column.column_name,
p_col_seq => ln_cnt,
p_col_type => r_tabl_column.data_type,
p_col_width => r_tabl_column.data_length,
p_nullable => r_tabl_column.nullable,
p_translate => 'Y',
p_precision => r_tabl_column.data_precision,
p_scale => r_tabl_column.data_scale);
END LOOP;
END xxindus_add_columns;

PROCEDURE xxindus_del_table (p_table VARCHAR2)


IS
CURSOR c_tabl
IS
SELECT *
FROM all_tables
WHERE table_name = p_table;

r_tabl c_tabl%ROWTYPE;
BEGIN
OPEN c_tabl;

FETCH c_tabl INTO r_tabl;

IF c_tabl%FOUND
THEN
ad_dd.delete_table (p_appl_short_name => g_appl_short_name,
p_tab_name => r_tabl.table_name);
END IF;

CLOSE c_tabl;
END xxindus_del_table;

PROCEDURE xxindus_del_columns (p_table VARCHAR2,


p_column VARCHAR2 DEFAULT NULL)
IS
CURSOR c_tabl_column
IS
SELECT *
FROM all_tab_columns
WHERE table_name = p_table
AND column_name = NVL (p_column, column_name);
BEGIN
FOR r_tabl_column IN c_tabl_column
LOOP
ad_dd.delete_column (
p_appl_short_name => g_appl_short_name,
p_tab_name => r_tabl_column.table_name,
p_col_name => r_tabl_column.column_name);
END LOOP;
END xxindus_del_columns;
END xxindus_application_api_pkg;

3. Go to Desktop Integration Manager responsibility.Click on Manage Integrators


4. Provide Integrator name and internal name details and click on next button.
5. Click on Create Interface button and create a new interface.Provide Interface type as Table
and provide table name.Table will come in the LOV only if that has been register in the
application from AD_DD API.Click on submit button.

6. Now this will come in the interface list.When we click on select radio button it will show all the
fields details of that table.
7. Now unselect displayed checkbox all the fields for which we dont want to display In WEBADI
layout.
8. Automatically WHO columns default values will be populated .

9. Provide sequence name (eg. xxindus_e269_eam_webadi_s) in the default value of Trx_id.Click


on update button and check Required (To be included in all layouts) and Enabled for Mapping
.Trx_id is the unique key of the table.
10. Run below update statement to update default type value of trx_id
update bne_interface_cols_b
set DEFAULT_TYPE = 'SEQUENCE_EACH_ROW'
where interface_code = <<interface_name>>
AND INTERFACE_COL_NAME ='TRX_ID'
There is no way to update default_type from front end application as value
'SEQUENCE_EACH_ROW'.After update backend value will be 'SEQUENCE_EACH_ROW'
but from front end it will show blank.

11. Click on the next and find out Group_id field.Group_id field value will be same for all records of
each run .In the default type select SQL Query and in default value field give SELECT
xxindus_e269_eam_webadi_s.NEXTVAL FROM DUAL

Click on update pencil button and check Required (To be included in all layouts) and Enabled
for Mapping .Trx_id is the unique key of the table.
12. Click on next button.Nothing is required.Click on next button.

13. Create an uploader .Automatically four parameters will be created.

14. In First parameter bne:rows,click on update button.

15. In the Default value field provide below values and click on Apply button.
a. String : FLAGGED
b. Description : Flagged Rows
16. Click on update button of bne:validation and check values as per below screenshot

17 . Click on update button of bne:import and check values as per below screenshot
18 . Click on update button of bne:commitrows and check values as per below screenshot

In the Default value field provide below values and click on Apply button.
String : EACH_ROW
Description : Each Row

19. Click on Next button and select Importer type as PL/SQL API and provide importer name
20. Click on Group definition update pencil button and provide GROUP_ID in the interface attribute
and click on apply button.

21. Click on Document Row : Interface Attribute Mapping update pencil button and provide key
fields details of the records and click on apply.
22. Click on PL/SQL API call update pencil button.Select API type as PL/SQL Procedure and
provide package name and procedure names.Keep API returns blank.It will automatically
populate parameters of the API.

P_Group_id is the IN parameter and P_REQ_ID is OUT parameter.P_GROUP_ID will same for
each record of that group.In the API, based on P_GROUP_ID field, we validate the records and if
every thing will be fine then run a concurrent program that will call seeded API to create EAM
asset.Request id will be returned using that OUT parameter.

In the above screenshot ,set Source as Import and value as and click on APPLY button.

P_GROUP_ID : XXINDUS_E269_EAM_WEBADI_TAB.GROUP_ID
P_REQ_ID : P_REQ_ID

23. Click on Error Row Definition update pencil button and provide below details
SQL Query : SELECT * FROM XXINDUS_E269_EAM_WEBADI_TAB WHERE ERROR_NUM LIKE 'ERR
%' AND GROUP_ID =$PARAM$.P_GROUP_ID_NUM

Set parameter source as Import and Value as XXINDUS_E269_EAM_WEBADI_TAB.GROUP_ID


and click on APPLY button.

20. Click on Error Message Lookup update pencil button and provide below details
SQL Query : SELECT distinct ERROR_MSG FROM XXINDUS_E269_EAM_WEBADI_TAB
WHERE GROUP_ID = $PARAM$.P_GROUP_ID AND ERROR_NUM=$PARAM$.P_ERROR_NUM

Provide reference name as ERROR_MSG and parmeter source as Interface table and value as and
click on APPLY button.

P_GROUP_ID : XXINDUS_E269_EAM_WEBADI_TAB.GROUP_ID
P_ERROR_NUM : XXINDUS_E269_EAM_WEBADI_TAB.ERROR_NUM

21. Click on Success Message Definition update pencil button and provide below details and click
on APPLY button
Success Message :
Request ID $IMPORT$.P_REQ_ID submitted for Concurrent program Indus EAM asset Import
Program

22. Click on Submit button.


23. Now to defined Layout ,query the integrator and select the integrator and click on Define
Layout Button.

24. On the next screen provide the layout name and click on next.

25. On the next screen ,select Line in the field placement and select the checkbox of the items those
we want to display in the webadi and click on next.
26. Use the fields move up and move down to set the layout and change the width as per the
requirement and click on apply.

27. Register integrator using form function : Go to function form (using application developer or
system administrator responsibility) and register a function.Below are the additional fields details
other than mandatory fields

Type : SSWA servlet function


Parameters : bne:page=BneCreateDoc&bne:viewer=BNE:EXCEL
%25&bne:integrator=500:<<Integrator_name>>&bne:reporting=N
SSWA servlet function
HTML Call : BneApplicationService

To get the integrator code use below sql

select INTEGRATOR_CODE from bne_integrators_tl


where user_name like <<Integrator name>>
Attached the function in the menu and attached the menu in the responsibility. Before using the
WEBADI ,clear the cache from functional administrator responsibility.

28. Sample data upload


Limitation of the design :
1. Validation failure in the concurrent program cant be displayed in the webadi. From WEBADI
prospective its successful. Concurrent program errors can be displayed in the out put and log
file.
Sample package code
CREATE OR REPLACE PACKAGE BODY APPS.xxindus_e269_eam_webadi_pkg
IS
/* API to print log messages in concurrent program log*/
PROCEDURE log_msg (p_msg VARCHAR2)
IS
BEGIN
fnd_file.put_line (fnd_file.LOG, p_msg);
DBMS_OUTPUT.put_line (p_msg);
END log_msg;

/* API to print output messages in concurrent program output*/


PROCEDURE output_msg (p_msg VARCHAR2)
IS
BEGIN
fnd_file.put_line (fnd_file.output, p_msg);
DBMS_OUTPUT.put_line (p_msg);
END output_msg;

PROCEDURE xxindus_change_oat_status_prc (
p_instance_id csi_item_instances.instance_id%TYPE,
p_location_id NUMBER,
p_type IN NUMBER)
IS
l_location_type_code csi_item_instances.location_type_code%TYPE;
l_location_id csi_item_instances.location_id%TYPE;
l_instance_usage_code csi_item_instances.instance_usage_code%TYPE;
l_operational_status_code csi_item_instances.operational_status_code%TYPE;
l_instance_tbl cse_deployment_grp.txn_instances_tbl;
l_dest_location_tbl cse_deployment_grp.dest_location_tbl;
l_ext_attrib_values_tbl cse_deployment_grp.txn_ext_attrib_values_tbl;
l_txn_tbl cse_deployment_grp.transaction_tbl;
l_transaction_type_id csi_txn_types.transaction_type_id%TYPE;
l_txn_sub_type_id csi_transactions.txn_sub_type_id%TYPE;
l_return_status VARCHAR2 (1) := fnd_api.g_ret_sts_success;
l_error_message VARCHAR2 (2000);

CURSOR c_oat_detals
IS
SELECT cii.instance_id,
cii.serial_number,
cii.lot_number,
cii.inventory_item_id,
cii.operational_status_code,
cii.location_type_code,
cii.location_id,
cii.instance_usage_code,
cii.quantity,
cii.unit_of_measure,
NULL pa_project_id,
NULL pa_project_task_id
FROM csi_item_instances cii
WHERE cii.instance_id = p_instance_id;

cr_oat_detals c_oat_detals%ROWTYPE;
BEGIN
OPEN c_oat_detals;

FETCH c_oat_detals INTO cr_oat_detals;

CLOSE c_oat_detals;

IF cr_oat_detals.instance_id IS NOT NULL


THEN
l_instance_tbl (1).instance_id := cr_oat_detals.instance_id;
l_instance_tbl (1).serial_number := cr_oat_detals.serial_number;
l_instance_tbl (1).lot_number := cr_oat_detals.lot_number;
l_instance_tbl (1).inventory_item_id :=
cr_oat_detals.inventory_item_id;
l_instance_tbl (1).operational_status_code :=
cr_oat_detals.operational_status_code;

BEGIN
IF p_type = 1
THEN
SELECT ctt.transaction_type_id, cts.sub_type_id
INTO l_transaction_type_id, l_txn_sub_type_id
FROM csi_txn_types ctt, csi_txn_sub_types cts
WHERE ctt.transaction_type_id = cts.transaction_type_id
AND ctt.source_transaction_type = 'IN_SERVICE';
ELSE
SELECT ctt.transaction_type_id, cts.sub_type_id
INTO l_transaction_type_id, l_txn_sub_type_id
FROM csi_txn_types ctt, csi_txn_sub_types cts
WHERE ctt.transaction_type_id = cts.transaction_type_id
AND ctt.source_transaction_type = 'ITEM_INSTALLED';
END IF;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_transaction_type_id := NULL;
l_txn_sub_type_id := NULL;
log_msg (
'Error Place:=> At Fetching OAT Transaction Type And Sub Type No Data - '
|| CHR (10)
|| 'Error Line :=>'
|| DBMS_UTILITY.format_error_backtrace
|| CHR (10)
|| 'Error:'
|| SUBSTR (SQLERRM, 1, 200));
WHEN OTHERS
THEN
log_msg (
'Error Place:=> At Fetching OAT Transaction Type And Sub Type - '
|| CHR (10)
|| 'Error Line :=>'
|| DBMS_UTILITY.format_error_backtrace
|| CHR (10)
|| 'Error:'
|| SUBSTR (SQLERRM, 1, 200));
END;
IF p_type = 1
THEN
l_instance_tbl (1).active_start_date := SYSDATE;
END IF;

l_txn_tbl (1).transaction_id := fnd_api.g_miss_num;


l_txn_tbl (1).source_transaction_date := SYSDATE;
l_txn_tbl (1).transaction_date := SYSDATE;
l_txn_tbl (1).transaction_type_id := l_transaction_type_id;
l_txn_tbl (1).txn_sub_type_id := l_txn_sub_type_id;
l_txn_tbl (1).source_group_ref_id := fnd_api.g_miss_num;
l_txn_tbl (1).source_group_ref := fnd_api.g_miss_char;
l_txn_tbl (1).source_header_ref_id := fnd_api.g_miss_num;
l_txn_tbl (1).source_header_ref := fnd_api.g_miss_char;
l_txn_tbl (1).transacted_by := fnd_api.g_miss_num;
l_txn_tbl (1).transaction_quantity := cr_oat_detals.quantity;
l_txn_tbl (1).operational_flag := 'Y';
l_txn_tbl (1).financial_flag := 'Y';
l_dest_location_tbl (1).parent_tbl_index := 1;
l_dest_location_tbl (1).location_type_code := 'HZ_LOCATIONS';
l_dest_location_tbl (1).location_id := p_location_id; l_dest_location_tbl (1).instance_usage_code :=
cr_oat_detals.instance_usage_code;
l_dest_location_tbl (1).operational_status_code :=
cr_oat_detals.operational_status_code;

BEGIN
cse_deployment_grp.process_transaction (
p_instance_tbl => l_instance_tbl,
p_dest_location_tbl => l_dest_location_tbl,
p_ext_attrib_values_tbl => l_ext_attrib_values_tbl,
p_txn_tbl => l_txn_tbl,
x_return_status => l_return_status,
x_error_msg => l_error_message);

IF l_return_status <> fnd_api.g_ret_sts_success


THEN
log_msg (
'Error Place:=> At Calling Process Transaction API Prc in InService Prc - '
|| CHR (10)
|| 'Error Message :=>'
|| l_error_message
|| CHR (10)
|| 'Error Status:'
|| l_return_status);
ROLLBACK;
ELSE
SELECT operational_status_code
INTO l_error_message FROM csi_item_instances
WHERE instance_id = p_instance_id;

log_msg (
'Retrun Status from In Service Procedure:=>'
|| l_error_message );
END IF;
EXCEPTION
WHEN OTHERS
THEN
log_msg (
'Error Place:=> At Calling OAT Process Transaction Procedure - '
|| CHR (10)
|| 'Error Line :=>'
|| DBMS_UTILITY.format_error_backtrace
|| CHR (10)
|| 'Error:'
|| SUBSTR (SQLERRM, 1, 200));
END;
ELSE
log_msg (
'No Details Found to Put In Serivce in OAT for the Instance id:=>'
|| p_instance_id);
END IF;
EXCEPTION
WHEN OTHERS
THEN
log_msg (
'Error Place:=> In xxindus_e052_inservice_oat_prc main Exception- '
|| CHR (10)
|| 'Error Line :=>'
|| DBMS_UTILITY.format_error_backtrace
|| CHR (10)
|| 'Error Message:'
|| SUBSTR (SQLERRM, 1, 200));
END xxindus_change_oat_status_prc;

FUNCTION get_item_info (p_item IN VARCHAR2,


p_item_type OUT VARCHAR2,
p_qr_code_enabled OUT VARCHAR2)
RETURN NUMBER
IS
l_item_id NUMBER;
l_item_type VARCHAR2 (240);
l_qr_code_enabled VARCHAR2 (10);
BEGIN
BEGIN
SELECT inventory_item_id, attribute16, attribute8
INTO l_item_id, l_item_type, l_qr_code_enabled
FROM mtl_system_items_b
WHERE segment1 = p_item
AND organization_id = xxindus_util_pkg.get_master_inv_id;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

p_item_type := l_item_type;
RETURN l_item_id;
END get_item_info;

FUNCTION get_organization_info (p_organization VARCHAR2)


RETURN NUMBER
IS
l_organization_id NUMBER;
BEGIN
BEGIN
SELECT organization_id
INTO l_organization_id
FROM mtl_parameters
WHERE organization_code = p_organization;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

RETURN l_organization_id;
END get_organization_info;

FUNCTION get_location_info (p_location VARCHAR2)


RETURN NUMBER
IS
l_location_id NUMBER;
BEGIN
BEGIN
SELECT location_id
INTO l_location_id
FROM hz_locations
WHERE clli_code = p_location;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

RETURN l_location_id;
END get_location_info;

FUNCTION get_fa_asset_info (p_asset_number IN VARCHAR2,


p_asset_category_id OUT NUMBER)
RETURN NUMBER
IS
l_asset_id NUMBER;
l_asset_category_id NUMBER;
BEGIN
BEGIN
SELECT asset_id, asset_category_id
INTO l_asset_id, l_asset_category_id
FROM fa_additions_b
WHERE asset_number = p_asset_number;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

p_asset_category_id := l_asset_category_id;
RETURN l_asset_id;
END get_fa_asset_info;

FUNCTION check_bom_info (p_item_id IN NUMBER,


p_organization_id IN NUMBER,
p_pitem_id IN NUMBER,
p_qty OUT NUMBER)
RETURN NUMBER
IS
l_qty NUMBER;
l_flag VARCHAR2 (1) := 'N';
BEGIN
BEGIN
SELECT bic.component_quantity, 'Y'
INTO l_qty, l_flag
FROM bom_bill_of_materials bom, bom_inventory_components bic
WHERE bic.bill_sequence_id = bom.common_bill_sequence_id
AND SYSDATE <= NVL (bic.disable_date, SYSDATE + 1)
AND bom.assembly_item_id = p_pitem_id
AND bom.organization_id = p_organization_id
AND bic.component_item_id = p_item_id;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

p_qty := l_qty;
RETURN l_flag;
END check_bom_info;

PROCEDURE get_parent_asset_info (p_instance_number IN VARCHAR2,


p_porganization_code OUT VARCHAR2,
p_porganization_id OUT NUMBER,
p_pinventory_item_id OUT NUMBER,
p_pserial_number OUT VARCHAR2)
IS
l_asset_id NUMBER;
BEGIN
BEGIN
SELECT inventory_item_id,
serial_number,
current_organization_id,
inv_organization_code
INTO p_pinventory_item_id,
p_pserial_number,
p_porganization_id,
p_porganization_code
FROM mtl_eam_asset_numbers_all_v
WHERE instance_number = p_instance_number;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
END get_parent_asset_info;

FUNCTION check_asset_exists (p_inventory_item_id IN NUMBER,


p_serial_number IN VARCHAR2
)
RETURN VARCHAR2
IS
l_flag VARCHAR2 (1) := 'N';
BEGIN
BEGIN
SELECT 'Y'
INTO l_flag
FROM mtl_eam_asset_numbers_all_v
WHERE ( (1 = 1 AND serial_number = p_serial_number)
);
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

RETURN l_flag;
END check_asset_exists;

FUNCTION validate_asset_eam_loc (p_asset_id IN NUMBER,


p_location IN VARCHAR2)
RETURN VARCHAR2
IS
l_flag VARCHAR2 (1) := 'N';
BEGIN
BEGIN
SELECT 'Y'
INTO l_flag
FROM fa_distribution_history b, fa_locations c
WHERE b.asset_id = p_asset_id
AND b.transaction_header_id_out IS NULL
AND c.location_id = b.location_id
AND c.segment3 = p_location
AND ROWNUM = 1;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

RETURN l_flag;
END validate_asset_eam_loc;

FUNCTION validate_asset_eam_serial (p_asset_id IN NUMBER,


p_serial IN VARCHAR2)
RETURN VARCHAR2
IS
l_flag VARCHAR2 (1) := 'N';
BEGIN
BEGIN
SELECT 'Y'
INTO l_flag
FROM fa_additions_b
WHERE asset_id = p_asset_id
AND serial_number = p_serial
AND ROWNUM = 1;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;

RETURN l_flag;
END validate_asset_eam_serial;

PROCEDURE xxindus_create_eam_asset_prc (
p_item_id IN NUMBER,
p_serial_number IN VARCHAR2,
p_organization_id IN NUMBER,
p_organization_code IN VARCHAR2,
p_porganization_code IN VARCHAR2,
p_porganization_id IN NUMBER,
p_pitem_id IN NUMBER,
p_pserial_number IN VARCHAR2,
p_add_batch_id IN NUMBER,
p_cost IN NUMBER,
p_location IN NUMBER,
p_fa_asset_id IN NUMBER,
p_asset_category_id IN NUMBER,
p_fa_sync_flag IN VARCHAR2,
p_rel_flag OUT VARCHAR2,
p_status_flag OUT VARCHAR2)
IS
l_return_status VARCHAR2 (1000);
l_msg_count NUMBER;
l_msg_data VARCHAR2 (1000);
l_object_id NUMBER;
l_api_error_msg VARCHAR2 (2000);
l_rel_flag VARCHAR2 (1) := 'N';
l_user_id NUMBER;
l_status_flag VARCHAR2 (1) := 'N';
l_instance_id NUMBER;
BEGIN
l_user_id := fnd_global.user_id;

log_msg ('p_item_id>' || p_item_id);


log_msg ('p_serial_number>' || p_serial_number);

eam_assetnumber_pub.insert_asset_number (
p_api_version => 1.0,
p_init_msg_list => fnd_api.g_true,
p_commit => fnd_api.g_false,
p_validation_level => fnd_api.g_valid_level_full,
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
x_object_id => l_object_id,
p_inventory_item_id => p_item_id,
p_serial_number => p_serial_number,
p_instance_number => csi_item_instances_s.NEXTVAL,
p_current_status => 3,
p_descriptive_text => '',
p_current_organization_id => p_organization_id,
p_wip_accounting_class_code => NULL,
p_maintainable_flag => NULL,
p_owning_department_id => NULL,
p_network_asset_flag => NULL,
p_fa_asset_id => p_fa_asset_id,
p_pn_location_id => NULL,
p_eam_location_id => NULL,
p_asset_criticality_code => NULL,
p_category_id => NULL, p_fa_sync_flag => p_fa_sync_flag,
p_prod_organization_id => NULL,
p_equipment_item_id => NULL,
p_eqp_serial_number => NULL,
p_equipment_gen_object_id => NULL,
p_eam_linear_id => NULL,
p_attribute6 => p_cost,
p_location => p_location,
p_instantiate_flag => TRUE,
p_active_start_date => SYSDATE,
p_active_end_date => SYSDATE);

log_msg ('l_Return_Status ' || l_return_status);


log_msg ('l_Msg_Count ' || l_msg_count);
log_msg ('l_Msg_Data ' || l_msg_data);

IF NVL (l_return_status, fnd_api.g_ret_sts_error) <>


fnd_api.g_ret_sts_success
THEN
IF l_msg_count > 1
THEN
FOR i IN 1 .. l_msg_count
LOOP
l_api_error_msg :=
i
|| '. '
|| SUBSTR (fnd_msg_pub.get (p_encoded => fnd_api.g_false),
1,
350);
log_msg ('l_api_error_msg>' || l_api_error_msg);
l_status_flag := 'Y';
END LOOP;
END IF;
ELSE
BEGIN
SELECT instance_id
INTO l_instance_id
FROM csi_item_instances
WHERE inventory_item_id = p_item_id
AND serial_number = p_serial_number;
EXCEPTION
WHEN OTHERS
THEN
l_instance_id := NULL;
log_msg ('OAT asset not found');
END;

IF l_instance_id IS NOT NULL


THEN
log_msg ('Calling OAT asset API to change status Install');
xxindus_e269_eam_webadi_pkg.xxindus_change_oat_status_prc (
l_instance_id,
p_location,
0);
log_msg ('Calling OAT asset API to change status InService');
xxindus_e269_eam_webadi_pkg.xxindus_change_oat_status_prc (
l_instance_id,
p_location,
1);
END IF;

IF p_pitem_id IS NOT NULL


THEN
-- processed
BEGIN
l_rel_flag := 'Y';

INSERT
INTO mtl_object_genealogy_interface (interface_header_id,
last_update_date,
last_updated_by,
creation_date,
created_by,
batch_id,
GROUP_ID,
object_type,
parent_object_type,
genealogy_origin,
genealogy_type,
process_status,
import_mode,
organization_id,
organization_code,
parent_organization_code,
inventory_item_id,
serial_number,
parent_organization_id,
parent_inventory_item_id,
parent_serial_number,
start_date_active)
VALUES (mtl_object_gen_interface_s.NEXTVAL,
SYSDATE,
l_user_id,
SYSDATE,
l_user_id,
p_add_batch_id,
NULL,
2,
2,
3,
5,
'P',
0,
p_organization_id,
p_organization_code,
p_porganization_code,
p_item_id,
p_serial_number,
p_porganization_id,
p_pitem_id,
p_pserial_number,
SYSDATE);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
NULL;
END;
END IF;
END IF;

p_rel_flag := l_rel_flag;
p_status_flag := l_status_flag;
END xxindus_create_eam_asset_prc;

PROCEDURE xxindus_process_eam_asset_prc (retcode OUT NUMBER,


errbuf OUT VARCHAR2,
p_group_id IN NUMBER)
IS
CURSOR c_validated_record
IS
SELECT *
FROM xxindus_e269_eam_webadi_tab
WHERE GROUP_ID = p_group_id
FOR UPDATE OF error_num, error_msg;

l_batch_id NUMBER;
l_rel_flag VARCHAR2 (1);
l_rel_flag_t VARCHAR2 (1) := 'N';
l_request_id NUMBER;
l_phase VARCHAR2 (100);
l_status VARCHAR2 (100);
l_dev_phase VARCHAR2 (100);
l_dev_status VARCHAR2 (100);
l_message VARCHAR2 (1000);
l_req_return_status BOOLEAN;
l_request_submission VARCHAR2 (1);
l_user_id NUMBER;
l_resp_id NUMBER;
l_resp_appl_id NUMBER;
l_status_flag VARCHAR2 (1);
BEGIN
l_batch_id := xxindus_e269_eam_webadi_s.NEXTVAL;
l_user_id := fnd_global.user_id;
l_resp_id := fnd_global.resp_id;
l_resp_appl_id := fnd_global.resp_appl_id;
fnd_global.apps_initialize (user_id => l_user_id,
resp_id => l_resp_id,
resp_appl_id => l_resp_appl_id);

FOR cr_validated_record IN c_validated_record


LOOP
l_rel_flag := NULL;
l_status_flag := NULL;
xxindus_create_eam_asset_prc (
p_item_id => cr_validated_record.asst_grp_item_id,
p_serial_number => cr_validated_record.asset_serial,
p_organization_id => cr_validated_record.organization_id,
p_organization_code => cr_validated_record.organization_code,
p_porganization_code => cr_validated_record.porganization_code,
p_porganization_id => cr_validated_record.porganization_id,
p_pitem_id => cr_validated_record.passt_grp_item_id,
p_pserial_number => cr_validated_record.passet_serial,
p_add_batch_id => l_batch_id,
p_cost => cr_validated_record.asset_cost,
p_location => cr_validated_record.location_id,
p_fa_asset_id => cr_validated_record.fa_id,
p_asset_category_id => cr_validated_record.asset_category_id,
p_fa_sync_flag => cr_validated_record.fa_sync_flag,
p_rel_flag => l_rel_flag,
p_status_flag => l_status_flag);

IF l_rel_flag = 'Y'
THEN
l_rel_flag_t := l_rel_flag;
END IF;

IF l_status_flag = 'Y'
THEN
UPDATE xxindus_e269_eam_webadi_tab
SET error_num = 'ERR100',
error_msg = 'API ERROR',
last_update_login = fnd_global.login_id,
last_update_date = SYSDATE,
last_updated_by = fnd_global.user_id
WHERE CURRENT OF c_validated_record;
ELSE
UPDATE xxindus_e269_eam_webadi_tab
SET error_num = 'PRC',
error_msg = 'Processed',
last_update_login = fnd_global.login_id,
last_update_date = SYSDATE,
last_updated_by = fnd_global.user_id
WHERE CURRENT OF c_validated_record;
END IF;
END LOOP;

IF l_rel_flag_t = 'Y'
THEN
l_request_id :=
fnd_request.submit_request (application => 'EAM',
program => 'EAMGEIMP',
description => NULL,
start_time => SYSDATE,
sub_request => FALSE,
argument1 => l_batch_id,
argument2 => 'N');
COMMIT;

IF l_request_id = 0
THEN
log_msg (
'Request Not Submitted due to "' || fnd_message.get || '".');
ELSE
log_msg (
'The Program PROGRAM_1 submitted successfully Request id :'
|| l_request_id);

LOOP
--To make process execution to wait for 1st program to complete
l_req_return_status :=
fnd_concurrent.wait_for_request (
request_id => l_request_id,
interval => 2,
max_wait => 120,
phase => l_phase,
status => l_status,
dev_phase => l_dev_phase,
dev_status => l_dev_status,
MESSAGE => l_message);
EXIT WHEN UPPER (l_phase) = 'COMPLETED'
OR UPPER (l_status) IN ('CANCELLED',
'ERROR',
'TERMINATED');
END LOOP;
END IF;
END IF;
END xxindus_process_eam_asset_prc;

PROCEDURE xxindus_eam_asset_webadi_prc (p_group_id IN NUMBER,


p_req_id OUT NUMBER)
IS
CURSOR c_get_record
IS
SELECT *
FROM xxindus_e269_eam_webadi_tab
WHERE GROUP_ID = p_group_id
FOR UPDATE OF error_num, error_msg;
l_asset_id NUMBER;
l_location_id NUMBER;
l_organization_id NUMBER;
l_item_id NUMBER;
l_already_exists VARCHAR2 (1);
l_porganization_code VARCHAR2 (100);
l_porganization_id NUMBER;
l_pinventory_item_id NUMBER;
l_pserial_number VARCHAR2 (100);
l_err_num VARCHAR2 (30);
l_err_msg VARCHAR2 (100);
l_error_flag NUMBER := 0;
l_user_id NUMBER;
l_resp_id NUMBER;
l_resp_appl_id NUMBER;
l_request_id NUMBER;
l_item_type VARCHAR2 (240);
l_asset_category_id NUMBER;
l_fa_sync_flag VARCHAR2 (1);
l_match_exists VARCHAR2 (1);
l_flag NUMBER;
l_qr_code_enabled VARCHAR2 (10);
l_bom_exists VARCHAR2 (1);
l_bom_qty NUMBER;
l_total_asset NUMBER;
BEGIN
FOR cr_get_record IN c_get_record
LOOP
l_asset_id := NULL;
l_location_id := NULL;
l_organization_id := NULL;
l_item_id := NULL;
l_already_exists := NULL;
l_porganization_code := NULL;
l_porganization_id := NULL;
l_pinventory_item_id := NULL;
l_pserial_number := NULL;
l_err_num := NULL;
l_err_msg := NULL;
l_item_type := NULL;
l_asset_category_id := NULL;
l_fa_sync_flag := NULL;
l_match_exists := NULL;
l_flag := NULL;
l_qr_code_enabled := NULL;
l_bom_exists := NULL;
l_bom_qty := NULL;
l_total_asset := NULL;

IF cr_get_record.asst_grp_item IS NOT NULL


THEN
l_item_id :=
get_item_info (p_item => cr_get_record.asst_grp_item,
p_item_type => l_item_type,
p_qr_code_enabled => l_qr_code_enabled);
IF l_item_id IS NULL
THEN
l_err_num := 'ERR001.1';
l_err_msg := 'Invalid Item Code';
END IF;
ELSE
l_err_num := 'ERR001';
l_err_msg := 'Item Code is blank';
END IF;

IF l_err_num IS NULL
THEN
IF cr_get_record.asset_serial IS NULL
THEN
l_err_num := 'ERR002';
l_err_msg := 'Asset serial is blank';
ELSIF l_qr_code_enabled = 'Y'
AND LENGTH (cr_get_record.asset_serial) <> 11
THEN
l_err_num := 'ERR002.2';
l_err_msg := 'QR Coded Item must be of 11 digits';
END IF;
END IF;

IF cr_get_record.organization_code IS NOT NULL AND l_err_num IS NULL


THEN
l_organization_id :=
get_organization_info (
p_organization => cr_get_record.organization_code);

IF l_organization_id IS NULL
THEN
l_err_num := 'ERR003';
l_err_msg := 'Invalid Organization';
END IF;
ELSIF l_err_num IS NULL
THEN
l_err_num := 'ERR003.1';
l_err_msg := 'Organization is blank';
END IF;

IF cr_get_record.location_code IS NOT NULL AND l_err_num IS NULL


THEN
l_location_id :=
get_location_info (p_location => cr_get_record.location_code);

IF l_location_id IS NULL
THEN
l_err_num := 'ERR004';
l_err_msg := 'Invalid Site Id';
END IF;
ELSIF l_err_num IS NULL
THEN
l_err_num := 'ERR004.1';
l_err_msg := 'Site Id is null';
END IF;
IF cr_get_record.fa_number IS NOT NULL AND l_err_num IS NULL
THEN
l_asset_id :=
get_fa_asset_info (
p_asset_number => cr_get_record.fa_number,
p_asset_category_id => l_asset_category_id);

IF l_asset_id IS NULL
THEN
l_err_num := 'ERR005';
l_err_msg := 'Invalid FA Asset';
END IF;
ELSIF l_err_num IS NULL
THEN
l_err_num := 'ERR005.1';
l_err_msg := 'FA Asset is blank';
END IF;

IF l_err_num IS NULL
THEN
IF cr_get_record.asset_cost <= 0
THEN
l_err_num := 'ERR005.6';
l_err_msg := 'Invalid Cost';
END IF;
END IF;

IF l_item_id IS NOT NULL


AND cr_get_record.asset_serial IS NOT NULL
AND l_err_num IS NULL
THEN
l_already_exists :=
check_asset_exists (
p_inventory_item_id => l_item_id,
p_serial_number => cr_get_record.asset_serial
);

IF l_already_exists = 'Y'
THEN
l_err_num := 'ERR005.2';
l_err_msg :=
'Item and serial combination already exists in EAM';
END IF;
END IF;

IF l_asset_id IS NOT NULL AND l_err_num IS NULL


THEN
l_match_exists :=
validate_asset_eam_loc (
p_asset_id => l_asset_id,
p_location => cr_get_record.location_code);

IF l_match_exists = 'N'
THEN
l_err_num := 'ERR007';
l_err_msg :=
'FA asset location and EAM Site location not matching';
END IF;
END IF;

IF l_err_num IS NULL
THEN
IF l_asset_id IS NOT NULL
THEN
l_match_exists :=
validate_asset_eam_serial (
p_asset_id => l_asset_id,
p_serial => cr_get_record.asset_serial);

IF l_match_exists = 'N'
THEN
l_err_num := 'ERR007.6';
l_err_msg := 'FA asset serial and EAM serial not matching';
END IF;
END IF;
END IF;

IF cr_get_record.parent_asset IS NOT NULL AND l_err_num IS NULL


THEN
get_parent_asset_info (
p_instance_number => cr_get_record.parent_asset,
p_porganization_code => l_porganization_code,
p_porganization_id => l_porganization_id,
p_pinventory_item_id => l_pinventory_item_id,
p_pserial_number => l_pserial_number);

IF l_pinventory_item_id IS NULL
THEN
l_err_num := 'ERR006';
l_err_msg := 'Invalid Parent asset';
END IF;
END IF;

IF l_err_num IS NULL
THEN
IF l_pinventory_item_id IS NOT NULL
THEN
-- parent item exists check BOM

l_bom_exists :=
check_bom_info (p_item_id => l_item_id,
p_organization_id => l_organization_id,
p_pitem_id => l_pinventory_item_id,
p_qty => l_bom_qty);

IF l_bom_exists = 'N'
THEN
-- parent chaild mapping not exists in BOM
l_err_num := 'ERR010';
l_err_msg := 'Parent Child mapping not exists in BOM';
ELSIF l_bom_exists = 'Y'
THEN
BEGIN
SELECT SUM (total_asset)
INTO l_total_asset
FROM (SELECT COUNT (*) total_asset
FROM xxindus_e269_eam_webadi_tab a
WHERE asst_grp_item || organization_code IN (SELECT asst_grp_item
|| organization_code
FROM xxindus_e269_eam_webadi_tab a
WHERE record_id =
cr_get_record.record_id)
AND a.GROUP_ID = cr_get_record.GROUP_ID
UNION ALL
SELECT COUNT (*) total_asset
FROM mtl_eam_asset_numbers_all_v
WHERE inventory_item_id = l_item_id
AND current_organization_id =
l_organization_id);

IF NVL (l_bom_qty, 0) < NVL (l_total_asset, 0)


THEN
l_err_num := 'ERR010.1';
l_err_msg := 'Parent Child limit exceed from BOM';
END IF;
END;

NULL;
END IF;
END IF;
END IF;

IF l_err_num IS NULL
THEN
BEGIN
SELECT COUNT (*)
INTO l_flag
FROM xxindus_e269_eam_webadi_tab a
WHERE EXISTS
(SELECT NULL
FROM xxindus_e269_eam_webadi_tab b
WHERE b.GROUP_ID = a.GROUP_ID
AND b.trx_id <> a.trx_id
AND b.record_id <> a.record_id
AND b.asset_serial = a.asset_serial
AND b.asst_grp_item = a.asst_grp_item)
AND record_id = cr_get_record.record_id;

IF l_flag > 0
THEN
l_err_num := 'ERR007.1';
l_err_msg := 'Duplicate records';
END IF;
END;
END IF;
IF l_err_num IS NOT NULL
THEN
UPDATE xxindus_e269_eam_webadi_tab
SET error_num = l_err_num,
error_msg = l_err_msg,
last_update_login = fnd_global.login_id,
last_update_date = SYSDATE,
last_updated_by = fnd_global.user_id
WHERE CURRENT OF c_get_record;

l_error_flag := l_error_flag + 1;
ELSE
IF l_asset_id IS NOT NULL
THEN
l_fa_sync_flag := 'Y';
ELSE
l_fa_sync_flag := NULL;
l_asset_category_id := NULL;
END IF;

UPDATE xxindus_e269_eam_webadi_tab
SET asst_grp_item_id = l_item_id,
organization_id = l_organization_id,
porganization_code = l_porganization_code,
porganization_id = l_porganization_id,
passt_grp_item_id = l_pinventory_item_id,
passet_serial = l_pserial_number,
location_id = l_location_id,
fa_id = l_asset_id,
asset_category_id = l_asset_category_id,
item_type = l_item_type,
fa_sync_flag = l_fa_sync_flag,
error_num = 'SUCC',
error_msg = 'Success',
last_update_login = fnd_global.login_id,
last_update_date = SYSDATE,
last_updated_by = fnd_global.user_id
WHERE CURRENT OF c_get_record;
END IF;
END LOOP;

IF l_error_flag = 0
THEN
-- fire request
l_user_id := fnd_profile.VALUE ('USER_ID');
l_resp_id := fnd_profile.VALUE ('RESP_ID');
l_resp_appl_id := fnd_profile.VALUE ('RESP_APPL_ID');

fnd_global.apps_initialize (user_id => l_user_id,


resp_id => l_resp_id,
resp_appl_id => l_resp_appl_id);

l_request_id :=
fnd_request.submit_request ('XXINDUS',
'XXINDUS_E269_EAM_AST_INT',
NULL,
NULL,
FALSE,
p_group_id);

log_msg ('Request id for Payables Import ' || l_request_id);


p_req_id := l_request_id;
END IF;
END xxindus_eam_asset_webadi_prc;
END xxindus_e269_eam_webadi_pkg;
/

Das könnte Ihnen auch gefallen