[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6741
  • Last Modified:

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?
0
eastbourne
Asked:
eastbourne
  • 4
  • 3
1 Solution
 
Mark GeerlingsDatabase AdministratorCommented:
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.
0
 
eastbourneAuthor Commented:
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.
0
 
Mark GeerlingsDatabase AdministratorCommented:
To assign a value to a global customer_no variable in a form with a block name of customer and an item name of customer_no, use this:
:global.customer_no := customer.customer_no;

You will need to do this in the trigger or procedure that calls your next form, before the "callform" statement.

In your second form, assume there is a block named "orders", just do this:

:orders.customer_no := :global.customer_no;

That cannot be in a pre-form trigger.  It may be in a pre-query trigger if you always want to limit queries to the value of the global variable.  It gets more complicated if you want to sometimes allow searches for other customers and/or use this as a default for entering a new order.  All of these are possible, but would require a control block, multiple triggers and setting the "default value" for customer_no in the data block to :control.customer_no.

Keep in mind that I do not feel that use of global variables is the best technique for passing values from form-to-form in Oracle Forms 5 or 6, but if you are convinved that is the way you want to go, it can work.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
eastbourneAuthor Commented:
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?
0
 
Mark GeerlingsDatabase AdministratorCommented:
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.
0
 
eastbourneAuthor Commented:
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?
0
 
Mark GeerlingsDatabase AdministratorCommented:
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.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now