Sunteți pe pagina 1din 11

Global Variables Declaration:

Global variables can be declared in two ways: the first one is simple :global.my_name := 'Littlefoot'; while the other one uses the DEFAULT_VALUE built in: default_value('Littlefoot', 'global.my_name'); Note that global variables' datatype is always CHARACTER (you can store a string up to 255 characters in length). How to use it in another form? Just as you'd use any other variable: message('My name is ' || :global.my_name); or l_another_variable := :global.my_name; etc.
Global variables are not formally declared the way PL/SQL local variables are. Rather, you initialize a global variable the first time you assign a value to it: :GLOBAL.my_var := TO_CHAR(:order.total * .85); hi Global variable are forms specifice variable. it can store character value upto 255 for all usages. We can initialize it when we declare otherwise give error if we did not assign it any value. Oracle 10g it can take upto 4000 bytes

GLOBAL.ur_globalvar := TO_CHAR(15); or :GLOBAL.ur_globalvar:= '15'; or Remmber numeric values are implicitly converted by oracle 2 character :GLOBAL.ur_globalvar:= 15; -- which can then subsequently be accessed using... :GLOBAL.ur_globalvar; -- To destroy a global variable and release its memory, use the ERASE built-in procedure: Erase('GLOBAL.my_var');
I want to declare a form level variable and want to assign a value at WHEN-NEW-FORM-INSTANCE trigger and i want to use the same value in Program units as well as other form level and block level triggers. How to achieve this? Do i need to refer the variable with :Symbol? Thanks! Hello, For these types of variables you can use GLOBAL VARIABLE. Like you can declare in your NEW-FORM-INSTANCE-TRIGGER like this...

:GLOBAL.MY_VARIABLE:='MY_VALUE';

and while using you can assign this global to any variable or item like this in the same logged in session...

:item_name:=:GLOBAL.MY_VARIABLE; variable_name:=:GLOBAL.MY_VARIABLE;
Or any where you want to use can use this as assigning :GLOBAL.MY_VARIABLE. I don't want to declare global variable. It is valid only for that form. I have created as a parameter and set the value. It is worked, i need to check in many places in the same form. Chris, There are a couple of ways to do this. As Ammad suggested, you can use a Global variable, but as you point out - Globals are visible to your Forms session unless you destroy the global. You can also use a Parameter as you have done or you can use a Control Block with a block item that will accept the type of data that will be stored in the variable. There are limitations with each of these options however. With Globals, all variables are of CHAR datatype and are limited to 4000 bytes in Forms 10g and higher and 255 in Form 9i and lower. Any non-character value stored in a global must be converted back to it's native datatype when you read the value to ensure it is evaluated correctly. When globals are declared, they always reserve the max amount of memory needed to support the 255 or 4000 characters. If you use Globals, it is a good habit to use the Erase() built-in to destroy the Global when you are finished with it. Also with Globals it is possible to get a Runtime error if the Global has not been initialized before you reference it, but will NOT produce a compile time error. Parameters and Control Block items are a little more flexible in that you can define the parameter's datatype as CHAR, DATE or NUMBER (check Forms Help for the max datatype values they can store). Parameters and Control block items also have properties which means they take up more memory resources because the properties of these items have to be loaded into memory in addition to the data. I would recommend using Parameters over Globals for Forms specific variables because you have greater flexibility with the data types supported, however, I personally prefer to use a Forms Package Specification with Package Variables declared as this more flexible and only allocates the amount of memory needed to support the variable. When I have a situation that requires a variable be visible to the entire form, but doesn't need to be Global to the session, I will create a Package Spec called FORM_VARS in the Program Units node of the Object Navigator and declare the variables I need. I do not create a Package Body. For example:

PACKAGE FORM_VARS IS n_User_ID NUMBER; v_User_Name VARCHAR2(25); END;


You then reference the variables the same as you would for any Forms program unit.

BEGIN Forms_Vars.n_User_ID := 1234546; Forms_Vars.v_User_Name := 'John Doe'; END;


Hope this helps, 2 ways to transmit information between forms: . GLOBAL variables . Forms parameters Francois etting the global in the calling form:

:GLOBAL.my_variable := 'Hello' ;

Getting the global in the called form:

:var := :GLOBAL.my_variable;

Francois Hotel Req Summary form to catch the parameter passed via the Parameter List. Then you will need to write code to do something with the value passed (usually in the When-New-Form-Instance trigger).

