You are html tracking Visitor

Thursday, July 3, 2008

Pragma

PRAGMA
Signifies that the statement is a pragma (compiler directive). Pragmas are processed at compile time, not at run time. They do not affect the meaning of a program; they simply convey information to the compiler.

1) Autonomous Transaction

Autonomous Transactions is the child transaction, which are Independent of Parent transactions. In Our Example, p1 is child transaction, which is used in the Parent transaction.


Example
: -

CREATE or REPLACE Procedure p1 IS
Pragma Autonomous_transaction;
BEGIN
INSERT INTO TEST_T VALUES (1111,’PHANI1’);
COMMIT;
END;

In the Declaration section, you will declare this Transaction as the Autonomous Transaction.

DECLARE
A NUMBER;
BEGIN
INSERT INTO TEST_T VALUES (2222,’JACK’);
P1;
ROLLBACK;
END;

NOW Table has (1111,’PHANI’) Record. COMMIT in the PROCEDURE P1 have not commit the Outside (p1) DML operations. It will just commit p1 transactions.

The ROLLBACK will not rollback PHANI record, it will just rollback the JACK record.

CREATE or REPLACE Procedure p1 IS
BEGIN
INSERT INTO TEST_T VALUES (1111,’PHANI1’);
COMMIT;
END;


If I remove the Pragma Autonomous_transaction From the declaration section, then this transaction will become the normal transaction. Now if you try to use the same parent transaction as given below.

>> delete from TEST_T;

DECLARE
A NUMBER;
BEGIN
INSERT INTO TEST_T VALUES (2222,’JACK’);
P1; -- This transaction has ended with the COMMIT;
ROLLBACK;
END;


After executing the above transaction, you can see BOTH records got Inserted (PHANI and JACK records). Here COMMIT in P1 will commit both transactions (PHANI and JACK Records Insert) And then Rollback. Since, there are no transactions happening between COMMIT and ROLLBACK. Our ROLLBACK is not doing any ROLLBACK.

Note: - IF COMMIT is not given in P1 then, the ROLLBACK will do the ROLLBACK both the INSERT transaction (PHANI Record which is in p1 procedure and JACK Record).

2) Pragma Restrict_references

It gives the Purity Level of the Function in the package.

CREATE OR REPLACE PACKAGE PKG12 AS
FUNCTION F1 RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES (F1, WNDS,
RNDS,
WNPS,
RNPS);
END PKG12;

CREATE OR REPLACE PACKAGE BODY PKG12 AS
FUNCTION F1 RETURN NUMBER IS
X NUMBER;
BEGIN
SELECT EMPNO INTO X FROM SCOTT.EMP
WHERE ENAME LIKE ‘SCOTT’;
DBMS_OUTPUT.PUT_LINE (X);
RETURN (X);
END F1;
END PKG12;

You will get the Violate It’s Associated Pragma Error. This in Purity Level, we said

It cannot read from the database. RNDS (In Our Function F1, we have SELECT STATEMENT which is reading the data from the database).

3) Pragma SERIALLY_REUSABLE


In my 5 Years of Experience in the Oracle Applications, I have never found the requirement to use this feature :). But, I found this feature is used in some standard Oracle Packages. We may use this feature for improving the performance or to meet certain requirements.

This pragma is appropriate for packages that declare large temporary work areas that are used once and not needed during subsequent database calls in the same session.

You can mark a bodiless package as serially reusable. If a package has a spec and body, you must mark both. You cannot mark only the body.

The global memory for serially reusable packages is pooled in the System Global Area (SGA), not allocated to individual users in the User Global Area (UGA). That way, the package work area can be reused. When the call to the server ends, the memory is returned to the pool. Each time the package is reused, its public variables are initialized to their default values or to NULL.

Serially reusable packages cannot be accessed from database triggers or other PL/SQL subprograms that are called from SQL statements. If you try, Oracle generates an error.


Examples

WITH PRAGMA SERIALLY_REUSABLE

The following example creates a serially reusable package:

CREATE PACKAGE pkg1 IS

PRAGMA SERIALLY_REUSABLE;

num NUMBER := 0;

PROCEDURE init_pkg_state(n NUMBER);

PROCEDURE print_pkg_state;

