Tuesday, October 10, 2017

pa_budget_pub.create_draft_finplan - Single Record Script

DECLARE
   v_commit                         VARCHAR2 (1)                       := 'F';
   v_init_msg_list                  VARCHAR2 (1);
   v_data                           VARCHAR2 (2000);
   v_msg_index_out                  VARCHAR2 (30);
   v_pm_product_code                pa_budget_versions.pm_product_code%TYPE
                                                               := 'MSPROJECT';
   v_pm_finplan_reference           pa_budget_versions.pm_budget_reference%TYPE;
   v_pm_project_reference           pa_projects_all.pm_project_reference%TYPE
                                                        := 'API TEST PROJECT';
   v_pa_project_id                  pa_budget_versions.project_id%TYPE
                                                                    := 117829;
   v_fin_plan_type_id               pa_budget_versions.fin_plan_type_id%TYPE;
   v_fin_plan_type_name             pa_fin_plan_types_vl.NAME%TYPE
                                                    := 'Approved Cost Budget';
   v_version_type                   pa_budget_versions.version_type%TYPE
                                                                    := 'COST';
   v_time_phased_code               VARCHAR2 (1)                       := 'P';
   v_resource_list_name             pa_resource_lists.NAME%TYPE;
   v_resource_list_id               pa_budget_versions.resource_list_id%TYPE;
   v_fin_plan_level_code            VARCHAR2 (1)                       := 'L';
   v_budget_version_name            pa_budget_versions.version_name%TYPE
                                                                       := '1';
   v_description                    pa_budget_versions.description%TYPE
                                                    := 'Approved Cost Budget';
   v_change_reason_code             pa_budget_versions.change_reason_code%TYPE;
   v_raw_cost_flag                  pa_fin_plan_amount_sets.raw_cost_flag%TYPE
                                                                       := 'Y';
   v_burdened_cost_flag             pa_fin_plan_amount_sets.burdened_cost_flag%TYPE
                                                                       := 'Y';
   v_cost_qty_flag                  pa_fin_plan_amount_sets.cost_qty_flag%TYPE
                                                                       := 'Y';
   v_create_new_curr_working_flag   VARCHAR2 (1)                       := 'Y';
   v_finplan_trans_tab              pa_budget_pub.finplan_trans_tab;
   v_replace_current_working_flag   VARCHAR2 (1);
   v_using_resource_lists_flag      VARCHAR2 (1);
   v_finplan_version_id             NUMBER;
   v_return_status                  VARCHAR2 (1);
   v_msg_count                      NUMBER;
   v_msg_data                       VARCHAR2 (2000);
   l_user_id                        NUMBER                           := 51711;
   l_responsibility_id              NUMBER                           := 22593;
   l_org_id                         NUMBER                             := 159;
   api_error                        EXCEPTION;