Global Variables
Introduction to Global Variables: Global variables in Oracle forms are the variable which are accessible thruout system (or entire runform session) until we erase it. You can declare these global variables anywhere in PL/SQL code (Triggers or Program Units). Main advantage of using global variables is that using global variable is very easy and simple. On the fly you can declare any number of variables. Value of global variable is preserved for whole runform session. In Oracle 10g forms you can store up to 4000 BYTES of CHAR data, while in previous version it was limited to 255 BYTES CHAR only. Declaration of Global variables Variables: In Oracle form style of declaring global variable is quite different than normal PL/SQL variables. PL/SQL variable are always declared in Declaration section of PL/SQL code, while you cannot declare global variables in declaration section. Global variables are initialized by assigning value to them. e.g. 1) Declaring PL/SQL local Variable
declare cMyName VARCHAR2(30); begin cMyName :='James Bond'; ........; ..........; END;

2) Declaring Global variables:


BEGIN :Global.myName:='James Bond'; -- Globals are prefixed by ':Global.' .....;

.....; END;

Remember that DATATYPE for global variable is always CHAR. So if you are assigning DATE, NUMBER data to global variable and reassigning these global values to any other variable having Datatype other than CHAR, there is always overhead of implicit data-type conversion. If you are using global variables heavily in your system then always take care that you erase global variables after use. Since One global variable requires 4000 BYTES size in Oracle 10g Forms and 255 in previous version, your application will consuming too much amount of memory for global variables variables. It reduces performance drastically. Removing/Erasing Global variables: You can remove global variable and release its memory by using 'ERASE' Build-in.
ERASE('Global.myName');

Referencing a global variable that has not been initialized through assignment causes a runtime error.
POSTED BY RAMESH AT 7:40 AM

Performance Guideline-Use a PL/SQL variable instead of a bind variable


Use a PL/SQL variable instead of a bind variable. Referencing a bind variable that represents a forms item (such as :DEPT.DEPTNO) requires forms to find the item in its internal list. Therefore, each time your code uses that same bind variable, the lookup has to occur again. If you have code that uses the same bind variable more than once in the PL/SQL block, create a variable instead. For example, the following code stores the value of :DEPT.DEPTNO in a variable and references that variable instead of repeating a lookup to find the value. For Example,
DECLARE v_deptno NUMBER := ept.deptno; BEGIN message('The department # is ' v_deptno); IF v_deptno < 0 THEN message('Incorrect department number'); ...; END IF; --

:control.department_num := v_deptno; END;

:SYSTEM.TRIGGER_ITEM vs :SYSTEM.CURRENT_ITEM
Both :SYSTEM.TRIGGER_ITEM and :SYSTEM.CURRENT_ITEM has character string values which is in form ofBLOCK_NAME.ITEMN_NAME. :SYSTEM.TRIGGER_ITEM represents the Item in the scope of firing trigger. When :SYSTEM.TRIGGER_ITEM is referenced in KEY-XXX triggers then only it returns the values same as :SYSTEM.CURSOR_ITEM. :SYSTEM.CURSOR_ITEM represents currently focused item and may change in a trigger if navigation takes place. Value of :SYSTEM.TRIGGER_ITEM remains same from begining of trigger till end.
POSTED BY RAMESH AT 6:36 AM

the :system.current_<...> - variables are for upgrade-compatibility with older forms. Don't use them. Forms-Help : Note: SYSTEM.CURRENT_ITEM is included for compatibility with previous versions. Oracle recommends that you use SYSTEM.CURSOR_ITEM or SYSTEM.TRIGGER_ITEM instead.

Oracle Forms-DEFAULT_VALUE Built-in


DEFAULT_VALUE built-in in oracle forms is used for assign value to variable if value of variable is NULL.
IF :DBT_BRANCH.LOCATION IS NULL THEN :DBT_BRANCH.LOCATION:='Pune'; END IF;

is equivalent to
default_value('Pune','DBT_BRANCH.LOCATION');

But DEFAULT_VALUE is noramally used to initialize global variable if they are not exist. If global variable are not exist in system then it will create new one or else assign value if its value is NULL.
POSTED BY RAMESH AT 6:47 AM

