Setting the Multi Org Context :


METHOD 1:

begin
    MO_GLOBAL.SET_POLICY_CONTEXT(ACCESS_MODE,ORG_ID);
end;

Example:

begin
    MO_GLOBAL.SET_POLICY_CONTEXT(‘S’,101);
end;

S – Denotes that the current session will work for Single Org_id (101)

M – Denotes that the current session will work for Multiple Org_id


 
METHOD 2:

begin
mo_global.init (<APPLICATION SHORT NAME>);
end;

Example :

begin
mo_global.init (‘AR’);
end;


Query :

select Application_short_name , application_name
from   fnd_application fapp,
       fnd_application_tl fappt
where  fapp.APPLICATION_ID = fappt.application_id
and    fappt.language = ‘US’
and    application_name = ‘General Ledger’

—————————————————————–

Setting the Application Context :

METHOD 1:

begin
fnd_global.apps_initialize(p_user_id, p_resp_id, p_resp_appl_id);
end;

Example :

begin
      fnd_global.APPS_INITIALIZE(200131258,20004,51710);
end;

begin
      fnd_global.APPS_INITIALIZE
      (user_id       => 200131258,
       resp_id       => 20004,
       resp_appl_id  => 51710
      );
end;

Query to find resp_is , resp_appl_id and user_id

select  responsibility_id
       ,application_id
       ,responsibility_name
from   fnd_responsibility_tl
where  upper(responsibility_name) IN ( upper(‘Receivables Manager’), upper(‘Application Developer’ ) )
and    language = ‘US’;


select  user_id
from    fnd_user
where  upper(user_name) = ‘SAIF’;

SELECT fnd_profile.value (‘RESP_ID’) FROM dual

SELECT fnd_profile.value (‘USER_ID’) FROM dual

SELECT fnd_profile.value (‘APPLICATION_ID’) FROM dual

SELECT TO_NUMBER (FND_PROFILE.VALUE( ‘LOGIN_ID ‘)) FROM dual

SELECT FND_PROFILE.VALUE(‘ORG_ID’) FROM dual

SELECT FND_PROFILE.VALUE(‘SO_ORGANIZATION_ID’) FROM dual

SELECT FND_PROFILE.VALUE(‘USERNAME’) FROM dual

SELECT FND_PROFILE.VALUE(‘GL_SET_OF_BKS_ID’) FROM dual

METHOD 2 :

begin
dbms_application_info.set_client_info(‘<org id>’);
end;

Example

begin
dbms_application_info.set_client_info(‘101’);
end;

CREATE OR REPLACE procedure APPS.xx_ar_invoice_api
is
l_return_status varchar2(1);
l_msg_count number;
l_msg_data varchar2(2000);
l_batch_source_rec ar_invoice_api_pub.batch_source_rec_type;
l_trx_header_tbl ar_invoice_api_pub.trx_header_tbl_type;
l_trx_lines_tbl ar_invoice_api_pub.trx_line_tbl_type;
l_trx_dist_tbl ar_invoice_api_pub.trx_dist_tbl_type;
l_trx_salescredits_tbl ar_invoice_api_pub.trx_salescredits_tbl_type;
l_cust_trx_id number;

BEGIN

begin
MO_GLOBAL.SET_POLICY_CONTEXT('S',82);
end;

fnd_global.apps_initialize(1090,20678,222);

l_batch_source_rec.batch_source_id := 1001;
l_trx_header_tbl(1).trx_header_id := 9898;
l_trx_header_tbl(1).trx_date := sysdate;
l_trx_header_tbl(1).trx_currency := 'AED';
l_trx_header_tbl(1).cust_trx_type_id := 1000;
l_trx_header_tbl(1).bill_to_customer_id := 1139;
l_trx_header_tbl(1).term_id := 1000;
l_trx_header_tbl(1).finance_charges := 'N';
l_trx_header_tbl(1).status_trx := 'OP';
l_trx_header_tbl(1).printing_option := 'NOT';
--l_trx_header_tbl(1).reference_number := '1111';
l_trx_lines_tbl(1).trx_header_id := 9898;
l_trx_lines_tbl(1).trx_line_id := 101;
l_trx_lines_tbl(1).line_number := 1;
l_trx_lines_tbl(1).inventory_item_id := 1185;
-- l_trx_lines_tbl(1).description := 'CAST IRON GRILL-325*485MM';
l_trx_lines_tbl(1).quantity_invoiced := 3;
l_trx_lines_tbl(1).unit_selling_price := 525; --Price
l_trx_lines_tbl(1).uom_code := 'EAC';
l_trx_lines_tbl(1).line_type := 'LINE';
l_trx_dist_tbl(1).trx_dist_id := 101;
l_trx_dist_tbl(1).trx_line_id := 101;
l_trx_dist_tbl(1).ACCOUNT_CLASS := 'REV';
l_trx_dist_tbl(1).percent := 100;
l_trx_dist_tbl(1).CODE_COMBINATION_ID := 1012;

--Here we call the API to create Invoice with the stored values


AR_INVOICE_API_PUB.create_invoice
(p_api_version => 1.0
--,p_commit => 'T'
,p_batch_source_rec => l_batch_source_rec
,p_trx_header_tbl => l_trx_header_tbl
,p_trx_lines_tbl => l_trx_lines_tbl
,p_trx_dist_tbl => l_trx_dist_tbl
,p_trx_salescredits_tbl => l_trx_salescredits_tbl
,x_return_status => l_return_status
,x_msg_count => l_msg_count
,x_msg_data => l_msg_data
);

dbms_output.put_line('Created:'||l_msg_data||l_return_status);

IF l_return_status = fnd_api.g_ret_sts_error OR
l_return_status = fnd_api.g_ret_sts_unexp_error THEN

dbms_output.put_line(l_return_status||':'||sqlerrm);
Else
dbms_output.put_line(l_return_status||':'||sqlerrm);
If (ar_invoice_api_pub.g_api_outputs.batch_id IS NOT NULL) Then
Dbms_output.put_line('Invoice(s) suceessfully created!') ;
Dbms_output.put_line('Batch ID: ' || ar_invoice_api_pub.g_api_outputs.batch_id);
Dbms_output.put_line('customer_trx_id: ' || l_cust_trx_id);
Else
Dbms_output.put_line(sqlerrm);
End If;
end if;
commit;
End;
/