Wednesday, November 6, 2013

API to Load FND_FLEX_VALUES with p_compiled_value_attributes

CREATE OR REPLACE PROCEDURE xxx_load_flex_values
IS
   l_row_id              VARCHAR2 (500) := NULL;
   l_flex_value_set_id   NUMBER := NULL;
   l_flex_value_id       NUMBER := NULL;
   l_err_msg             VARCHAR2 (500) := NULL;
   l_db_nls_language     VARCHAR2 (500) := NULL;

   CURSOR fetch_details
   IS
      SELECT * FROM xxx_fin_location_t where process_flag = 'N';
BEGIN
   --Set NLS_LANG to Arabic to insert  Arabic Values
   fnd_global.set_nls (p_nls_language                => 'AMERICAN',
                       p_nls_date_format             => NULL,
                       p_nls_date_language           => NULL,
                       p_nls_numeric_characters      => NULL,
                       p_nls_sort                    => NULL,
                       p_nls_territory               => NULL,
                       p_db_nls_language             => l_db_nls_language,
                       p_db_nls_date_format          => l_db_nls_language,
                       p_db_nls_date_language        => l_db_nls_language,
                       p_db_nls_numeric_characters   => l_db_nls_language,
                       p_db_nls_sort                 => l_db_nls_language,
                       p_db_nls_territory            => l_db_nls_language,
                       p_db_nls_charset              => l_db_nls_language);


   -- Get Value Set ID
   SELECT flex_value_set_id
     INTO l_flex_value_set_id
     FROM apps.fnd_flex_value_sets
    WHERE flex_value_set_name = 'xxx_GL_SUBLOCATION'; -- Change the Name as per Value Set

   FOR get_details IN fetch_details
   LOOP
      -- Get Next Sequence Number
      SELECT apps.fnd_flex_values_s.NEXTVAL INTO l_flex_value_id FROM DUAL;

      BEGIN
         apps.fnd_flex_values_pkg.
          insert_row (
            x_rowid                        => l_row_id,
            x_flex_value_id                => l_flex_value_id,
            x_attribute_sort_order         => NULL,
            x_flex_value_set_id            => l_flex_value_set_id,
            x_flex_value                   => get_details.location_code,
            x_enabled_flag                 => 'Y',
            x_summary_flag                 => 'N',
            x_start_date_active            => TO_DATE ('01-JAN-1950', 'DD-MON-YYYY'),
            x_end_date_active              => NULL,
            x_parent_flex_value_low        => NULL,
            x_parent_flex_value_high       => NULL,
            x_structured_hierarchy_level   => NULL,
            x_hierarchy_level              => NULL,
            x_compiled_value_attributes    =>  'Y'||CHR(10)||'Y',
            x_value_category               => NULL,
            x_attribute1                   => NULL,
            x_attribute2                   => NULL,
            x_attribute3                   => NULL,
            x_attribute4                   => NULL,
            x_attribute5                   => NULL,
            x_attribute6                   => NULL,
            x_attribute7                   => NULL,
            x_attribute8                   => NULL,
            x_attribute9                   => NULL,
            x_attribute10                  => NULL,
            x_attribute11                  => NULL,
            x_attribute12                  => NULL,
            x_attribute13                  => NULL,
            x_attribute14                  => NULL,
            x_attribute15                  => NULL,
            x_attribute16                  => NULL,
            x_attribute17                  => NULL,
            x_attribute18                  => NULL,
            x_attribute19                  => NULL,
            x_attribute20                  => NULL,
            x_attribute21                  => NULL,
            x_attribute22                  => NULL,
            x_attribute23                  => NULL,
            x_attribute24                  => NULL,
            x_attribute25                  => NULL,
            x_attribute26                  => NULL,
            x_attribute27                  => NULL,
            x_attribute28                  => NULL,
            x_attribute29                  => NULL,
            x_attribute30                  => NULL,
            x_attribute31                  => NULL,
            x_attribute32                  => NULL,
            x_attribute33                  => NULL,
            x_attribute34                  => NULL,
            x_attribute35                  => NULL,
            x_attribute36                  => NULL,
            x_attribute37                  => NULL,
            x_attribute38                  => NULL,
            x_attribute39                  => NULL,
            x_attribute40                  => NULL,
            x_attribute41                  => NULL,
            x_attribute42                  => NULL,
            x_attribute43                  => NULL,
            x_attribute44                  => NULL,
            x_attribute45                  => NULL,
            x_attribute46                  => NULL,
            x_attribute47                  => NULL,
            x_attribute48                  => NULL,
            x_attribute49                  => NULL,
            x_attribute50                  => NULL,
            x_flex_value_meaning           => get_details.location_code,
            x_description                  => get_details.location_eng,
            x_creation_date                => SYSDATE,
            x_created_by                   => fnd_global.user_id,
            x_last_update_date             => SYSDATE,
            x_last_updated_by              => fnd_global.user_id,
            x_last_update_login            => fnd_global.user_id);

         UPDATE xxx_fin_location_t
            SET process_flag = 'Y'
          WHERE location_eng = get_details.location_eng;

         COMMIT;
      EXCEPTION
         WHEN OTHERS
         THEN
            l_err_msg := SQLERRM;

            UPDATE xxx_fin_location_t
               SET process_flag = 'N', err_msg = l_err_msg
             WHERE location_eng = get_details.location_eng;

            COMMIT;
      END;
   END LOOP;
EXCEPTION
   WHEN OTHERS
   THEN
      l_err_msg := SQLERRM;
      DBMS_OUTPUT.put_line ('Main Exception: ' || l_err_msg);
END;



No comments:

Post a Comment