LIST_VALUES
LIST_VALUES displays the list of values for the current item, as long as the input focus is in a text item that has an attached LOV. The list of values remains displayed until the operator dismisses the LOV or selects a value. By default, LIST_VALUES uses the NO_RESTRICT parameter. This parameter causes

Oracle Forms not to use the automatic search and complete feature. If you use the RESTRICT parameter, Oracle Forms uses the automatic search and complete feature. Automatic Search and Complete Feature: With the automatic search and complete feature, an LOV evaluates a text item's current value as a search value. That is, if an operator presses [List] in a text item that has an LOV, Oracle Forms checks to see if the item contains a value. If the text item contains a value, Oracle Forms automatically uses that value as if the operator had entered the value into the LOV's search field and pressed [List] to narrow the list. If the item value would narrow the list to only one value, Oracle Forms does not display the LOV, but automatically reads the correct value into the field. Usages of RESTRICT kwyword: Where list value has too many valus then it affects the performance of the application. At that time use RESTRICT.
POSTED BY RAMESH AT 10:19 PM

Do_key and Execute_trigger


EXECUTE_TRIGGER built-in Description - EXECUTE_TRIGGER executes an indicated trigger. Syntax PROCEDURE EXECUTE_TRIGGER(trigger_name VARCHAR2); Built-in Type restricted procedure (if the user-defined trigger calls any restricted built-in subprograms) Enter Query Mode yes Note: EXECUTE_TRIGGER is not the preferred method for executing a user-named trigger: writing a usernamed subprogram is the preferred method.

Parameters Trigger_name Specifies the name of a valid user-named trigger.

Usage Notes Because you cannot specify scope for this built-in, Form Builder always looks for the trigger starting at the lowest level, then working up. To execute a built-in associated with a key, use the DO_KEY built-in instead of EXECUTE_TRIGGER. For example, rather than: Execute_Trigger ('KEY-NEXT-ITEM'); Use instead: Do_Key('NEXT_ITEM'); EXECUTE_TRIGGER restrictions Although you can use EXECUTE_TRIGGER to execute a built-in trigger as well as a user-named trigger, this usage is not recommended, because the default fail behavior follows a different rule than when invoked automatically by Form Builder as part of default processing. For example, in default processing, if the When-Validate-Item trigger fails, it raises an exception and stops the processing of the form. However, if the When-Validate-Item trigger fails when it is invoked by EXECUTE_TRIGGER, that failure does not stop the processing of the form, but only sets Form_Failure to FALSE on return from the EXECUTE_TRIGGER built-in.
POSTED BY RAMESH AT 2:37 AM

Oracle form size-(Introduction of P-Code???)


Yesterday I was doing some maintenance on one form. So achieve desired functionality I modified it. I hardly added 4-6 procedures of average 8-10 line of codes. Initially forms .fmb size was about 3.4MB. After modification it become around 8.5MB. I was wondering what has happened with form One of my Team member suggest me to replace ; with ; in all code which is very common solution is something is not working as expected. I did so. But Due to that is it broken inheritance Trigger Text of inherited trigger at Form, Block and item level. Property classes triggers inheritance was also broken. So I have to re-inherit all the triggers manually. Finally form size was reduced to 3.2MB. That guy told me that P-code has been inserted into form. I googled for p-code related to Oracle forms but unfortunately i didnt get any information.

So chaps do have any idea, thoughts on it. Please reply.


POSTED BY RAMESH AT 9:32 PM

KEY-DUPREC Trigger
Key-DupRec trigger is used to Copy previous record to current record in Create Record Mode. Whole record contains from last record including Sequence numbers are copied and newly record is not marked for validation. Item level validations are fired unless we go to item of newly created record and try to change it. If you are using PRE-INSERT trigger to generate Record last Change Details, auditing and Sequence number then duplicated records will have values calculated/generated in PREINSERT trigger. Its is always better idea to code constraints to database side. If you code constraints at database end then 1) Constraint violating record never will be in database. 2) If your application have different middle tier and client tier implemented in different technologies/channels then you can just catch these ora errors and make them user friendly before displaying.
POSTED BY RAMESH AT 3:07 AM

Global Variables
Global Variables Oracle Forms Developer and PL/SQL support different types of global variables: Oracle Forms Global: a variable in the global pseudoblock of a form PL/SQL Package Global: a global defined in the specification of a package Oracle Forms Parameter: a variable created within the Oracle Forms Designer as a Parameter

