Thursday, February 3, 2011

Create and Release Pciking Batch via API (wsh_picking_batches_pub.create_batch and wsh_picking_batches_pub.Release_batch)

                                                                                                      

Below script will help you to create a Picking batch in the table WSH_PICKING_BATCHES and release them through API named wsh_picking_batches_pub.create_batch and wsh_picking_batches_pub.Release_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;
l_REQUEST_ID      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','&RESPONSIILITY',39);
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                := 6898;
l_batch_info_rec.order_header_id            := 9766;
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;
l_rule_name := 'FL1 Stockton Manual';
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;

-- Release the batch Created Above

WSH_PICKING_BATCHES_PUB.RELEASE_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_BATCH_ID      => p_new_batch_id,
    P_BATCH_NAME    => NULL,
    P_LOG_LEVEL     => 1,
    P_RELEASE_MODE  => 'ONLINE',-- (ONLINE or CONCURRENT)
    X_REQUEST_ID    => l_REQUEST_ID
  );

IF l_return_status = 'S' THEN
   DBMS_OUTPUT.put_line('Pick Selection List Generation '||l_REQUEST_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;

5 Responses to “Create and Release Pciking Batch via API (wsh_picking_batches_pub.create_batch and wsh_picking_batches_pub.Release_batch)”

raj said...
May 5, 2011 at 10:12 PM

Hi
Does the script perform all the following? "Delivery , Delivery Line , Trip , PICKING_BATCHES"
Please confirm.

Regards,


raj said...
May 7, 2011 at 2:11 AM

Hello there,
I managed to try out your script and everything works fine, but P_RELEASE_MODE => 'ONLINE'. Until I change it to 'CONCURRENT' the process keeps on providing errors stating shipping has errors.
Our primary aim is to exclude the concurrent process call for "Delivery , Delivery Line , Trip , PICKING_BATCHES" processes.

When I run the script with 'ONLINE' method, though it errors out, I could see that the lines get shipped as expected. However unless knowing why the error are populated by the script, cannot integrate with a custom development. Please help.

Regards,


Anonymous said...
June 27, 2012 at 5:29 PM

Hi
I used this script but it is not creating DELIVERY_ID somehow, and line status still shows "Awaiting Shipping".
Do you have any idea why ?

Thanks,
Anu


Anonymous said...
February 24, 2013 at 6:25 AM

Thanks,

This is API is workinf fine.

Vinay


Ruichi Kagoyasha said...
November 4, 2015 at 8:07 PM

i will ask something, when execute this procedure how to determine for location sub inventory when pick release.
thank you.


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.