using Global variables/parameters in D2k forms

I have created some D2k forms.  I need to initiate Global variables/parameters in calling and called forms(variable name is myvar varchar2(30)).  But I dont know how to do it.

Can any one guide me where and how to initiate the global variables/parameters,  how to retrieve the values and make use of them.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Helena Markováprogrammer-analystCommented:
Global variable can be defined everywhere in a Forms. I use them rarely. I define them in the When-New-Form-Instance trigger:
:GLOBAL.myvar := 'my_value';
The data type of the global variables is always VARCHAR2 !

This is from the on-line help - "Passing parameters to forms" topic:
When you invoke a form with the procedures OPEN_FORM, CALL_FORM, or NEW_FORM, you can pass values for form parameters from the calling form to the called form.
To pass parameter values from one form to another, each parameter and its value must be in a parameter list.  Parameter lists are internal, three-column data structures that contain the key (name), the type  (Text_Parameter or Data_Parameter) and the value of each parameter on the list.
The parameters whose values are being passed must have been defined in the called form at design time.  That is, the called form must be expecting a value for each of the parameters included in the parameter list it receives from the calling form.

You can define parameters in a form in the Object Navigator at design time and also programmatically at runtime.  The properties of a parameter include Name, Parameter Data Type, Length, and Parameter Initial Value.  Parameter lists must be created programmatically with the built-in routines CREATE_PARAMETER_LIST and ADD_PARAMETER.
Parameter values are not visible across multiple forms.  Thus, even if there is a parameter named p1 defined in both Form A and Form B, each form has a separate context, and setting the value of p1 in Form B has no effect on the value of p1 in Form A.  For this reason, parameters are useful in multiple-form applications primarily as inputs to a form when it is first invoked.

If your application requires variables whose values are visible across called forms, you should use global variables. Global variables are visible across called forms, and remain active until they are explicitly deleted with the ERASE built-in procedure, or until the session ends.

Helena Markováprogrammer-analystCommented:
There are Text or Data parameters there. This is an example of using it in the When-New-Form-Instance trigger.


"Creating and Passing Parameter Lists" on-line help topic:
Parameters are passed to called forms by means of a parameter list. A parameter list is a named programmatic construct that is simply a list of parameter names (called keys) and their values.  
You can pass parameter values to forms invoked by the built-in subprograms CALL_FORM, OPEN_FORM, and NEW_FORM.  In addition, you can pass parameter values to other Oracle tools with the RUN_PRODUCT procedure.
A parameter you include in a parameter list can be either a text parameter or a data parameter.  The parameter type determines how its value is interpreted.

Text Parameters
The value of a text parameter being passed to a called product is a CHAR string that can represent the following:

     a user-defined form parameter defined in a form invoked by the CALL_FORM, OPEN_FORM, or NEW_FORM built-in subprograms

     a command line or user-defined parameter for a product invoked with the RUN_PRODUCT built-in subprogram

Data Parameters
The value of a data parameter being passed to a called product is always the name of a record group defined in the current form.  (A record group is a data structure that stores records derived from a query or through programmatic assignment.) Data parameters are used to pass data to products invoked with the RUN_PRODUCT built-in subprogram.  You cannot pass data parameters to forms.

The following table shows the structure of a parameter list that contains four parameters:

Key             Paramtype     Value
CITY             Text_Parameter     'BOGOTA'
CATEGORY     Text_Parameter     'EXPORTS'
MULTIPLIER     Text_Parameter     '.0275'
NEW_DATA     Data_Parameter     'RECORD_GROUP8'

Helena Markováprogrammer-analystCommented:
I think that this is an interesting article:

Global Variables and Package Variables

The purpose of this note is to explain Global Variables(Globals) and Package Variables, how global variable is different than a package variable, when to use globals instead of package variables.

Datatype:    Globals are always CHAR data. Package variables can be any PL/SQL data type.

Creation:    Globals are created the first time they are assigned.
Package variables are explicitly declared as part of a package.

Default Values:
Globals must have a value programmatically assigned.
Package variables can be assigned a default value of the proper datatype at design-time.Package variables can also be initialized with arbitrarily complex code in the initialization block of the package.

Globals are assigned directly through PL/SQL with the bind variable notation
(:GLOBAL.GLOBAL_NAME), or indirectly using the Copy() built-in.
Package variables are assigned directly through PL/SQL.

Global names are global to the whole runform session. Therefore, if you try to combine two forms that happen to use the same global name for different purposes, the forms will not integrate without changes.
Package variables are qualified by the name of the package. If two packages declare the same variable name, there is no interaction between them. Integrating forms that rely on package variables for their shared global data is much more straightforward than using the other two methods, because there are no hidden subtle interactions between same-name objects.
Globals can be created anywhere in any trigger. Unless a developer is disciplined and uses some sort of methodology, globals variables can be very hard to find and document. Errors are easy to make and hard to find, since a typing error when assigning to a global simply   creates a new global under the new, mistyped name. Globals preserve their value for the duration of the Runform session, unless explicitly erased. They are visible to all forms which get called during the session. Any modification made to a global variable in a called form is visible to any calling form and all subsequent forms in the session.
Package variables preserve their value for the duration of the Runform session. They are visible to all forms which get called during the session provided the CALL_FORM argument data_mode is set to SHARE_LIBRARY_DATA. Any modification made in a called form to a package variable is visible to any calling form and all subsequent forms in the session.Package variables are declared explicitly in a package and can be explicitly initialized. They can be easily documented in the PL/SQL code. If you specifically need to create variables dynamically use globals else use package variables.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.