Link to home
Start Free TrialLog in
Avatar of eastbourne
eastbourne

asked on

How do you set up a Global Variable?

I want to be able to click on a button and go to another form using the same information I just input in the privous form.
Example: I input a customer name in the customer form.  I click on the order form icon and it takes me to the order form WITH the customer name and information that I was working, that applies to the order form, transferred over.
The answer is 'use a global variable'.  The form is GLOBAL.my_variable, the trigger is PRE-FORM... but how does one acctually set it up?  What is the script that makes it all work?
Avatar of Mark Geerlings
Mark Geerlings
Flag of United States of America image

Global variables are one approach for this.  They have worked since Forms2.3 at least.  Prior to leaving the current form, you need to set the value like this:
:global.customer_no := [:block.customer_no];

Then in the second form, in a when-new-form-instance trigger you need to get that value and put in a control block item (assuming that your data block has a default where clause or a relation to the control block) and do a query, or have a pre-query trigger in your data block copy it into the data block item.

With Forms5.0 and 6.0 there is a better way (at least a way that uses memory more efficiently) according to both Oracle and third-party documentation.  This is through the use of client-side package variables that are part of a PLL library that you attach to your forms.

To do this, first create a new PLL library, named something like "shared".  Create a package header in this library and define variables for the items you want to pass from form to form.  Compile the library and attach this to *ALL* of your forms.  This works best if you have a startup form that functions as a main menu and always stays loaded in memory, and you do callforms from that.  (If you do not have that calling form in the background, you would reload the PLL and re-initialize the variables between forms.)

Also, you need to modify *ALL* of your callform commands to include the "sharelibrarydata" parameter.  Unfortunately this is not the default.  Before leaving a form, simply assign the value of the screen fields you want to carry along to the appropriate package variables, then retrieve them in the second form just as with global variables.  The programming is admittedly more complex, but the performance is supposedly better.

Also, with global variables, if you make a mistake and mistype the name, you may not get a compile error, but you will not get the results you expect at runtime.  With package variables, you avoid the potential for this kind of error.
Avatar of eastbourne
eastbourne

ASKER

The debate among professionals is to great, at this time, and the research involved in looking up what he is talking about is too involved at the moment.

I need to know how to use Global variables from how to declare them in a Pre Form or where ever they are to be declared, to how to define the global variable (how to input a variable from a block.item) to calling it from other blocks and other forms.

Giving me hits about other ways to handle variables is not answering the question: How are global variables declared and used.  

I need step by step instructions on how to declare the global variable, then how I input a value into this global variable from a block.item, and how that global variable can be called by other blocks and other forms.
ASKER CERTIFIED SOLUTION
Avatar of Mark Geerlings
Mark Geerlings
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It still doesn't work. I used:

Preform trigger   :Global.Customer:=:Custhdr.customer to declare Global Variable

I then filled in my customer form with customer information. On a When-button-pressed trigger I call_form('Profile'); to go to the next form.

On my Form trigger, I have when-new-form-instance
:Global.Customer:='Custhdr.Customer';
:Profile.CustomerName:=:Global.Customer;

Nothing Happens!

How do I get it to appear?
It cannot be a pre-form trigger - at that point in time the form fields have no values yet.  You must assigne the value to the global in your When-button-pressed trigger.

On the second form, if you use the when-new-form-instance trigger, the values will be used almost like defaults to create new records.  If that is the functionality you want, then the when-new-form-instance trigger is the place to put it.  If though, you want this value to be used to search for existing orders for this customer, it must be a pre-query trigger.

It sounds like you are not clear on which trigger to use for what.  If you are new to Oracle Forms and are trying to use it without formal training, a co-worker who knows the tool, or a good book or two, you will likely have quite a bit of difficulty and/or frustration.  Forms is a powerful, but complex tool.
The answer is still very vague!  Being new does not necessitate not having formal Oracle classes.  I have five formal Oracle Classes and ten good books, but no one seems to be able to give a clear concise answer, which makes it hard to learn.  My vague guessing around about how to proceed has earned me above 80% in all my test, but it still isn't enough to know the specifics.  What you have come up with so far is little more than I have come up with myself through classes and books.  It is the actual HOW TO; what goes where and when, that no one seems to be able to answer.  It should be a matter, for an expert, to teach a beginner where to put things and to get the desired results.  At least I should be able to get an answer on how to have my global variable appear when I go to my next block or form.   Is it that no one really knows just how, beyond what is in the books?
I tried to be clear and concise in my proposed answer of January 10.

I also enjoy teaching and have spent five years as a classroom teacher.  This forum though is limiting - we don't get the direct verbal exchange that is possible in a classroom or mentoring situation at work.

I find the Oracle documentation disappointing quite often too.  It usually goes to great length to list all of the various parameters and possibilities, but is usually light on simple, specific examples.  Also, there is unsually no explanation of when or why you might choose one option compared to another.  Many of the third-party books are much better at that.  Some of the magazines like Oracle Developer from Pinnacle also have very good, specific articles from time to time.

I don't encourage direct contact between people through this site, but in this case, since I feel I have answered the question (and made it possible for other readers to learn from it) I would be willing to talk to you.  Leave a comment here with your e-mail address or phone number and I'll contact you, if you like.