Thursday, February 3, 2011

Picking Batch Creation Through API ( wsh_picking_batches_pub.create_batch)

                                                                                                                

Below script will help you to create a Picking batch in the table WSH_PICKING_BATCHES through API named wsh_picking_batches_pub.create_batch. We have tested this script in Oracle Apps R12.1.1 instance.

Script:

SET SERVEROUTPUT ON;
Declare
l_return_status   VARCHAR2 (1);
l_msg_count       NUMBER (15);
l_msg_data        VARCHAR2 (2000);
l_count           NUMBER (15);
l_msg_data_out    VARCHAR2 (2000);
l_mesg            VARCHAR2 (2000);
p_count           NUMBER (15);
p_new_batch_id    NUMBER;
l_rule_id         NUMBER;
l_rule_name       VARCHAR2 (2000);
l_batch_prefix    VARCHAR2 (2000);
l_batch_info_rec  wsh_picking_batches_pub.batch_info_rec;

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('&USERNAME','&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');

l_batch_info_rec.backorders_only_flag       := 'E';
l_batch_info_rec.existing_rsvs_only_flag    := 'N';
l_batch_info_rec.customer_id                := 6798;
l_batch_info_rec.order_header_id            := 9484;
l_batch_info_rec.from_scheduled_ship_date   := NULL;
l_batch_info_rec.organization_id            := 92;
l_batch_info_rec.include_planned_lines      := 'N';
l_batch_info_rec.autocreate_delivery_flag   := 'Y';
l_batch_info_rec.autodetail_pr_flag         := 'Y';
l_batch_info_rec.allocation_method          := 'I';
l_batch_info_rec.pick_from_locator_id       := NULL;
l_batch_info_rec.auto_pick_confirm_flag     := 'Y';
l_batch_info_rec.autopack_flag              := 'Y';
l_rule_id := 10;  -- Picking rule id from WSH_PICKING_RULES
l_rule_name := 'FL1 Manual'; -- Picking rule name from WSH_PICKING_RULES
l_batch_prefix := NULL;

wsh_picking_batches_pub.create_batch
       (
           p_api_version   => 1.0,
         p_init_msg_list => fnd_api.g_true,
         p_commit        => fnd_api.g_true,
         x_return_status => l_return_status,
         x_msg_count     => l_msg_count,
         x_msg_data      => l_msg_data,
         p_rule_id       => l_rule_id,
         p_rule_name     => l_rule_name,
         p_batch_rec     => l_batch_info_rec,
         p_batch_prefix  => l_batch_prefix,
         x_batch_id      => p_new_batch_id
       );

IF l_return_status = 'S' THEN
   DBMS_OUTPUT.put_line('Pick Release Batch Got Created Sucessfully '||p_new_batch_id);
ELSE
   DBMS_OUTPUT.put_line('Message count ' || l_msg_count);
   IF l_msg_count = 1 THEN
      DBMS_OUTPUT.put_line('l_msg_data '||l_msg_data);
   ELSIF l_msg_count > 1 THEN
   LOOP
      p_count := p_count+1;
      l_msg_data := FND_MSG_PUB.Get(FND_MSG_PUB.G_NEXT,FND_API.G_FALSE);
      IF l_msg_data IS NULL THEN
      EXIT;
      END IF;
      DBMS_OUTPUT.put_line('Message' || p_count ||'---'||l_msg_data);
      END LOOP;
      END IF;
END IF;
END;
/

0 Responses to “Picking Batch Creation Through API ( wsh_picking_batches_pub.create_batch)”

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.