Loading

Tuesday, February 1, 2011

AR_RECEIPT_API_PUB.Apply_on_account ( Script to apply a receipt on account )

  
Below script will help you apply a receipt on account using the API AR_RECEIPT_API_PUB.Apply_on_account.
This script was tested in R12.1.1 instance.

Script:

set serveroutput on;
DECLARE

v_return_status      VARCHAR2(1);
v_msg_count          NUMBER;
v_msg_data           VARCHAR2(240);
v_count              NUMBER;
v_receipt_number     VARCHAR2(240) := 'SHAREORACLEAPPS';
v_org_id             NUMBER        := 93;
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','&org_id');
IF v_context = 'F'
    THEN
        DBMS_OUTPUT.PUT_LINE('Error while setting the context');       
    END IF;
DBMS_OUTPUT.PUT_LINE('2');

MO_GLOBAL.init('AR');

AR_RECEIPT_API_PUB.Apply_on_account
            ( 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,
              x_return_status    => v_return_status,
              x_msg_count        => v_msg_count,
              x_msg_data         => v_msg_data,
              p_receipt_number   => v_receipt_number,
              p_org_id           => v_org_id
            );

IF v_return_status = 'S' THEN
   DBMS_OUTPUT.put_line('Receipt applied on account ');
ELSE
   DBMS_OUTPUT.put_line('Message count ' || v_msg_count);
   IF v_msg_count = 1 THEN
      DBMS_OUTPUT.put_line('v_msg_data '||v_msg_data);
   ELSIF v_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 v_msg_data IS NULL THEN
      EXIT;
      END IF;
      DBMS_OUTPUT.put_line('Message' || p_count ||'---'||v_msg_data);
      END LOOP;
      END IF;
END IF;
END;
/

1 Responses to “AR_RECEIPT_API_PUB.Apply_on_account ( Script to apply a receipt on account )”

Anonymous said...
August 12, 2012 at 11:07 PM

FOR WHAT THIS API IS USED?


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.