BEGIN
   v_msg_count := NULL;
   v_msg_data := NULL;
   DBMS_OUTPUT.put_line ('Setting global variables');

   SELECT fin_plan_type_id
     INTO v_fin_plan_type_id
     FROM pa_fin_plan_types_tl
    WHERE LANGUAGE = 'US' AND NAME = 'Approved Cost Budget';

   SELECT resource_list_id
     INTO v_resource_list_id
     FROM pabv_resource_lists
    WHERE NAME = 'Forecast Roles';

   -- Projects Responsibility
   DBMS_OUTPUT.put_line ('Setting global info');
   pa_interface_utils_pub.set_global_info
                                  (p_api_version_number      => 1,
                                   p_responsibility_id       => l_responsibility_id,
                                   p_user_id                 => l_user_id,
                                   p_operating_unit_id       => l_org_id,
                                   p_calling_mode            => 'AMG',
                                   p_msg_count               => v_msg_count,
                                   p_msg_data                => v_msg_data,
                                   p_return_status           => v_return_status
                                  );
   mo_global.set_policy_context ('S', l_org_id);
   DBMS_OUTPUT.put_line ('Calling init budget');
   pa_budget_pub.init_budget;
   v_finplan_trans_tab (1).pm_product_code := 'MSPROJECT';
   --'PA';
   v_finplan_trans_tab (1).task_id := 6468200;
   v_finplan_trans_tab (1).pm_task_reference := 646820011;
   v_finplan_trans_tab (1).pm_res_asgmt_reference := NULL;
   v_finplan_trans_tab (1).currency_code := 'GBP';
   v_finplan_trans_tab (1).unit_of_measure_code := 'HOURS';
   v_finplan_trans_tab (1).start_date :=
                                        TO_DATE ('01-MAR-2016', 'DD-MON-YYYY');
   v_finplan_trans_tab (1).end_date := TO_DATE ('31-DEC-2016', 'DD-MON-YYYY');
   v_finplan_trans_tab (1).cost_code := NULL;
   v_finplan_trans_tab (1).cbs_element_id := NULL;
   v_finplan_trans_tab (1).quantity := 10;
   v_finplan_trans_tab (1).raw_cost := 5000;
   v_finplan_trans_tab (1).burdened_cost := 5000;
   ---v_finplan_trans_tab(1).revenue:=NULL;
   v_finplan_trans_tab (1).resource_list_member_id := 168012;
   v_finplan_trans_tab (1).attribute_category := NULL;
   v_finplan_trans_tab (1).attribute1 := NULL;
   v_finplan_trans_tab (1).attribute1 := NULL;
   v_finplan_trans_tab (1).attribute2 := NULL;
   v_finplan_trans_tab (1).attribute3 := NULL;
   v_finplan_trans_tab (1).attribute4 := NULL;
   v_finplan_trans_tab (1).attribute5 := NULL;
   v_finplan_trans_tab (1).attribute6 := NULL;
   v_finplan_trans_tab (1).attribute7 := NULL;
   v_finplan_trans_tab (1).attribute8 := NULL;
   v_finplan_trans_tab (1).attribute9 := NULL;
   v_finplan_trans_tab (1).attribute10 := NULL;
   v_finplan_trans_tab (1).attribute11 := NULL;
   v_finplan_trans_tab (1).attribute12 := NULL;
   v_finplan_trans_tab (1).attribute13 := NULL;
   v_finplan_trans_tab (1).attribute14 := NULL;
   v_finplan_trans_tab (1).attribute15 := NULL;
   v_finplan_trans_tab (1).attribute16 := NULL;
   v_finplan_trans_tab (1).attribute17 := NULL;
   v_finplan_trans_tab (1).attribute18 := NULL;
   v_finplan_trans_tab (1).attribute19 := NULL;
   v_finplan_trans_tab (1).attribute20 := NULL;
   v_finplan_trans_tab (1).attribute21 := NULL;
   v_finplan_trans_tab (1).attribute22 := NULL;
   v_finplan_trans_tab (1).attribute23 := NULL;
   v_finplan_trans_tab (1).attribute24 := NULL;
   v_finplan_trans_tab (1).attribute25 := NULL;
   v_finplan_trans_tab (1).attribute26 := NULL;
   v_finplan_trans_tab (1).attribute27 := NULL;
   v_finplan_trans_tab (1).attribute28 := NULL;
   v_finplan_trans_tab (1).attribute29 := NULL;
   v_finplan_trans_tab (1).attribute30 := NULL;
   DBMS_OUTPUT.put_line ('Calling create draft finplan');
   pa_budget_pub.create_draft_finplan
            (p_api_version_number                => 1.0,
             p_commit                            => v_commit,
             p_init_msg_list                     => v_init_msg_list,
             p_pm_product_code                   => v_pm_product_code,
             p_pm_finplan_reference              => v_pm_finplan_reference,
             p_pm_project_reference              => v_pm_project_reference,
             p_pa_project_id                     => v_pa_project_id,
             p_fin_plan_type_id                  => v_fin_plan_type_id,
             p_fin_plan_type_name                => v_fin_plan_type_name,
             p_version_type                      => v_version_type,
             p_time_phased_code                  => v_time_phased_code,
             p_resource_list_name                => v_resource_list_name,
             p_resource_list_id                  => v_resource_list_id,
             p_fin_plan_level_code               => v_fin_plan_level_code,
             p_budget_version_name               => v_budget_version_name,
             p_description                       => v_description,
             p_change_reason_code                => v_change_reason_code,
             p_raw_cost_flag                     => v_raw_cost_flag,
             p_burdened_cost_flag                => v_burdened_cost_flag,
             p_cost_qty_flag                     => v_cost_qty_flag,
             p_create_new_curr_working_flag      => v_create_new_curr_working_flag,
             p_using_resource_lists_flag         => v_using_resource_lists_flag,
             p_finplan_trans_tab                 => v_finplan_trans_tab,
             x_finplan_version_id                => v_finplan_version_id,
             x_return_status                     => v_return_status,
             x_msg_count                         => v_msg_count,
             x_msg_data                          => v_msg_data
            );

   IF v_return_status != 'S'
   THEN
      DBMS_OUTPUT.put_line ('Create fin plan ended with errors');
      RAISE api_error;
   ELSE
      DBMS_OUTPUT.put_line ('Create fin plan called successfully');
   END IF;

   DBMS_OUTPUT.put_line ('Calling clear budget');
   pa_budget_pub.clear_budget;
EXCEPTION
   WHEN api_error
   THEN
      FOR i IN 1 .. v_msg_count
      LOOP
         pa_interface_utils_pub.get_messages
                                          (p_encoded            => 'F',
                                           p_msg_index          => i,
                                           p_msg_data           => v_msg_data,
                                           p_data               => v_data,
                                           p_msg_count          => v_msg_count,
                                           p_msg_index_out      => v_msg_index_out
                                          );
         DBMS_OUTPUT.put_line ('An error occurred: ' || v_msg_data);
         DBMS_OUTPUT.put_line (fnd_msg_pub.get (p_msg_index      => i,
                                                p_encoded        => 'F'
                                               )
                              );
      END LOOP;
END;
/

No comments: