Pre-requisites :
Step1: Data Definition and Template to be created
Step2: Concurrent program needs to be created

Steps To Create the PL/SQL package:

1. Initialize the  Session Specific variable using fnd_global.APPS_INITIALIZE
2. Set The BI publisher report layout Before submitting the concurrent program
3. Submit the Concurrent Program

Code: (Tested in R12.1.1 )

DECLARE
l_user_id              fnd_user.user_id%TYPE;
l_resp_id              fnd_responsibility.responsibility_id%TYPE;
l_resp_appl_id         fnd_application.application_id%TYPE;
l_set_layout           boolean;
l_request_id           NUMBER;
l_phase                VARCHAR2 (100);
l_status               VARCHAR2 (100);
l_dev_phase            VARCHAR2 (100);
l_dev_status           VARCHAR2 (100);
l_wait_for_request     boolean := FALSE;
l_get_request_status   boolean := FALSE;
Output_layout_failed EXCEPTION;
request_submission_failed EXCEPTION;
request_completion_abnormal EXCEPTION;
BEGIN
l_request_id := NULL;


— Get the Apps Intilization Variables

SELECT   fnd.user_id, fresp.responsibility_id, fresp.application_id
INTO   l_user_id, l_resp_id, l_resp_appl_id
FROM   fnd_user fnd, fnd_responsibility_tl fresp
WHERE   fnd.user_name = ‘OEAG’
AND fresp.responsibility_name = ‘Custom XML Reports’;


–Initialize the Apps Variables

fnd_global.APPS_INITIALIZE (user_id        => l_user_id,
resp_id        => l_resp_id,
resp_appl_id   => l_resp_appl_id);

COMMIT;


— Set the Layout  for BI Publisher Report

l_set_layout :=
fnd_request.add_layout (template_appl_name   => ‘XXERP’,
template_code        => ‘XXORACLEERPAPPSGUIDE’,
–Data Template Code
template_language    => ‘en’,
template_territory   => ‘US’,
output_format        => ‘PDF’);

IF l_set_layout
THEN
— Submit the Request

l_request_id :=
fnd_request.submit_request (application   => ‘XXERP’,
program       => ‘XXOEAG_PG’,
description   => ”,
start_time    => SYSDATE,
sub_request   => FALSE,
argument1     => l_person_id);

COMMIT;

IF l_request_id > 0
THEN

–waits for the request completion

l_wait_for_request :=
fnd_concurrent.wait_for_request (request_id   => l_request_id,
interval     => 60,
max_wait     => 0,
phase        => l_phase,
status       => l_status,
dev_phase    => l_dev_phase,
dev_status   => l_dev_status,
MESSAGE      => l_messase);

COMMIT;


— Get the Request Completion Status.

l_get_request_status :=
fnd_concurrent.get_request_status (
request_id       => l_request_id,
appl_shortname   => NULL,
program          => NULL,
phase            => l_phase,
status           => l_status,
dev_phase        => l_dev_phase,
dev_status       => l_dev_status,
MESSAGE          => l_messase
);


–Check the status if It IS completed Normal Or Not

IF UPPER (l_dev_phase) != ‘COMPLETED’
AND UPPER (l_dev_status) != ‘NORMAL’
THEN
RAISE request_completion_abnormal;
END IF;
ELSE
RAISE request_submission_failed;
END IF;
ELSE
RAISE Output_layout_failed;
END IF;

p_request_id := l_request_id;
EXCEPTION
WHEN Output_layout_failed
THEN
DBMS_OUTPUT.put_line (‘Out put Layout failed’);
WHEN request_submission_failed
THEN
DBMS_OUTPUT.put_line (‘Concurrent request submission failed’);
WHEN request_completion_abnormal
THEN
DBMS_OUTPUT.put_line (
‘Submitted request completed with error’ || l_request_id
);
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (‘ERROR:’ || SUBSTR (SQLERRM, 0, 240));
END;

/

You can Create this as PL/SQL Procedure and register into Concurrent Program also.

For each Concurrent program we must use mandatory parameters : ERRBUF and RETCODE.

ERRBUF: It return the error message. 
For you program if you get any error in exception block you can assign the error message to this parameter. 
This error message you can see after concurrent program run go to details button it will open details in that Completion Text filed will show your errbuf.

RETCODE: This parameter returns the status of the concurrent program.
0- Success –Completed
1- Warning — Yellow color
2- Error — Red

These parameters we call as a first parameters for the program.

Ex:
Create procedure  CProgram(ERRBUF out varchar2, RETCODE  out varchar2, person_id in NUmber)
as
begin
<Declaration Goes  Here>
begin
<Code Block1 Here>

exception
when no_data_found then
retcode := 1;
errbuf:= ‘RetCode : Warning’;
end;

<Code Block2 Here>

