Assumption: The following Budget creation program is based on Financial Plan.
/* Formatted on 2012/12/13 12:52 (Formatter Plus v4.8.8) */
PROCEDURE budget_creation_conc (
errorbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_project_number IN VARCHAR2,
p_version_num IN VARCHAR2,
p_rev_amount IN NUMBER,
p_cost_amount IN NUMBER,
p_period_num IN VARCHAR2,
p_user_id IN NUMBER,
p_success IN OUT VARCHAR2,
p_error_message IN OUT VARCHAR2
)
IS
l_api_version_number NUMBER := 1.0;
x_finplan_version_id NUMBER;
l_commit VARCHAR2 (1) := 'F';
l_return_status VARCHAR2 (1);
l_init_msg_list VARCHAR2 (1) := 'F';
l_msg_data VARCHAR2 (2000);
l_msg_count NUMBER;
l_msg_index_out NUMBER;
l_data VARCHAR2 (2000);
l_workflow_started VARCHAR2 (1) := 'Y';
l_pm_product_code VARCHAR2 (10) := 'XXBUDGET';---has to be define in the system
l_budget_type_code VARCHAR2 (30);
l_responsility VARCHAR2 (100 BYTE);
l_application_id NUMBER;
--l_user_id NUMBER := 10803;
--l_responsibility_id NUMBER := 51222;
l_user_id NUMBER := 0;
l_responsibility_id NUMBER := 0;
l_project_id pa_projects_all.project_id%TYPE;
l_resource_list_name pa_resource_lists.NAME%TYPE;
l_resource_list_id pa_resource_lists.resource_list_id%TYPE;
l_task_id NUMBER;
l_description pa_budget_versions.description%TYPE;
l_pm_finplan_reference pa_budget_versions.pm_budget_reference%TYPE;
l_project_reference pa_projects_all.pm_project_reference%TYPE;
l_change_reason_code pa_budget_versions.change_reason_code%TYPE;
l_budget_version_name pa_budget_versions.version_name%TYPE;
l_fin_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE;
l_fin_plan_type_name pa_fin_plan_types_vl.NAME%TYPE;
l_version_type pa_budget_versions.version_type%TYPE;
l_fin_plan_level_code pa_proj_fp_options.cost_fin_plan_level_code%TYPE;
l_time_phased_code pa_proj_fp_options.cost_time_phased_code%TYPE;
l_raw_cost_flag VARCHAR2 (1);
l_burdened_cost_flag VARCHAR2 (1);
l_revenue_flag VARCHAR2 (1);
l_cost_qty_flag VARCHAR2 (1);
l_revenue_qty_flag VARCHAR2 (1);
l_all_qty_flag VARCHAR2 (1);
l_create_new_working_flag VARCHAR2 (1);
l_replace_current_working_flag VARCHAR2 (1);
l_using_resource_lists_flag VARCHAR2 (1);
p_message VARCHAR2 (2000);
l_resource_list_member_id NUMBER;
l_line_return_status VARCHAR2 (1);
l_proj_count NUMBER;
l_budget_lines_in pa_budget_pub.budget_line_in_tbl_type;
l_budget_lines_in_rec pa_budget_pub.budget_line_in_rec_type;
l_budget_lines_out pa_budget_pub.budget_line_out_tbl_type;
l_budget_lines_out_rec pa_budget_pub.budget_line_out_rec_type;
l_loop_cnt NUMBER;
l_dummy_cnt NUMBER;
l_error VARCHAR2 (500);
l_cnt NUMBER;
l_project_number VARCHAR2 (30);
l_org_id NUMBER := fnd_profile.VALUE ('ORG_ID');
l_error_message VARCHAR2 (4000);
l_start_date DATE;
l_end_date DATE;
v_budget_version_id NUMBER;
l_currency VARCHAR2 (3);
v_rev_amount NUMBER;
v_cost_amount NUMBER;
v_rate NUMBER;
v_status VARCHAR2 (1);
l_func_currency VARCHAR2 (3);
BEGIN
SELECT project_id, TRUNC (start_date), TRUNC (completion_date),
NVL (pm_product_code, 'XXBUDGET'), project_currency_code, org_id,
projfunc_currency_code
INTO l_project_id, l_start_date, l_end_date,
l_pm_product_code, l_currency, l_org_id,
l_func_currency
FROM apps.pa_projects_all
WHERE segment1 = p_project_number;
mo_global.set_policy_context ('S', l_org_id);
l_responsility := fnd_profile.VALUE ('XX_PROJECT_BUDGET_RESP');
SELECT responsibility_id, application_id
INTO l_responsibility_id, l_application_id
FROM fnd_responsibility_tl
WHERE responsibility_name = l_responsility;
/*
fnd_global.apps_initialize (user_id => p_user_id,
resp_id => l_responsibility_id,
resp_appl_id => l_application_id
);
*/
pa_interface_utils_pub.set_global_info
(p_api_version_number => l_api_version_number,
p_responsibility_id => l_responsibility_id,
p_user_id => p_user_id,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_return_status => l_return_status
);
mo_global.set_policy_context ('S', l_org_id);
SELECT SUM (NVL (projfunc_allocated_amount, 0)),
SUM (projfunc_allocated_amount) / SUM (allocated_amount)
INTO v_rev_amount,
v_rate
FROM pa_project_fundings
WHERE project_id = l_project_id;
v_cost_amount := v_rate * p_cost_amount;
l_budget_lines_in_rec.pm_product_code := l_pm_product_code;
l_budget_lines_in_rec.pa_task_id := l_project_id;
l_budget_lines_in_rec.pm_task_reference := p_project_number;
l_budget_lines_in_rec.resource_alias := NULL;
l_budget_lines_in_rec.resource_list_member_id := 3000;
---2004; --**--
l_budget_lines_in_rec.budget_start_date := l_start_date;
l_budget_lines_in_rec.budget_end_date := l_end_date;
l_budget_lines_in_rec.period_name := p_period_num;
l_budget_lines_in_rec.description := 'Revenue And Cost Budget';
l_budget_lines_in_rec.raw_cost := v_cost_amount; -- p_cost_amount;
l_budget_lines_in_rec.revenue := v_rev_amount;
l_budget_lines_in_rec.txn_currency_code := l_func_currency;
--l_budget_lines_in_rec.burdened_cost :=0;
--l_budget_lines_in_rec.quantity := l_quantity;
l_budget_lines_in (1) := l_budget_lines_in_rec;
pa_budget_pub.create_draft_budget
(p_api_version_number => 1.0,
p_commit => 'T',
p_init_msg_list => NULL,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_return_status => l_return_status,
p_pm_product_code => l_pm_product_code,
p_pm_budget_reference => NULL,
p_budget_version_name => p_version_num,
p_pa_project_id => l_project_id,
p_pm_project_reference => p_project_number,
p_description => 'Revenue And Cost Budget',
p_entry_method_code => 'PA_LT_DR_WITHOUT_RES',
p_resource_list_id => 2000, ----1003, --**--
p_budget_lines_in => l_budget_lines_in,
p_budget_lines_out => l_budget_lines_out,
p_fin_plan_type_name => 'XX Cost and Revenue Budget', ---has to be define in the system
p_version_type => 'ALL',
p_revenue_flag => 'Y',
p_create_new_curr_working_flag => 'Y',
p_using_resource_lists_flag => 'Y'
);
--COMMIT;
DBMS_OUTPUT.put_line ('l_return_status ' || l_return_status);
IF l_msg_count > 0
THEN
l_loop_cnt := 1;
LOOP
fnd_msg_pub.get (p_msg_index => l_loop_cnt,
p_data => l_msg_data,
p_encoded => fnd_api.g_false,
p_msg_index_out => l_dummy_cnt
);
IF l_return_status = 'E' OR l_return_status = 'U'
THEN
l_msg_data :=
CONCAT
( 'ERROR pa_budget_pub.create_draft_budget>>> user id~'
|| p_user_id
|| 'Resp Id~'
|| l_responsibility_id
|| '>',
l_msg_data
);
DBMS_OUTPUT.put_line (l_msg_data);
fnd_file.put_line (fnd_file.LOG,
'*** ERROR ENCOUNTERED ***:' || l_msg_data
);
fnd_file.put_line (fnd_file.output,
'*** ERROR ENCOUNTERED ***:' || l_msg_data
);
--fnd_file.put_line(fnd_file.OUTPUT,x_msg_data1);
v_status := 'E';
ELSE
fnd_file.put_line (fnd_file.output,
'*** REVENUE BUDGET UPLOADED ***:'
|| l_msg_data
);
v_status := 'S';
END IF;
DBMS_OUTPUT.put_line ('RETURN STATUS :' || l_return_status);
l_error_message :=
SUBSTR (l_error_message || '~' || l_msg_data, 1, 4000);
l_loop_cnt := l_loop_cnt + 1;
EXIT WHEN l_loop_cnt > l_msg_count;
END LOOP;
ELSE
v_status := 'S';
END IF;
fnd_file.put_line (fnd_file.LOG,
'pa_budget_pub.create_draft_budget RETURN STATUS :'
|| l_return_status
);
---base line part ---
EXCEPTION
WHEN OTHERS
THEN
fnd_file.put_line (fnd_file.output,
'RETURN STATUS :' || l_return_status
);
l_error_message := SUBSTR (SQLERRM, 1, 240);
fnd_file.put_line (fnd_file.output,
'l_error_message:' || l_error_message
);
END budget_creation_conc;
/* Formatted on 2012/12/13 12:52 (Formatter Plus v4.8.8) */
PROCEDURE budget_creation_conc (
errorbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_project_number IN VARCHAR2,
p_version_num IN VARCHAR2,
p_rev_amount IN NUMBER,
p_cost_amount IN NUMBER,
p_period_num IN VARCHAR2,
p_user_id IN NUMBER,
p_success IN OUT VARCHAR2,
p_error_message IN OUT VARCHAR2
)
IS
l_api_version_number NUMBER := 1.0;
x_finplan_version_id NUMBER;
l_commit VARCHAR2 (1) := 'F';
l_return_status VARCHAR2 (1);
l_init_msg_list VARCHAR2 (1) := 'F';
l_msg_data VARCHAR2 (2000);
l_msg_count NUMBER;
l_msg_index_out NUMBER;
l_data VARCHAR2 (2000);
l_workflow_started VARCHAR2 (1) := 'Y';
l_pm_product_code VARCHAR2 (10) := 'XXBUDGET';---has to be define in the system
l_budget_type_code VARCHAR2 (30);
l_responsility VARCHAR2 (100 BYTE);
l_application_id NUMBER;
--l_user_id NUMBER := 10803;
--l_responsibility_id NUMBER := 51222;
l_user_id NUMBER := 0;
l_responsibility_id NUMBER := 0;
l_project_id pa_projects_all.project_id%TYPE;
l_resource_list_name pa_resource_lists.NAME%TYPE;
l_resource_list_id pa_resource_lists.resource_list_id%TYPE;
l_task_id NUMBER;
l_description pa_budget_versions.description%TYPE;
l_pm_finplan_reference pa_budget_versions.pm_budget_reference%TYPE;
l_project_reference pa_projects_all.pm_project_reference%TYPE;
l_change_reason_code pa_budget_versions.change_reason_code%TYPE;
l_budget_version_name pa_budget_versions.version_name%TYPE;
l_fin_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE;
l_fin_plan_type_name pa_fin_plan_types_vl.NAME%TYPE;
l_version_type pa_budget_versions.version_type%TYPE;
l_fin_plan_level_code pa_proj_fp_options.cost_fin_plan_level_code%TYPE;
l_time_phased_code pa_proj_fp_options.cost_time_phased_code%TYPE;
l_raw_cost_flag VARCHAR2 (1);
l_burdened_cost_flag VARCHAR2 (1);
l_revenue_flag VARCHAR2 (1);
l_cost_qty_flag VARCHAR2 (1);
l_revenue_qty_flag VARCHAR2 (1);
l_all_qty_flag VARCHAR2 (1);
l_create_new_working_flag VARCHAR2 (1);
l_replace_current_working_flag VARCHAR2 (1);
l_using_resource_lists_flag VARCHAR2 (1);
p_message VARCHAR2 (2000);
l_resource_list_member_id NUMBER;
l_line_return_status VARCHAR2 (1);
l_proj_count NUMBER;
l_budget_lines_in pa_budget_pub.budget_line_in_tbl_type;
l_budget_lines_in_rec pa_budget_pub.budget_line_in_rec_type;
l_budget_lines_out pa_budget_pub.budget_line_out_tbl_type;
l_budget_lines_out_rec pa_budget_pub.budget_line_out_rec_type;
l_loop_cnt NUMBER;
l_dummy_cnt NUMBER;
l_error VARCHAR2 (500);
l_cnt NUMBER;
l_project_number VARCHAR2 (30);
l_org_id NUMBER := fnd_profile.VALUE ('ORG_ID');
l_error_message VARCHAR2 (4000);
l_start_date DATE;
l_end_date DATE;
v_budget_version_id NUMBER;
l_currency VARCHAR2 (3);
v_rev_amount NUMBER;
v_cost_amount NUMBER;
v_rate NUMBER;
v_status VARCHAR2 (1);
l_func_currency VARCHAR2 (3);
BEGIN
SELECT project_id, TRUNC (start_date), TRUNC (completion_date),
NVL (pm_product_code, 'XXBUDGET'), project_currency_code, org_id,
projfunc_currency_code
INTO l_project_id, l_start_date, l_end_date,
l_pm_product_code, l_currency, l_org_id,
l_func_currency
FROM apps.pa_projects_all
WHERE segment1 = p_project_number;
mo_global.set_policy_context ('S', l_org_id);
l_responsility := fnd_profile.VALUE ('XX_PROJECT_BUDGET_RESP');
SELECT responsibility_id, application_id
INTO l_responsibility_id, l_application_id
FROM fnd_responsibility_tl
WHERE responsibility_name = l_responsility;
/*
fnd_global.apps_initialize (user_id => p_user_id,
resp_id => l_responsibility_id,
resp_appl_id => l_application_id
);
*/
pa_interface_utils_pub.set_global_info
(p_api_version_number => l_api_version_number,
p_responsibility_id => l_responsibility_id,
p_user_id => p_user_id,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_return_status => l_return_status
);
mo_global.set_policy_context ('S', l_org_id);
SELECT SUM (NVL (projfunc_allocated_amount, 0)),
SUM (projfunc_allocated_amount) / SUM (allocated_amount)
INTO v_rev_amount,
v_rate
FROM pa_project_fundings
WHERE project_id = l_project_id;
v_cost_amount := v_rate * p_cost_amount;
l_budget_lines_in_rec.pm_product_code := l_pm_product_code;
l_budget_lines_in_rec.pa_task_id := l_project_id;
l_budget_lines_in_rec.pm_task_reference := p_project_number;
l_budget_lines_in_rec.resource_alias := NULL;
l_budget_lines_in_rec.resource_list_member_id := 3000;
---2004; --**--
l_budget_lines_in_rec.budget_start_date := l_start_date;
l_budget_lines_in_rec.budget_end_date := l_end_date;
l_budget_lines_in_rec.period_name := p_period_num;
l_budget_lines_in_rec.description := 'Revenue And Cost Budget';
l_budget_lines_in_rec.raw_cost := v_cost_amount; -- p_cost_amount;
l_budget_lines_in_rec.revenue := v_rev_amount;
l_budget_lines_in_rec.txn_currency_code := l_func_currency;
--l_budget_lines_in_rec.burdened_cost :=0;
--l_budget_lines_in_rec.quantity := l_quantity;
l_budget_lines_in (1) := l_budget_lines_in_rec;
pa_budget_pub.create_draft_budget
(p_api_version_number => 1.0,
p_commit => 'T',
p_init_msg_list => NULL,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_return_status => l_return_status,
p_pm_product_code => l_pm_product_code,
p_pm_budget_reference => NULL,
p_budget_version_name => p_version_num,
p_pa_project_id => l_project_id,
p_pm_project_reference => p_project_number,
p_description => 'Revenue And Cost Budget',
p_entry_method_code => 'PA_LT_DR_WITHOUT_RES',
p_resource_list_id => 2000, ----1003, --**--
p_budget_lines_in => l_budget_lines_in,
p_budget_lines_out => l_budget_lines_out,
p_fin_plan_type_name => 'XX Cost and Revenue Budget', ---has to be define in the system
p_version_type => 'ALL',
p_revenue_flag => 'Y',
p_create_new_curr_working_flag => 'Y',
p_using_resource_lists_flag => 'Y'
);
--COMMIT;
DBMS_OUTPUT.put_line ('l_return_status ' || l_return_status);
IF l_msg_count > 0
THEN
l_loop_cnt := 1;
LOOP
fnd_msg_pub.get (p_msg_index => l_loop_cnt,
p_data => l_msg_data,
p_encoded => fnd_api.g_false,
p_msg_index_out => l_dummy_cnt
);
IF l_return_status = 'E' OR l_return_status = 'U'
THEN
l_msg_data :=
CONCAT
( 'ERROR pa_budget_pub.create_draft_budget>>> user id~'
|| p_user_id
|| 'Resp Id~'
|| l_responsibility_id
|| '>',
l_msg_data
);
DBMS_OUTPUT.put_line (l_msg_data);
fnd_file.put_line (fnd_file.LOG,
'*** ERROR ENCOUNTERED ***:' || l_msg_data
);
fnd_file.put_line (fnd_file.output,
'*** ERROR ENCOUNTERED ***:' || l_msg_data
);
--fnd_file.put_line(fnd_file.OUTPUT,x_msg_data1);
v_status := 'E';
ELSE
fnd_file.put_line (fnd_file.output,
'*** REVENUE BUDGET UPLOADED ***:'
|| l_msg_data
);
v_status := 'S';
END IF;
DBMS_OUTPUT.put_line ('RETURN STATUS :' || l_return_status);
l_error_message :=
SUBSTR (l_error_message || '~' || l_msg_data, 1, 4000);
l_loop_cnt := l_loop_cnt + 1;
EXIT WHEN l_loop_cnt > l_msg_count;
END LOOP;
ELSE
v_status := 'S';
END IF;
fnd_file.put_line (fnd_file.LOG,
'pa_budget_pub.create_draft_budget RETURN STATUS :'
|| l_return_status
);
---base line part ---
EXCEPTION
WHEN OTHERS
THEN
fnd_file.put_line (fnd_file.output,
'RETURN STATUS :' || l_return_status
);
l_error_message := SUBSTR (SQLERRM, 1, 240);
fnd_file.put_line (fnd_file.output,
'l_error_message:' || l_error_message
);
END budget_creation_conc;
Hi i am using the above API for creating a cost budgets for specific tasks, and i get the below message.
ReplyDeleteanonymous block completed
error msg
can you please help me resolving this