Step1- Create 1 procedure in database.
CREATE OR REPLACE PROCEDURE XXX_UPD_ASSEST_PRC (P_ASSET_NUMBER VARCHAR2)
AS
CURSOR cur_loc_update
IS
SELECT a.asset_number,
fa.asset_id,
‘IND CORP BOOK’ book_type_code,
a.from_site location_from,
a.to_site location_to,
fdh.UNITS_ASSIGNED units,
a.segment7,
a.segment1,
a.segment3,
a.from_segment3 from_segment3,
a.flag
FROM xxbackup.XXX_fa_loc_update2809 a,
apps.fa_distribution_history fdh,
apps.fa_additions_b fa,
apps.fa_locations fl
WHERE 1 = 1
AND a.asset_number = fa.asset_number
AND fa.asset_id = fdh.asset_id
AND fdh.location_id = fl.location_id
AND DATE_INEFFECTIVE IS NULL
AND fl.segment1 = a.from_site
and a.asset_number = P_ASSET_NUMBER;
CURSOR cur_unit_trans (
p_asset_id IN NUMBER,
p_book_type_code IN VARCHAR2,
p_location_from IN VARCHAR2,
p_location_to IN VARCHAR2,
p_units IN NUMBER,
p_segment7 IN VARCHAR2,
p_segment1 IN VARCHAR2,
p_from_segment3 IN VARCHAR2,
p_segment3 IN VARCHAR2)
IS
SELECT asset_id,
book_type_code,
distribution_id,
units_assigned,
code_combination_id dist_code_combination_id,
dist_account,
location_id,
site_id,
delta_units,
source_type
FROM (SELECT fdh.asset_id asset_id,
fdh.book_type_code,
distribution_id,
units_assigned,
fdh.code_combination_id,
gcc.concatenated_segments dist_account,
fl.location_id,
fl.segment1 site_id,
TO_NUMBER (p_units) * (-1) delta_units,
‘FA’ source_type
FROM apps.fa_distribution_history fdh,
apps.fa_locations fl,
apps.fa_additions_b fa,
apps.gl_code_combinations_kfv gcc
WHERE 1 = 1
AND fdh.asset_id = p_asset_id
AND book_type_code = p_book_type_code
AND date_ineffective IS NULL
AND fa.asset_id = fdh.asset_id
AND fdh.location_id = fl.location_id
AND fdh.code_combination_id = gcc.code_combination_id
AND fl.segment3 = p_from_segment3
and fl.segment1= p_location_from
UNION ALL
SELECT p_asset_id asset_id,
p_book_type_code book_type_code,
NULL,
0,
(apps.fnd_flex_ext.get_ccid (
‘SQLGL’,
‘GL#’,
101,
TRUNC (SYSDATE),
(SELECT NVL (RTRIM (LTRIM (p_segment1)),
gcci.segment1)
|| ‘.’
|| gcci.segment2
|| ‘.’
|| gcci.segment3
|| ‘.’
|| gcci.segment4
|| ‘.’
|| (p_location_to)
|| ‘.’
|| gcci.segment6
|| ‘.’
|| NVL ( (p_segment7), gcci.segment7)
FROM apps.gl_code_combinations gcci,
apps.fa_distribution_history fdhi
WHERE 1 = 1
AND fdhi.code_combination_id =
gcci.code_combination_id
AND fdhi.asset_id = p_asset_id
AND fdhi.book_type_code = p_book_type_code
AND fdhi.date_ineffective IS NULL
AND ROWNUM = 1))),
(SELECT NVL (p_segment1, gcci.segment1)
|| ‘.’
|| gcci.segment2
|| ‘.’
|| gcci.segment3
|| ‘.’
|| gcci.segment4
|| ‘.’
|| p_location_to
|| ‘.’
|| gcci.segment6
|| ‘.’
|| NVL (p_segment7, gcci.segment7)
— added nvl
FROM apps.gl_code_combinations gcci,
apps.fa_distribution_history fdhi
WHERE 1 = 1
AND fdhi.code_combination_id =
gcci.code_combination_id
AND fdhi.asset_id = p_asset_id
AND fdhi.book_type_code = p_book_type_code
AND fdhi.date_ineffective IS NULL
AND ROWNUM = 1),
(SELECT location_id
FROM apps.fa_locations fl
WHERE 1=1
AND fl.segment1 = p_location_to
AND fl.segment3= p_segment3
AND enabled_flag = ‘Y’
AND TRUNC (SYSDATE) BETWEEN NVL (
start_date_active,
TRUNC (SYSDATE))
AND NVL (
end_date_active,
TRUNC (SYSDATE)
+ 1)),
p_location_to site_id,
TO_NUMBER (p_units) delta_units,
‘New’ source_type
FROM apps.fa_locations fa
WHERE 1 = 1
AND fa.segment1 = p_location_to
AND fa.segment3= p_segment3
AND NVL (fa.end_date_active, TRUNC (SYSDATE) + 1) >=
TRUNC (SYSDATE)
AND NVL (fa.enabled_flag, ‘Y’) = ‘Y’);
l_return_status VARCHAR2 (1);
l_msg_count NUMBER;
l_mesg_count NUMBER;
l_calling_fn VARCHAR2 (30);
l_msg_data VARCHAR2 (2000);
l_tbl_ct NUMBER;
l_trans_rec apps.fa_api_types.trans_rec_type;
l_asset_hdr_rec apps.fa_api_types.asset_hdr_rec_type;
l_asset_dist_tbl apps.fa_api_types.asset_dist_tbl_type;
l_mesg VARCHAR2 (2000) := NULL;
l_ccid VARCHAR2 (2000);
p_ret_msg VARCHAR2 (2000) := NULL;
— l_asset_id Number;
BEGIN
DBMS_output.put_line(‘Block execution :’|| to_char(sysdate,’DD-MON-YYYY HH24:MI:SS’));
FOR i_loc_update IN cur_loc_update
LOOP
DBMS_output.put_line(‘For ASSET_NUMBER :’);
DBMS_output.put_line(i_loc_update.asset_number);
l_tbl_ct := 1;
DBMS_output.put_line('Before CCID :'|| to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
BEGIN
SELECT (apps.fnd_flex_ext.get_ccid (
'SQLGL',
'GL#',
101,
TRUNC (SYSDATE),
(SELECT NVL (i_loc_update.segment1, gcci.segment1)
|| '.'
|| gcci.segment2
|| '.'
|| gcci.segment3
|| '.'
|| gcci.segment4
|| '.'
|| i_loc_update.segment3
|| '.'
|| gcci.segment6
|| '.'
|| NVL (i_loc_update.segment7, gcci.segment7)
FROM apps.gl_code_combinations gcci,
apps.fa_distribution_history fdhi
WHERE 1 = 1
AND fdhi.code_combination_id =
gcci.code_combination_id
AND fdhi.asset_id = i_loc_update.asset_id
AND fdhi.book_type_code =
i_loc_update.book_type_code
AND fdhi.date_ineffective IS NULL
AND ROWNUM = 1)))
ccid
INTO l_ccid
FROM DUAL;
EXCEPTION
WHEN OTHERS
THEN
apps.fnd_file.put_line (apps.fnd_file.LOG, 'l_ccid' || l_ccid);
END;
DBMS_output.put_line('After CCID :'|| to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
FOR trans_rec IN cur_unit_trans (i_loc_update.asset_id,
i_loc_update.book_type_code,
i_loc_update.location_from,
i_loc_update.location_to,
i_loc_update.units,
i_loc_update.segment7,
i_loc_update.segment1,
i_loc_update.from_segment3,
i_loc_update.segment3)
LOOP
DBMS_output.put_line('Inside trans loop and before if conditions :'|| to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
l_return_status := NULL;
l_asset_hdr_rec.asset_id := trans_rec.asset_id;
l_asset_hdr_rec.book_type_code := trans_rec.book_type_code;
l_asset_dist_tbl (l_tbl_ct).distribution_id :=
trans_rec.distribution_id;
l_asset_dist_tbl (l_tbl_ct).distribution_id :=
trans_rec.distribution_id;
IF (trans_rec.distribution_id IS NOT NULL)
THEN
l_asset_dist_tbl (l_tbl_ct).transaction_units :=
trans_rec.delta_units;
l_asset_dist_tbl (l_tbl_ct).expense_ccid :=
trans_rec.dist_code_combination_id;
l_asset_dist_tbl (l_tbl_ct).location_ccid := trans_rec.location_id;
l_asset_dist_tbl (l_tbl_ct).assigned_to := NULL;
ELSE
l_asset_dist_tbl (l_tbl_ct).transaction_units :=
trans_rec.delta_units;
l_asset_dist_tbl (l_tbl_ct).units_assigned :=
trans_rec.delta_units;
l_asset_dist_tbl (l_tbl_ct).expense_ccid :=
trans_rec.dist_code_combination_id;
l_asset_dist_tbl (l_tbl_ct).location_ccid := trans_rec.location_id;
l_asset_dist_tbl (l_tbl_ct).assigned_to := NULL;
END IF;
l_tbl_ct := l_tbl_ct + 1;
l_return_status := NULL;
l_msg_count := NULL;
l_msg_data := NULL;
END LOOP;
DBMS_output.put_line('After trans end loop :'|| to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
DBMS_output.put_line('Before API call :'|| to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
apps.fa_transfer_pub.do_transfer (
p_api_version => 1.0,
p_init_msg_list => apps.fnd_api.g_true,
p_commit => apps.fnd_api.g_false,
p_validation_level => apps.fnd_api.g_valid_level_full,
p_calling_fn => l_calling_fn,
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
px_trans_rec => l_trans_rec,
px_asset_hdr_rec => l_asset_hdr_rec,
px_asset_dist_tbl => l_asset_dist_tbl);
DBMS_output.put_line('After API call :'|| to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
DBMS_output.put_line('l_return_status ::'|| l_return_status);
--COMMIT;
IF (NVL (l_return_status, 'X') <> apps.fnd_api.g_ret_sts_success)
THEN
l_mesg_count := apps.fnd_msg_pub.count_msg;
IF l_mesg_count > 0
THEN
l_mesg :=
CHR (10)
|| SUBSTR (
apps.fnd_msg_pub.get (apps.fnd_msg_pub.g_first,
apps.fnd_api.g_false),
1,
250);
FOR i IN 1 .. (l_mesg_count - 1)
LOOP
l_mesg :=
SUBSTR (
apps.fnd_msg_pub.get (apps.fnd_msg_pub.g_next,
apps.fnd_api.g_false),
1,
250);
END LOOP;
apps.fnd_msg_pub.delete_msg ();
END IF;
-----------------------------------end---------------------------------------------------------------------
apps.fnd_msg_pub.count_and_get (p_count => l_msg_count,
p_data => l_msg_data);
p_ret_msg :=
'Error while asset transfer - apps.fa_transfer_pub.do_transfer';
DBMS_OUTPUT.put_line ('p_ret_msg ==> ' || p_ret_msg);
ELSE
p_ret_msg := NULL;
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
p_ret_msg := ‘Error while asset transfer.’ || SQLERRM;
DBMS_OUTPUT.put_line ('p_ret_msg ==> ' || p_ret_msg);
END;
/
Step2-
DECLARE
CURSOR cur_loc_update
IS
SELECT DISTINCT a.asset_number
FROM xxbackup.XXX_fa_loc_update2809 a,
apps.fa_distribution_history fdh,
apps.fa_additions_b fa,
apps.fa_locations fl
WHERE 1 = 1
AND a.asset_number = fa.asset_number
AND fa.asset_id = fdh.asset_id
AND fdh.location_id = fl.location_id
AND DATE_INEFFECTIVE IS NULL
AND fl.segment1 = a.from_site;
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM(
PROGRAM_NAME => 'XXX_FA_UPD_ASSET_PROGRAM'
,PROGRAM_TYPE => 'STORED_PROCEDURE'
,PROGRAM_ACTION => 'XXX_UPD_ASSEST_PRC'
,NUMBER_OF_ARGUMENTS => 1
,ENABLED => FALSE
,COMMENTS => 'my test program'
);
DBMS_SCHEDULER.DEFINE_PROGRAM_ARGUMENT(
PROGRAM_NAME => 'XXX_FA_UPD_ASSET_PROGRAM',
argument_name => 'P_ASSET_NUMBER',
argument_position => 1,
argument_type => 'VARCHAR2',
default_value => ''
);
dbms_scheduler.enable (name => 'XXX_FA_UPD_ASSET_PROGRAM');
FOR i_loc_update IN cur_loc_update
LOOP
DBMS_output.put_line('For ASSET_NUMBER :'|| i_loc_update.ASSET_NUMBER);
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'MY_TEST_JOB_'||i_loc_update.ASSET_NUMBER||'_5',
PROGRAM_NAME => 'XXX_FA_UPD_ASSET_PROGRAM'
);
dbms_scheduler.set_job_argument_value(
job_name => 'MY_TEST_JOB_'||i_loc_update.ASSET_NUMBER||'_5',
argument_position => 1,
argument_value => i_loc_update.ASSET_NUMBER);
DBMS_SCHEDULER.RUN_JOB(
JOB_NAME => 'MY_TEST_JOB_'||i_loc_update.ASSET_NUMBER||'_5',
USE_CURRENT_SESSION => FALSE);
END LOOP;
END;
You must be logged in to post a comment.