retcode:= 0;
commit;
exception
when others then

retcode := 2;

errbuf:= ‘errbuf:= ‘RetCode : Error’;

end;
The main classification is Oracle Defined and User defined Exceptions

User Defined:

User defined exceptions are defined in many ways.

a.New user defined Exceptions can be created using existing Oracle defined Exceptions

b.Entirely new Exceptions can be according to a users need. 
Eg: Raise an exception if employee salry should not be negative value.

There are mainly 3 ways to use User Defined Exceptions

A. RAISE EXCEPTION

declare
exc_user Exception; –declare exception
begin
–code–
exception when others then
raise exc_user;
–exception raised
exception
when exc_user then
–handler for exc_user. exception handled
when others then
–handler for others
end;

B. RAISE_APPLICATION_ERROR

declare
exc_user Exception; –declare exception
begin
if (<logic>) then
RAISE_APPLICATION_ERROR(-20001, exc_user);
–code greater than -20000
exception
when exc_user then
 –handled when error occurs with the specified Oracle Code
when others then
–handler for others

C. PRAGMA EXCEPTION_INIT

declare
exc_user Exception; –declare exception
PRAGMA EXCEPTION_INIT(exc_user, -<oracle_error_code>); 
— Oracle code with ‘-‘sign
begin
–code–
exception
when exc_user then
–handler for exc_user –handled when error occurs with the specified Oracle Code
when others then
–handler for others

Oracle defined:

There are many built in exceptions which we can use. Most commonly used ones are:

a.NO_DATA_FOUND
b.TOO_MANY_ROWS_FOUND
c.ZERO_DIVIDE
d.CURSOR_ALREADY_OPEN
e.INVALID_CURSOR
f.DUP_VALUE_ON_INDEX
g.VALUE_ERROR
h.INVALID_NUMBER

Difference between Value Error and Invalid Number
See below are the examples:

Eg1:
SQL> select to_number (‘a’)
  from dual

Error :ORA-01722: invalid number

Eg2:

SQL>   declare
       n number;
   begin
      n := ‘a’;
    exception
     when value_error
    then
     dbms_output.put_line (‘Value Error’);
   end;

 
Error: Value Error

Eg3:

SQL> declare
     n number;
    begin
         select ‘a’ into n
         from dual ;
     exception
     when value_error then
     dbms_output.put_line (‘Value Error’);
    end;


Error: Value Error

Eg4:
SQL> declare
     n number;
    begin
        select to_number(‘a’) into n
        from dual;
    exception
    when value_error  then
    dbms_output.put_line (‘Value Error’);
    when invalid_number then
    dbms_output.put_line (‘Invalid Number’);
 end;

Error:Invalid Number
The focus of the document is for consultants who are new to Oracle Forms and needs a kick-start on the concepts for better understanding of the subject.
Let’s start understanding the basic but important concepts in Forms.
What is Form :It is a developmental tool that is used for designing data entry and query screens. It is a front-end tool that runs in a Graphical User Interface (GUI).
GUI Concepts:
These concepts holds good for any user-interface.
To develop an effective GUI there are 4 basic stages:
  1. Define User Requirements
  2. Plan the User Interface
  3. Build the User Interface Elements (Create/Modify elements/functionality)
  4. User Feedback (Holds Key on the functionality and basis of the requirement)
Let’s move on to Forms Developer
How many components in Forms?
There are 3 components involved in the application development
  1. Form Builder
  2. Form Compiler
  3. Form Runtime
Form builder consists of following tools to perform a specific task
  1. Object Navigator
  2. Layout Editor
  3. Property Palette
  4. PL/SQL Editor
  5. Menu Editor
  6. Object Library

Object Navigator: It’s a hierarchal representation of all objects.
Layout Editor: It provides a virtual representation of the application user interface.
Property Palette: Each object in the form module has a property associated to it. Developer can view/set properties for one/multiple object.
PL/SQL Editor: Programmatically to enhance the functionality and appearance of an application.
Menu Editor: Create menu as per applications requirement and can add various functionality to various menu options.
Object Library: Creation of objects on some default specification. Storing some standard objects that can be re-used in other forms/menu.
Blocks: Logically related interface items are grouped into functional units called Blocks.
Types of Block:
Data Block: It is associated with or bound, to a database table or view or a set of stored procedures.
Control Block: It is not associated with any database table but items that will control the behavior of the application.
Let’s move on to the next scheme of things…
Canvas: It is a surface inside a window on which we place the interface that end user interacts.
Types of Canvas:
  1. Stacked Canvas
  2. Content Canvas
  3. Horizontal Toolbar
  4. Vertical Toolbar
  5. Tab Canvas