============================================================================ =======
http://itknowledgeexchange.techtarget.com/itanswers/global-variables-in-oracle-libraries/

Library modules are compiled independently of forms, and thus the values of global variables are out of scope of library program units (you cannot access them directly). However, you can use the NAME_IN built-in function to reference them. For example, instead of:
:GLOBAL.your_variable

Reference the value of the variable this way:


Name_In('GLOBAL.your_variable')

If you want to set the value of the global variable inside your library program units, you can use the COPY built-in procedure, for example:
Copy('something','GLOBAL.your_variable');

But, I would prefer to create the library procedures with parameters (IN or OUT) to pass data between forms and the library, instead of using global variables this way. ============================================================================ ========= FROM http://ora-forms-dev.blogspot.com/2008/08/global-variables.html
Global Variables Introduction to Global Variables: Global variables in Oracle forms are the variable which are accessible thruout system (or entire runform session) until we erase it. You can declare these global variables anywhere in PL/SQL code (Triggers or Program Units). Main advantage of using global variables is that using global variable is very easy and simple. On the fly you can declare any number of variables. Value of global variable is preserved for whole runform session. In Oracle 10g forms you can store up to 4000 BYTES of CHAR data, while in previous version it was limited to 255 BYTES CHAR only. Declaration of Global variables Variables: In Oracle form style of declaring global variable is quite different than normal PL/SQL variables. PL/SQL variable are always declared in Declaration section of PL/SQL code, while you cannot declare global variables in declaration section. Global variables are initialized by assigning value to them.

e.g. 1) Declaring PL/SQL local Variable declare cMyName VARCHAR2(30); begin cMyName :='James Bond'; ........; ..........; END; 2) Declaring Global variables: BEGIN :Global.myName:='James Bond'; -- Globals are prefixed by ':Global.' .....; .....; END; Remember that DATATYPE for global variable is always CHAR. So if you are assigning DATE, NUMBER data to global variable and reassigning these global values to any other variable having Datatype other than CHAR, there is always overhead of implicit data-type conversion. If you are using global variables heavily in your system then always take care that you erase global variables after use. Since One global variable requires 4000 BYTES size in Oracle 10g Forms and 255 in previous version, your application will consuming too much amount of memory for global variables variables. It reduces performance drastically. Removing/Erasing Global variables: You can remove global variable and release its memory by using 'ERASE' Build-in. ERASE('Global.myName'); Referencing a global variable that has not been initialized through assignment causes a runtime error. ===================================

WHEN-FORM-NAVIGATE
To pass information when navigating from one form to another when both forms are already open, use the WHEN-FORM-NAVIGATE trigger. You do not code this trigger directly; instead pass the information through global variables. To use this trigger, populate a global variable called GLOBAL.WHEN_FORM_NAVIGATE with the name of a user-named trigger. When a form is navigated to, this trigger fires. The WHEN-FORM-NAVIGATE trigger fires upon programmatically navigating to a form using the GO_FORM built-in. Accordingly, this trigger is referenced into all forms.

========

WHEN-FORM-NAVIGATE

You cannot modify this referenced trigger. It enables certain standard behaviors, such as normalizing a minimized form when it is navigated to. To make use of this form event, populate a global variable called GLOBAL.WHEN_FORM_NAVIGATE with the name of a user-named trigger. Usually you populate this global immediately before issuing a GO_FORM.
========

Querying an Item It often makes sense to navigate to a form and query on a specific item. For example, suppose you have an Order Entry form ORDERS and a Catalog form CATALOGS. You want to navigate from the ORDERS form to CATALOGS and query up a specific part number. In the ORDERS form, create a global variable called GLOBAL.PART_NUMBER, and populate it with the value you want to query. In the ORDERS form, create a global variable called GLOBAL.WHEN_FORM_NAVIGATE. Populate this variable with the string "QUERY_PART_NUMBER". Create a user-named trigger in the CATALOGS form, "QUERY_PART_NUMBER". In this trigger, enter query mode by calling EXECUTE_QUERY. Create a PRE-QUERY trigger in the CATALOGS form that calls copy('GLOBAL.PART_NUMBER, 'PARTS_BLOCK.PART_ NUMBER'). Then call copy('','GLOBAL.PART_NUMBER'). When there is a value in GLOBAL.PART_NUMBER, it becomes part of the query criteria.

S-ar putea să vă placă și