END pkg1;

/

CREATE PACKAGE BODY pkg1 IS

PRAGMA SERIALLY_REUSABLE;

PROCEDURE init_pkg_state (n NUMBER) IS

BEGIN

pkg1.num := n;

END;

PROCEDURE print_pkg_state IS

BEGIN

dbms_output.put_line('Num: ' || pkg1.num);

END;

END pkg1;

/

begin

pkg1.init_pkg_state(10);

pkg1.PRINT_PKG_STATE;

end;

Num: 10

begin

pkg1.PRINT_PKG_STATE;

end;

Num: 0

Note: - The first block is changing the value of the variable (num) to 10 and if I check the value in same block then it is showing the changed value that is 10. But, if I try to check the value of the (num) variable then it should the default value given to it (i.e.) “0”

WITHOUT PRAGMA SERIALLY_REUSABLE

CREATE OR REPLACE PACKAGE pkg1 IS

num NUMBER := 0;

PROCEDURE init_pkg_state(n NUMBER);

PROCEDURE print_pkg_state;

END pkg1;

CREATE PACKAGE BODY pkg1 IS

PROCEDURE init_pkg_state (n NUMBER) IS

BEGIN

pkg1.num := n;

END;

PROCEDURE print_pkg_state IS

BEGIN

dbms_output.put_line('Num: ' || pkg1.num);

END;

END pkg1;

begin

pkg1.init_pkg_state(10);

pkg1.PRINT_PKG_STATE;

end;

>>Num: 10

begin

pkg1.PRINT_PKG_STATE;

end;

>>Num: 10

Note: - Now, you may noticed the difference. The second block is giving us the changed value.

DROP PACKAGE pkg1;

