Tuesday, October 7, 2014

Creating Cost_allocation_keyflex_id

This Procedure will create cost_allocation_keyflex combinations if the passed cost_allocation_keyflex_id does not not exist. I did this because standard API FND_FLEX_EXT.GET_COMBINATION_ID for creating combinations was not populating concatenated segment column. May be because of the bug in the API.



IN parameters for the below procedure can be changed based on which all segments you need to pass to create the combination. Since I was using only one segment, I have passed only one segment.


CREATE OR PROCEDURE create_cost_combination(p_business_group_id  NUMBER
                                                      ,p_segment6  VARCHAR2
                                                      ,p_status       OUT VARCHAR2
                                                      ,p_cost_allocation_keyflex_id IN OUT NUMBER
AS                
CURSOR csr_cost_structure IS
    SELECT pbg.cost_allocation_structure
      FROM   per_business_groups pbg
    WHERE  pbg.business_group_id = p_business_group_id;

l_flex_num                                 fnd_id_flex_segments.id_flex_num%TYPE;
l_error                                      VARCHAR2(2) := 'N';
l_cost_allocation_keyflex_id      NUMBER := -1;   
l_message                                 VARCHAR2(220);
  
BEGIN    
DBMS_OUTPUT.PUT_LINE('Inside create_cost_combination');
  OPEN csr_cost_structure;
  FETCH csr_cost_structure INTO l_flex_num;
  IF csr_cost_structure%NOTFOUND THEN
    CLOSE csr_cost_structure;
    l_error := 'Y';
  END IF;
  CLOSE csr_cost_structure;

--DBMS_OUTPUT.PUT_LINE('l_flex_num'||l_flex_num);

IF l_error <> 'Y' THEN
        BEGIN
           l_cost_allocation_keyflex_id :=
hr_entry.maintain_cost_keyflex( p_cost_keyflex_structure     => l_flex_num,
                                                p_cost_allocation_keyflex_id =>                    NVL(p_cost_allocation_keyflex_id,l_cost_allocation_keyflex_id),
                                                p_concatenated_segments      => NULL,
                                                p_summary_flag               =>'N',
                                                p_start_date_active          => NULL,
                                                p_end_date_active            => NULL,
                                                p_segment1                   =>NULL,--p_segment1,
                                                p_segment2                   =>NULL,--p_segment2,
                                                p_segment3                   =>NULL,--p_segment3,
                                                p_segment4                   =>NULL,--p_segment4,
                                                p_segment5                   =>NULL,--p_segment5,
                                                p_segment6                   =>p_segment6,
                                                p_segment7                   =>NULL,--p_segment7,
                                                p_segment8                   =>NULL,--p_segment8,
                                                p_segment9                   =>NULL,--p_segment9,
                                                p_segment10                  =>NULL,--p_segment10,
                                                p_segment11                  =>NULL,--p_segment11,
                                                p_segment12                  =>NULL,--p_segment12,
                                                p_segment13                  =>NULL,--p_segment13,
                                                p_segment14                  =>NULL,--p_segment14,
                                                p_segment15                  =>NULL,--p_segment15,
                                                p_segment16                  =>NULL,--p_segment16,
                                                p_segment17                  =>NULL,--p_segment17,
                                                p_segment18                  =>NULL,--p_segment18,
                                                p_segment19                  =>NULL,--p_segment19,
                                                p_segment20                  =>NULL,--p_segment20,
                                                p_segment21                  =>NULL,--p_segment21,
                                                p_segment22                  =>NULL,--p_segment22,
                                                p_segment23                  =>NULL,--p_segment23,
                                                p_segment24                  =>NULL,--p_segment24,
                                                p_segment25                  =>NULL,--p_segment25,
                                                p_segment26                  =>NULL,--p_segment26,
                                                p_segment27                  =>NULL,--p_segment27,
                                                p_segment28                  =>NULL,--p_segment28,
                                                p_segment29                  =>NULL,--p_segment29,
                                                P_SEGMENT30                  =>NULL);--p_segment30);

        EXCEPTION
        WHEN OTHERS THEN
        l_message := SUBSTR(SQLERRM,1,200);
        l_error := 'Y';
        DBMS_OUTPUT.PUT_LINE(l_message);       
        END;                                     
END IF;

IF l_error = 'Y' THEN
    p_status := 'FAILED';
ELSE
    p_status := 'SUCCESS';
    p_cost_allocation_keyflex_id := l_cost_allocation_keyflex_id;
END IF;

END;