Let’s discuss briefly about the triggers in this section, for more information you can look through the Forms Builder Help Topics.
Note: The hierarchy of Objects in a form is
Form
Block
Record
Item
What is Triggers: These are program units which enhance the functionality of a form/application.
The following triggers can be used to enhance the functionality of the form:
What are Types of triggers in Oracle Form?

Block Processing Triggers: It fires in response to events related to record management in block.
e.g., When_Create_Record,When_Clear_Block,…
Interface Event Triggers: It fires in response to events that occur in form interface.
e.g., When_Button_Pressed,When_Checkbox_Changed,…
Master-Detail Triggers: It fires automatically when defined master-detail relationship between blocks. (Master-Detail relationship discussed further in the document)
e.g.,On_Checkdelete_Master,On_Clear_Details,…
Message Handling Triggers: It fires to issue appropriate error and information messages in response to runtime events.
e.g.,On_Error,On_Message,..
Navigational Triggers: It fires in response to Navigational Items.
e.g., Pre_Form, Post_Form, When_New_Form_Instance, When_New_Block_Instance,..
Query Time Triggers: It fires before/after the operator/application executes a query.
e.g.,Pre_Query,Post_Query,…
Transactional Triggers: It fires in response to wide variety of events that occur as a form interacts with data source.
e.g.,On_Delete,On_Update,..
Validation Triggers: It fires when it validates data in an item/record.
e.g.,When_Validate_Item,When_Validate_Record,..
Mouse Event Triggers: It fires for a mouse event.
e.g.,When_Mouse_Enter,When_Mouse_Click,..
Key Triggers: It has one to one relationship with specific Keys.
e.g.,Key F1,Key Enter,..
There are lot number triggers that can be used, please use as per the requirement with reference to Form Builder Help Topics.
What is Master- Detail Relationship? or What is Parent -Child Relationship?
Master- Detail Relationship : It is an association between two datablocks.One block is called Master Block and other Detail block. The relationship signifies that there is a primary key to foreign key relationship between the tables on the blocks associated.
What are Properties associated with blocks in a master-detail relationship?
Isolated : If you delete master records, associated detail records are not deleted from the database.
Non-Isolated: You cannot delete master records if the associated detail records exist in database.
Cascading: If you delete master records then automatically detail records will be automatically deleted from the database.
Windows : It is a container for all visual objects that make up a form, including canvases.
There are 2 types of Windows:
Document Window : It typically display the main canvases and work areas of the application where most data entry, and data retrieval is performed. It always remains within the application window frame.
Dialog Window: are free-floating, windows typically used for modal dialogs that require immediate user interaction.
Modality of the window depends on the functionality required i.e., Modal or Modeless.
Alert : It is a modal window that displays message to inform user about some application condition. E.g., STOP,CAUTION,NOTE,…
Invoking an alert : show_alert(alert_name)
Return number;
What is Record Group: It is an internal form builder structure that has column/row structure similar to database table. Static and Query based record groups can be used on the functionality of the form.
What is List of Values (LOV) : It is a pop-up window that provides end user selection list. LOV’s can be invoked programmatically or statically based on the record group. It can be positional based or automatic display.
The most important features of LOV are it provides auto-reduction and search features due to which user can locate specific values easily.
Let’s get to items on canvas which holds the key points.
Boilerplate Text Tool is used to create or edit a graphics text in the form. Graphics text is a static text in the form. E.g. Labels for items
Text Item Tool is used to create text item. It is an interface control that displays and allows editing of a text. It can be single or multi-line format.
Display Item tool are similar to text items but display items only store and displayed fetched or assigned values.
Buttons is a tool to execute commands or initiate buttons. E.g., OK ,CANCEL,..
Types : Text and Iconic Buttons
List Item is a list of text elements. A list item displays a fixed number of elements.
Types: Tlist,Pop List, Combo Box
Checkbox: It is a control that has 2 states i.e., checked or unchecked. It is used to indicate whether a certain condition is true or false.
Radio Button/Box : It is a logical set of options.
Editors: are used to edit item values in form. There are three editors that can be used at run time: Default editor, System Editor, User Named Editor
Property Class: Form builder provides a facility to create a named list of common properties and their values. This object is known as property class. Once you create a property class, you can base other objects on it. It is similar to the OOPS concept in programming languages.
Visual attribute : is a list of font, color and pattern properties and their values. This visual attribute can be attached to various objects to define object’s visual attributes.
This article details the steps used to clone R12 RAC database to Single instance database using RMAN duplicate command, Notice that we used the control file as a catalog database and the Production will keep up and running.

