Friday, September 20, 2013

API to Create/Delete the Categories.

DECLARE
   l_category_rec                                    inv_item_category_pub.category_rec_type;
   x_return_status                                   VARCHAR2 (1);
   x_error_code                                      NUMBER;
   x_msg_count                                       NUMBER;
   x_msg_data                                        VARCHAR2 (250);
   l_out_category_id                                 NUMBER;
   l_msg_index_out                                   NUMBER;
   l_error_message                                   VARCHAR2 (2000);
BEGIN
   l_category_rec.segment1                                  := 'Test';
   l_category_rec.segment2                                  := 'Test';
   l_category_rec.segment3                                  := 'Test';
   l_category_rec.segment4                                  := 'Test';
   l_category_rec.segment5                                  := 'Test';
   l_category_rec.segment6                                  := 'Test1';
   fnd_global.apps_initialize (10089, 20634, 401);
   COMMIT;

   SELECT f.id_flex_num
     INTO l_category_rec.structure_id
     FROM fnd_id_flex_structures f
    WHERE UPPER (f.id_flex_structure_code) = 'REV ITEM CATEGORY';

   l_category_rec.description                               := 'Test Category Codes';
   inv_item_category_pub.create_category (p_api_version                 => 1.0
                                        , p_init_msg_list               => fnd_api.g_false
                                        , p_commit                      => fnd_api.g_true
                                        , x_return_status               => x_return_status
                                        , x_errorcode                   => x_error_code
                                        , x_msg_count                   => x_msg_count
                                        , x_msg_data                    => x_msg_data
                                        , p_category_rec                => l_category_rec
                                        , x_category_id                 => l_out_category_id
                                         );
   DBMS_OUTPUT.put_line ('API Return Status : ' || l_return_status);

   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index                   => i
                             , p_encoded                     => fnd_api.g_false
                             , p_data                        => x_msg_data
                             , p_msg_index_out               => l_msg_index_out
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message                                          := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message                                          :=
                                                                      l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;

      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      DBMS_OUTPUT.put_line ('*****************************************');
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('Category Comibination Create Successfully. Category Id = ' || l_out_category_id);
      DBMS_OUTPUT.put_line ('*****************************************');
      COMMIT;
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Unexpected Error ' || SUBSTR (SQLERRM, 1, 250));
END;

---******************************
--- Delete Category Api
---******************************

DECLARE
   x_return_status                                   VARCHAR2 (80);
   x_error_code                                      NUMBER;
   x_msg_count                                       NUMBER;
   x_msg_data                                        VARCHAR2 (80);
   l_category_id                                     NUMBER := 1842;
   l_msg_index_out                                   NUMBER;
   l_error_message                                   VARCHAR2 (2000);
BEGIN
   inv_item_category_pub.delete_category (p_api_version                 => 1.0
                                        , p_init_msg_list               => fnd_api.g_false
                                        , p_commit                      => fnd_api.g_true
                                        , x_return_status               => x_return_status
                                        , x_errorcode                   => x_error_code
                                        , x_msg_count                   => x_msg_count
                                        , x_msg_data                    => x_msg_data
                                        , p_category_id                 => l_category_id
                                         );
   DBMS_OUTPUT.put_line ('l_return_status : ' || l_return_status);

   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index                   => i
                             , p_encoded                     => fnd_api.g_false
                             , p_data                        => x_msg_data
                             , p_msg_index_out               => l_msg_index_out
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message                                          := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message                                          :=
                                                                      l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;

      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      DBMS_OUTPUT.put_line ('*****************************************');
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('Deleted Category Id : ' || l_category_id || ' Successfully');
      DBMS_OUTPUT.put_line ('*****************************************');
      COMMIT;
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Unexpected Error ' || SUBSTR (SQLERRM, 1, 250));
END;

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.