Wednesday, February 2, 2011

Assign Delivery Details to a Delivery through API ( WSH_DELIVERY_DETAILS_PUB.DETAIL_TO_DELIVERY )

                                                                                                                        

Below script will be useful to assign a set of delivery details to a delivery programmatically using the API named WSH_DELIVERY_DETAILS_PUB.DETAIL_TO_DELIVERY. We have tested the script in R12.1.1 instance.

SCRIPT:
set serveroutput on;
DECLARE
  P_API_VERSION      NUMBER;
  P_INIT_MSG_LIST    VARCHAR2(200);
  P_COMMIT           VARCHAR2(200);
  P_VALIDATION_LEVEL NUMBER;
  X_RETURN_STATUS    VARCHAR2(200);
  X_MSG_COUNT        NUMBER;
  X_MSG_DATA         VARCHAR2(2000);
  P_TABOFDELDETS     APPS.WSH_DELIVERY_DETAILS_PUB.ID_TAB_TYPE;
  P_ACTION           VARCHAR2(200);
  P_DELIVERY_ID      NUMBER;
  P_DELIVERY_NAME    VARCHAR2(200);
  P_COUNT            NUMBER;
 
  V_CONTEXT          VARCHAR2(100);


FUNCTION set_context( i_user_name    IN  VARCHAR2
                     ,i_resp_name    IN  VARCHAR2
                     ,i_org_id       IN  NUMBER)
RETURN VARCHAR2
IS
v_user_id      NUMBER;
v_resp_id      NUMBER;
v_resp_appl_id NUMBER;
v_lang         VARCHAR2(100);
v_session_lang VARCHAR2(100):=fnd_global.current_language;
v_return       VARCHAR2(10):='T';
v_nls_lang     VARCHAR2(100);
v_org_id       NUMBER:=i_org_id;
/* Cursor to get the user id information based on the input user name */
CURSOR cur_user
IS
    SELECT     user_id
    FROM       fnd_user
    WHERE      user_name  =  i_user_name;
/* Cursor to get the responsibility information */
CURSOR cur_resp
IS
    SELECT     responsibility_id
              ,application_id
              ,language
    FROM       fnd_responsibility_tl
    WHERE      responsibility_name  =  i_resp_name;
/* Cursor to get the nls language information for setting the language context */
CURSOR cur_lang(p_lang_code VARCHAR2)
IS
    SELECT    nls_language
    FROM      fnd_languages
    WHERE     language_code  = p_lang_code;
BEGIN
    /* To get the user id details */
    OPEN cur_user;
    FETCH cur_user INTO v_user_id;
    IF cur_user%NOTFOUND
    THEN
        v_return:='F';
       
    END IF;
    CLOSE cur_user;

    /* To get the responsibility and responsibility application id */
    OPEN cur_resp;
    FETCH cur_resp INTO v_resp_id, v_resp_appl_id,v_lang;
    IF cur_resp%NOTFOUND
    THEN
        v_return:='F';
       
    END IF;
    CLOSE cur_resp;
   
    DBMS_OUTPUT.PUT_LINE (v_user_id||' ' ||v_resp_id|| ' ' ||v_resp_appl_id);

    /* Setting the oracle applications context for the particular session */
    fnd_global.apps_initialize ( user_id      => v_user_id
                                ,resp_id      => v_resp_id
                                ,resp_appl_id => v_resp_appl_id);

    /* Setting the org context for the particular session */
    mo_global.set_policy_context('S',v_org_id);

    /* setting the nls context for the particular session */
    IF v_session_lang != v_lang
    THEN
        OPEN cur_lang(v_lang);
        FETCH cur_lang INTO v_nls_lang;
        CLOSE cur_lang;
        fnd_global.set_nls_context(v_nls_lang);
    END IF; --IF v_session_lang != v_lang

    RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
    RETURN 'F';
END set_context;

BEGIN

  DBMS_OUTPUT.PUT_LINE('1');
  --1. Set applications context if not already set.
  v_context := set_context('&userid','&responsibility',93);
  IF v_context = 'F'
    THEN
        DBMS_OUTPUT.PUT_LINE('Error while setting the context');       
    END IF;
  DBMS_OUTPUT.PUT_LINE('2');

  MO_GLOBAL.init('ONT');

  P_API_VERSION      := 1.0;
  P_INIT_MSG_LIST    := FND_API.G_TRUE;
  P_COMMIT           := FND_API.G_TRUE;
  P_VALIDATION_LEVEL := FND_API.G_VALID_LEVEL_FULL;
 
  -- Initialize the PLSQL table type variable with 'N' number of Delivery Detail id's
  P_TABOFDELDETS(1)  := 216030;
  P_TABOFDELDETS(1)  := 216028;
 
  P_ACTION           := 'ASSIGN';  -- Provide the proper Action Type
  P_DELIVERY_ID      := 838214;      -- Delivery id to which the delivery details to be assigned
  P_DELIVERY_NAME    := '838214';    -- Respective delivery name

  WSH_DELIVERY_DETAILS_PUB.DETAIL_TO_DELIVERY
            (
              P_API_VERSION      => P_API_VERSION,
              P_INIT_MSG_LIST    => P_INIT_MSG_LIST,
              P_COMMIT           => P_COMMIT,
              P_VALIDATION_LEVEL => P_VALIDATION_LEVEL,
              X_RETURN_STATUS    => X_RETURN_STATUS,
              X_MSG_COUNT        => X_MSG_COUNT,
              X_MSG_DATA         => X_MSG_DATA,
              P_TABOFDELDETS     => P_TABOFDELDETS,
              P_ACTION           => P_ACTION,
              P_DELIVERY_ID      => P_DELIVERY_ID,
              P_DELIVERY_NAME    => P_DELIVERY_NAME
            );
  IF X_RETURN_STATUS = 'S' THEN
   DBMS_OUTPUT.PUT_LINE('Assigned Sucessfully ');
  ELSE
   DBMS_OUTPUT.PUT_LINE('Message count ' || X_MSG_COUNT);
   IF X_MSG_COUNT = 1 THEN
      DBMS_OUTPUT.PUT_LINE('X_msg_data '||X_MSG_DATA);
   ELSIF X_MSG_COUNT > 1 THEN
   LOOP
      P_COUNT := P_COUNT+1;
      V_MSG_DATA := FND_MSG_PUB.GET(FND_MSG_PUB.G_NEXT,FND_API.G_FALSE);
      IF X_MSG_DATA IS NULL THEN
      EXIT;
      END IF;
      DBMS_OUTPUT.PUT_LINE('Message' || P_COUNT ||'---'||X_MSG_DATA);
      END LOOP;
   END IF;
  END IF;
END;

0 Responses to “Assign Delivery Details to a Delivery through API ( WSH_DELIVERY_DETAILS_PUB.DETAIL_TO_DELIVERY )”

Post a Comment

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.