/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2016 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

CREATE OR REPLACE VIEW xxas_cagr_key_ff_v
AS
SELECT  pcgd.cagr_grade_def_id
       ,pcgd.id_flex_num
       ,pcgd.segment1              cagr_segment1
       ,pcgd_tbl.segment1_value    cagr_segment1_value
       ,pcgd_tbl.segment1_meaning  cagr_segment1_meaning
       ,pcgd.segment2              cagr_segment2
       ,pcgd_tbl.segment2_value    cagr_segment2_value
       ,pcgd_tbl.segment2_meaning  cagr_segment2_meaning
       ,pcgd.segment3              cagr_segment3
       ,pcgd_tbl.segment3_value    cagr_segment3_value
       ,pcgd_tbl.segment3_meaning  cagr_segment3_meaning
       ,pcgd.segment4              cagr_segment4
       ,pcgd_tbl.segment4_value    cagr_segment4_value
       ,pcgd_tbl.segment4_meaning  cagr_segment4_meaning
       ,pcgd.segment5              cagr_segment5
       ,pcgd_tbl.segment5_value    cagr_segment5_value
       ,pcgd_tbl.segment5_meaning  cagr_segment5_meaning
       ,pcgd.segment6              cagr_segment6
       ,pcgd_tbl.segment6_value    cagr_segment6_value
       ,pcgd_tbl.segment6_meaning  cagr_segment6_meaning
       ,pcgd.segment7              cagr_segment7
       ,pcgd_tbl.segment7_value    cagr_segment7_value
       ,pcgd_tbl.segment7_meaning  cagr_segment7_meaning
       ,pcgd.segment8              cagr_segment8
       ,pcgd_tbl.segment8_value    cagr_segment8_value
       ,pcgd_tbl.segment8_meaning  cagr_segment8_meaning
       ,pcgd.segment9              cagr_segment9
       ,pcgd_tbl.segment9_value    cagr_segment9_value
       ,pcgd_tbl.segment9_meaning  cagr_segment9_meaning
       ,pcgd.segment10             cagr_segment10
       ,pcgd_tbl.segment10_value   cagr_segment10_value
       ,pcgd_tbl.segment10_meaning cagr_segment10_meaning
       ,pcgd.segment11             cagr_segment11
       ,pcgd_tbl.segment11_value   cagr_segment11_value
       ,pcgd_tbl.segment11_meaning cagr_segment11_meaning
       ,pcgd.segment12             cagr_segment12
       ,pcgd_tbl.segment12_value   cagr_segment12_value
       ,pcgd_tbl.segment12_meaning cagr_segment12_meaning
       ,pcgd.segment13             cagr_segment13
       ,pcgd_tbl.segment13_value   cagr_segment13_value
       ,pcgd_tbl.segment13_meaning cagr_segment13_meaning
       ,pcgd.segment14             cagr_segment14
       ,pcgd_tbl.segment14_value   cagr_segment14_value
       ,pcgd_tbl.segment14_meaning cagr_segment14_meaning
       ,pcgd.segment15             cagr_segment15
       ,pcgd_tbl.segment15_value   cagr_segment15_value
       ,pcgd_tbl.segment15_meaning cagr_segment15_meaning
       ,pcgd.segment16             cagr_segment16
       ,pcgd_tbl.segment16_value   cagr_segment16_value
       ,pcgd_tbl.segment16_meaning cagr_segment16_meaning
       ,pcgd.segment17             cagr_segment17
       ,pcgd_tbl.segment17_value   cagr_segment17_value
       ,pcgd_tbl.segment17_meaning cagr_segment17_meaning
       ,pcgd.segment18             cagr_segment18
       ,pcgd_tbl.segment18_value   cagr_segment18_value
       ,pcgd_tbl.segment18_meaning cagr_segment18_meaning
       ,pcgd.segment19             cagr_segment19
       ,pcgd_tbl.segment19_value   cagr_segment19_value
       ,pcgd_tbl.segment19_meaning cagr_segment19_meaning
       ,pcgd.segment20             cagr_segment20
       ,pcgd_tbl.segment20_value   cagr_segment20_value
       ,pcgd_tbl.segment20_meaning cagr_segment20_meaning
FROM    per_cagr_grades_def    pcgd
       ,fnd_id_flex_structures fifs 
       ,table(xxas_com_flex_pkg.kff_value_set_details
                (xxas_util_pkg.get_app_id('PER')
                ,'SCL'
                ,fifs.id_flex_structure_code
                ,'SEGMENT1'
                ,pcgd.segment1
                ,'SEGMENT2'
                ,pcgd.segment2
                ,'SEGMENT3'
                ,pcgd.segment3
                ,'SEGMENT4'
                ,pcgd.segment4
                ,'SEGMENT5'
                ,pcgd.segment5
                ,'SEGMENT6'
                ,pcgd.segment6
                ,'SEGMENT7'
                ,pcgd.segment7
                ,'SEGMENT8'
                ,pcgd.segment8
                ,'SEGMENT9'
                ,pcgd.segment9
                ,'SEGMENT10'
                ,pcgd.segment10
                ,'SEGMENT11'
                ,pcgd.segment11
                ,'SEGMENT12'
                ,pcgd.segment12
                ,'SEGMENT13'
                ,pcgd.segment13
                ,'SEGMENT14'
                ,pcgd.segment14
                ,'SEGMENT15'
                ,pcgd.segment15
                ,'SEGMENT16'
                ,pcgd.segment16
                ,'SEGMENT17'
                ,pcgd.segment17
                ,'SEGMENT18'
                ,pcgd.segment18
                ,'SEGMENT19'
                ,pcgd.segment19
                ,'SEGMENT20'
                ,pcgd.segment20
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL
                ,NULL)) pcgd_tbl
WHERE   pcgd.id_flex_num    = fifs.id_flex_num
AND     fifs.application_id = xxas_util_pkg.get_app_id('PER')
AND     fifs.id_flex_code   = 'CAGR';

BEGIN
  xxas_fnd_dictionary_pkg.add_view
   (p_application_short_name => xxas_util_pkg.app
   ,p_view_name              => 'XXAS_CAGR_KEY_FF_V'
   ,p_description            => 'Applaud CAGR Key Flex Field View');
END;
/

COMMIT;
EXIT;