The databases used here are:
Production: PROD
Cloned: CPCLONE
1- On the source system; Run the preclone script on both database and apps tiers.
Database:
$ cd ORACLE_HOME/appsutil/scripts/$CONTEXT_NAME/
$ perl adpreclone.pl
Application:
$ cd $ADMIN_SCRIPTS_HOME/appsutil/scripts/$CONTEXT_NAME/
$ perl adpreclone.pl
2- Archive and move the Apps tier and Database home form the source to the target server:
For the application tier:
$ cd $APPL_TOP/../../..
$ tar cvf – apps| gzip > apps_PROD.tar.gz
For the database tier
$ cd $ORACLE_HOME/..
$ tar cvf – db | gzip > db_PROD.tar.gz
3- Create full RMAN backup for the source database:
$ export ORACLE_SID=PROD
$ rman target /
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup format ‘/backup/MASTER/ERP/df_prodt%t_s%s_p%p.bak’ database;
sql ‘alter system archive log current’;
backup format ‘/backup/MASTER/ERP/df_archive%t_s%s_p%p.arc’ archivelog all;
release channel d1; release channel d2;
}
4- Move the backup pieces generated from Rman to the target server to the same path or make a soft link as the same backup original path to let Rman see it.
Example $ ln –f -s /u02/CPCLONE/backup /backup/MASTER/ERP.
5- Extract the archive files on the Target servers
For the application tier:
$ tar cvf – apps| gzip > apps_PROD.tar.gz
For the database tier
$ tar cvf – db | gzip > db_PROD.tar.gz
Note: The current path depends on your configuration.
6- On the target system; Run the preclone script on the database tier.
$ cd $ORACLE_HOME/appsutil/clone/bin
$ perl adcfgclone.pl dbTechStack
7- Edit the new created init file under $ORACLE_HOME/dbs to include the following parameters; Note we are using ASM as data storage:
_no_recovery_through_resetlogs=TRUE
db_file_name_convert =(‘+DATA1/prod’, ‘/u01/CPCLONE/oradata’)
log_file_name_convert =(‘+DATA1/prod’, ‘/u01/CPCLONE/oradata’)
and edit the following parameters if not have those values
undo_management =AUTO
undo_tablespace =UNDOTBS1
db_name =cpclone
instance_name =cpclone
8- On the target system; Startup the database on nomount state:
$ export $ORACLE_SID=CPCLONE
$ sqlplus / as sysdba
SQL> startup nomount pfile=initCPCLONE.ora;
9- Make the production database accessible from the clone database:
$ cd $TNS_ADMIN
$ vi tnsnames.ora
And insert the follow entries:
PROD= (
DESCRIPTION=
(
ADDRESS=(PROTOCOL=tcp)(HOST=gfmisdb1)
(PORT=1521))
(CONNECT_DATA=
(SERVICE_NAME=PROD)
(INSTANCE_NAME=PROD1)
)
)

10- Test the connection to the production database:
$ tnsping PROD
$ sqlplus apps/apps@PROD
11- Lunch rman to start the duplicate process:
$ export $ORACLE_SID=CPCLONE
$ rman target sys/sys@prod auxiliary /
run
{
allocate auxiliary channel C1 device type disk;
allocate auxiliary channel C2 device type disk;
duplicate target database to cpclone;
release channel C1;
release channel C2;
}
12- Shutdown the cpclone database and edit the parameter file as:
$ sqlplus / as sysdba
$ shutdown abort;
Edit the following parameters:
undo_management to =MANUAL
undo_tablespace=UNDOTBS1
13- Open the database in with resetlogs option:
$ sqlplus / as sysdba
Sql> startup mount;
Sql> alter database open resetlogs;
Sql> drop tablespace APPS_UNDOTS1 including contents;
Sql> CREATE UNDO TABLESPACE APPS_UNDOTS1 DATAFILE
‘/u02/CPCLONE/oradata/datafile/undo01.dbf’ SIZE 4000M AUTOEXTEND
ON NEXT 100M MAXSIZE 7000M
ONLINE
RETENTION NOGUARANTEE
BLOCKSIZE 8K
FLASHBACK ON;
Then shutdown the database
Sql> shutdown immediate;
14- Edit the parameter file:
Remove _no_recovery_through_resetlogs=TRUE and edit
undo_management=AUTO
undo_tablespace=APPS_UNDOTS1
15- Change the database mode to be in no archive log mode:
$ sqlplus / as sysdba
Sql> startup mount;
Sql> alter database noarchivelog;
Sql> alter database open;
Execute the following script
Sql> @ $ORACLE_HOME/appsutil/install/[CONTEXT NAME]/ adupdlib.sql so
Sql> create spfile from pfile.
Sql> shutdown immediate;
Sql> startup;
16- After the database opened; execute the following script:
cd $ORACLE_HOME/appsutil/clone/bin
perl adcfgclone.pl dbconfig $ORACLE_HOME/appsutil/$CONTEXT_NAME.xml
17- On the application tier run the following script:
cd $COMMON_TOP/clone/bin
perl adcfgclone.pl appsTier