(There are many other pragma's like Pragma Exception_init etc. I have not convered these concepts in this article. I will cover them in Exception concept article).

NOCOPY

NOCOPY Hint Demo:-
------------------------

The NOCOPY hint tells the PL/SQL compiler to pass OUT and IN OUT parameters by reference, rather than by value.

When parameters are passed by value, the contents of the OUT and IN OUT parameters are copied to temporary variables, which are then used by the subprogram being called. On successful completion of the subprogram the values are copied back to the actual parameters, but unhandled exceptions result in the original parameter values being left unchanged. The process of copying large parameters, such as records, collections, and objects requires both time and memory which affects performance.

With the NOCOPY hint the parameters are passed by reference and on successful completion the outcome is the same, but unhandled exceptions may leave the parameters in an altered state, so programs must handle errors or cope with the suspect values.

The nocopy.sql script compares the performance of both methods by passing a populated collection as a parameter.

nocopy.sql

SET SERVEROUTPUT ON
DECLARE

TYPE t_tab IS TABLE OF VARCHAR2(32767);
l_tab t_tab := t_tab();
l_start NUMBER;

PROCEDURE in_out (p_tab IN OUT t_tab) IS
BEGIN
NULL;
END;

PROCEDURE in_out_nocopy (p_tab IN OUT NOCOPY t_tab) IS
BEGIN
NULL;
END;

BEGIN
l_tab.extend;
l_tab(1) := '1234567890123456789012345678901234567890';
l_tab.extend(999999, 1); -- Copy element 1 into 2..1000000


-- Time normal IN OUT
l_start := DBMS_UTILITY.get_time;

in_out(l_tab);

DBMS_OUTPUT.put_line('IN OUT : ' ||
(DBMS_UTILITY.get_time - l_start));

-- Time IN OUT NOCOPY
l_start := DBMS_UTILITY.get_time;

in_out_nocopy(l_tab); -- pass IN OUT NOCOPY parameter

DBMS_OUTPUT.put_line('IN OUT NOCOPY: ' ||
(DBMS_UTILITY.get_time - l_start));
END;
/

The output of the script clearly demonstrates the performance improvements possible when using the NOCOPY hint.

SQL> @nocopy.sql

IN OUT : 122
IN OUT NOCOPY: 0

PL/SQL procedure successfully completed.

Registering Executable, Concurrent Program etc from backend

For Registering the Executable from backend.

PROMPT Creating Concurrent Executable XXM_XYZ_EMPLOYEE ......
PROMPT

BEGIN
FND_PROGRAM.executable('XXM_XYZ_EMPLOYEE' -- executable
, 'ABC' -- application
, 'ABC_XYZ_EMPLOYEE' -- short_name
, 'Executable for Migrating Employee' -- description
, 'PL/SQL Stored Procedure' -- execution_method
, 'abc_xyz_employee_pkg.create_employee' -- execution_file_name
, '' -- subroutine_name
, '' -- icon_name
, 'US' -- language_code
, '');

END;
/

For Registering the Concurrent program for the Executable file created.

PROMPT Creating Concurrent Program ABC_XYZ_EMPLOYEE ...
PROMPT

BEGIN
FND_PROGRAM.register('ABC Data migration program for HR-Employee' -- program
, 'XXM' -- application
, 'Y' -- enabled
, 'ABC_XYZ_EMPLOYEE' -- short_name
, 'Data Migration Program for Migrating HR-Employee' -- description
, 'ABC_XYZ_EMPLOYEE' -- executable_short_name
, 'XYZ' -- executable_application
, '' -- execution_options
, '' -- priority
, 'Y' -- save_output
, 'Y' -- print
, '' -- cols
, '' -- rows
, '' -- style
, 'N' -- style_required
, '' -- printer
, '' -- request_type
, '' -- request_type_application
, 'Y' -- use_in_srs
, 'N' -- allow_disabled_values
, 'N' -- run_alone
, 'TEXT' -- output_type
, 'N' -- enable_trace
, 'Y' -- restart
, 'Y' -- nls_compliant
, '' -- icon_name
, 'US'); -- language_code
END;
/

For attaching the concurrent program to the request group.

PROMPT Adding Concurrent program to request group 'XYZ Group'
PROMPT

BEGIN
FND_PROGRAM.add_to_group('XYZ_ABC_EMPLOYEE' -- program_short_name
, 'XYZ' -- application
, 'XYZ Group' -- Report Group Name
, 'XYZ'); -- Report Group Application

END;
/

Submit the Concurrent Program from Backend.

Submit Program is the Function. where. we need to pass the Application name, Program, stage etc.

function FND_SUBMIT.SUBMIT_PROGRAM
(application IN varchar2,
program IN varchar2,
stage IN varchar2,
argument1,...argument100)
return boolean;


PROMPT Submitting the Concurrent Program from backend.
PROMPT

BEGIN
--fnd_global.apps_initialize( user_id => , resp_id => , resp_appl_id => );

l_success := fnd_submit.set_request_set('', '');

IF l_success = TRUE
THEN


l_success := fnd_submit.submit_program(
'' --Application
,'' -- program
,'' --Stage
,'NEW' -- Arument1
,'10' -Arument2
,'N'
,'N'
,'N');

-- If fail then for the log record.

IF (NOT l_success)
THEN
fnd_file.put_line(
fnd_file.LOG
,'Request submission of stage STAGE FAILED');
ELSE
fnd_file.put_line(
fnd_file.LOG
,'Request submission of stage STAGE10 SUCCESSFUL');
END IF;
l_req_id := fnd_submit.submit_set(NULL, FALSE );

IF (l_req_id <= 0) THEN fnd_file.put_line( fnd_file.LOG ,'REQUEST SET SUBMISSION FAILED'); ELSE fnd_file.put_line( fnd_file.LOG ,'REQUEST SET SUBMITTED SUCCESSFULLY: ' || l_req_id); END IF; END IF; END;


I hope the above document is helpful to all of you for understanding the backend process and API's to register the program and submit from the backend.

Friday, June 27, 2008

Multi Org Concept

Introduction

Any enterprise has several organization structures. These organizations interact with each other for various purposes. While interacting with other organizations data has to be secure and should be transferred to the correct organization.

What is Multi Org

Multi Org is a feature, which helps us to classify and define various organizations in such a way that hierarchy is maintained and data is secure across organizations. It also decides how transactions flow through different organizations and how those organizations interact with each other.

Types of Organizations

The various organizations that can be defined within Oracle Applications are as follows:

Business Group. The business group represents the highest level in the organization structure, such as the consolidated enterprise, a major division, or an operation company. Oracle Apps provides with a predefined Business Group ‘Setup Business Group’. Reliance Group of Companies is an example of Business Group.

GRE/Legal Entity. The company for which we prepare tax returns. You assign tax identifiers and other legal entity information to this type of organization. If there are several subsidiary companies for which tax returns are filed, each company is a separate legal entity. Reliance Group of Companies consists of several companies like Reliance Industries ltd, Reliance Info-comm, Reliance Energy ltd etc. Each company is a separate Legal Entity.

Note: The Set of Book can contain multiple Legal Entities.

Operating Unit. Each group company will have several branch offices involved with purchasing, order management, shipping execution etc. Each such branch will be an Operating Unit.

It could be a sales office, a division, or a department. An operating unit is associated with a legal entity.

For implementing Oracle Cash Management, Order Management and Shipping Execution, Oracle Payables, Oracle Projects, Oracle Purchasing, Oracle Property Manager, Oracle Receivables and Sales and Marketing Operating Unit is required.

Information is secured by operating unit for these applications. Each user sees information only for their operating unit.

Inventory Organization. An organization for which you track inventory transactions and balances, and/or an organization that manufactures or distributes products. Inventory organization is generally assigned to a manufacturing plant. An operating unit can also be an Inventory Organization. Many branches (operating units) might be Manufacturing Plants and will be attached to an Inventory/Warehouse. Such inventory/warehouses will be Inventory Organizations.

HR Organization. HR organizations represent the basic work structure of any enterprise. They usually represent the functional management, or reporting groups that exist within a business group.

Asset Organization. An asset organization is an organization that allows you to perform asset–related activities for a specific Oracle Assets corporate depreciation book. Any organization (legal entity, operating unit, inventory organization), which has Fixed Assets can be classified as Asset Organization. For implementing Oracle Assets, this type of organization is used.


Secure Access within Multi Org

An individual Operating Unit is assigned to an individual application Responsibility. To see and work with data that is relevant to a specific Operating Unit, users choose the appropriate Responsibility after logging on to Oracle Applications.

The current Multi-Org architecture utilizes database objects like Views to build a security layer that allows you to logically partition all your application data in one database, instead of physically partitioning data with multiple instances and even multiple application installations.

In earlier versions of Oracle Applications data partitioning was done using multiple instances and therefore installation had to be done several times for various operating units.

Note: All Multi Org tables in the database will be suffixed with ‘_ALL’.

HRMS Organization Model

The business group is the largest organization unit you set up in Human Resources to represent your enterprises as an employer. After defining one or more business groups for your enterprise, you set up one or more Government Reporting Entities (GREs) within each business group. The GRE is the organization that federal, state, and local governments recognize as the employer.

Needless to say, HR does not require Operating Units, Inventory Organization and Asset Organization.


Multi Org Setup

The following are the summarized steps for implementing Multi-Org in Oracle Applications or when converting from a Non Multi-Org environment to a Multi-Org environment.

1.1 Develop an Organization Structure

1.2 Define Set of Books

1.3 Define Locations

1.4 Define Business Groups (Optional)

1.5 Define Responsibilities

1.6 Associate Responsibilities with Business Groups

1.7 Define Organizations

1.8 Define Organization Relationships

1.9 Set MO: Operating Unit Profile Option

1.10 Convert to Multi-Org Architecture

1.11 Define Inventory Organization Security

1.12 Define Inter-company Relations

Technical

How to set Org_id at back-end

We have a API to set the org_id from the backend.

begin
fnd_client_info.set_org_context();
end;

Note:- Org_id indicates the "Operating Unit" in the Business Structure.

How to I know what Org_id is set at back-end

We can use userenv function to know the Org_id set at backend.

select userenv('CLIENT_INFO') from dual;

Why we need to set org_id at back-end

We usually, set org_id at back-end. So that we can get the org_id records from the Multi Organization views.

What happens if I try to query records from Multi-Origination views without setting Org_id at back-end

It will not fetch any records. As, "where" condition fails (org_id = Userenv('CLIENT_INFO'));

Note:- If you set org_id from back-end, then you get org_id value populated by above userenv function.

Is this Multi -Org concept is same for all the Oracle Application versions

No. Above Technical points are applicable only till 11i version. It is different in Release 12.