Friday, 10 January 2014

API - Assign Categries to Inventory Items

DECLARE

 X_RETURN_STATUS  VARCHAR2(1000);
 X_ERRORCODE         NUMBER;
 X_MSG_COUNT        NUMBER;
 X_MSG_DATA          VARCHAR2(1000);
 X_MSG_INDEX_OUT VARCHAR2(2000);
 L_ERROR_MESSAGE VARCHAR2(2000);

 BEGIN

   --Apps Initialization is available in another section. Use the below link to know in detail
    --     Apps_Initialize;

 INV_ITEM_CATEGORY_PUB.CREATE_CATEGORY_ASSIGNMENT
                                                 (  P_API_VERSION           => 1.0,
                                                    P_INIT_MSG_LIST         => FND_API.G_FALSE,
                                                    P_COMMIT                => FND_API.G_FALSE,
                                                    X_RETURN_STATUS         => X_RETURN_STATUS,
                                                    X_ERRORCODE             => X_ERRORCODE,
                                                    X_MSG_COUNT             => X_MSG_COUNT,
                                                    X_MSG_DATA              => X_MSG_DATA,
                                                    P_CATEGORY_ID           => 1355,                                          -- Category id to be assigned
                                                    P_CATEGORY_SET_ID       => 1100000043,                            -- Category Set id
                                                    P_INVENTORY_ITEM_ID     => 25803,                                    -- Inventory Item Id
                                                    P_ORGANIZATION_ID       => 755);                                       -- Warehouse

    IF x_return_status = fnd_api.g_ret_sts_success
    THEN
       COMMIT;
       DBMS_OUTPUT.put_line ('Item Category Assignment using API is Successful');
  
    ELSE
       BEGIN
          IF (fnd_msg_pub.count_msg > 1)
          THEN
             FOR k IN 1 .. fnd_msg_pub.count_msg
             LOOP
                fnd_msg_pub.get (p_msg_index            => k,
                                              p_encoded            => 'F',
                                              p_data                 => x_msg_data,
                                              p_msg_index_out   => x_msg_index_out
                                             );

                DBMS_OUTPUT.PUT_LINE('x_msg_data:= ' || x_msg_data);
                IF x_msg_data IS NOT NULL
                THEN
                   l_error_message := l_error_message || '-' || x_msg_data;
                END IF;
             END LOOP;
          ELSE
             --Only one error
             fnd_msg_pub.get (p_msg_index             => 1,
                                            p_encoded            => 'F',
                                            p_data                 => x_msg_data,
                                            p_msg_index_out   => x_msg_index_out
                                          );
             l_error_message := x_msg_data;
          END IF;

          DBMS_OUTPUT.put_line (   'Error encountered by the API is '
                                || l_error_message
                               );
          ROLLBACK;
       EXCEPTION
          WHEN OTHERS
          THEN
             l_error_message := SQLERRM;
             DBMS_OUTPUT.put_line (   'Error encountered by the API is '
                                   || l_error_message
                                  );
       END;
    END IF;

 EXCEPTION
   WHEN OTHERS THEN
       DBMS_OUTPUT.put_line('Error in Assigning Category to an Item and error is '||SUBSTR(SQLERRM,1,200));
 END;

No comments:

Post a Comment