Global variable in form

hi how can i reset global variable in oracle form 11g i have the following block IN MY when-new-form-instance


:block_home.enter_employee_id := substr(:global.ent_empid,1,4)||' - '||substr(:global.ent_ent_empid,5,2)||' - '||substr(:global.ent_empid,7,3)||' - '||substr(:global.ent_empid,10,4);	
:BLOCK_HOME.CURR_employee_id    :=substr(:global.uni_empid,1,4)||' - '||substr(:global.uni_empid,1,2)||' - '||substr(:global.uni_empid,3,3)||' - '||substr(:global.uni_empid,6,4);

Declare
	Cursor C_jobs 
	  is
	  Select employee_id, start_date, end_date,
	         job_id, department_id 
	         from hr.job_history
	         where employee_id = substr(:global.uni_empid,5,9); --am geting value as -18-047-6 instead of 5320180476694 how can i resert :BLOCK_HOME.CURR_employee_id
begin
	go_block('job_history');
	-- first clear the block if it contains any records
	clear_block(no_validate);
	-- move control to first record;
	first_record;
	for cur in C_jobs loop
		 :job_history.employee_id := cur.employee_id;
		 :job_history.start_date := cur.start_date;
		 :job_history.end_date := cur.end_date;
		 :job_history.job_id := cur.job_id;
		 :job_history.department_id := cur.department_id;
		 -- move control to next record;
		 next_record;
	end loop;
	-- again after completion move control to first record
	first_record;
	
end;

Open in new window

chalie001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Mark GeerlingsDatabase AdministratorCommented:
1. Which global variable do you want to reset?
2. What value do you want it reset to?
3. Exactly when (before, in, after, etc.) your when-new-form-instance trigger do you want it to be reset?

In Oracle Forms, global variables are usually used to pass values from form-to-form.  They should not be used for values that are only needed with a single form.

The syntax to assign a value to a global variable is the standard PL\SQL assignment statement, like this:
:global.my_variable := [something];
1

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
Mark GeerlingsDatabase AdministratorCommented:
I'm looking over you trigger some more now, and I'm wondering why you need this trigger?  Why not base this form block on the hr.job_history table?  Then your trigger could simply be:
begin
      go_block('job_history');
        execute_query;
end;
0
Mark GeerlingsDatabase AdministratorCommented:
If you want that query limited to a particular value from a :global variable, that is possible.  One way to do this is to add a non-database, control record to your form.   This block does not need any items that the user can see or interact with directly.  Your when-new-form-instance trigger should extract the value that you want from the global variable, and store that in a an item in your control block.  You can add a pre-query trigger in your job_history block to copy this value into  the appropriate item in the job_history block.  And, use a post-query trigger to clear the value from the control block item, it that is non-blank.  This will allow users of the screen to query other records after the initial query , if they want to.
1
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

chalie001Author Commented:
0
chalie001Author Commented:
this what i need the global value to be
when i press the button
declare
      cursor upd_global is
             select empid from employee
              where cii.sin = bii.sin
              where  emcode||serial||empnumber = regexp_replace(:block.item.assoc_nsn,'-',null);
              
begin
      
open upd_global;
fetch upd_global into   :global.use_empid;
close upd_global;       
            
      end;
0
Mark GeerlingsDatabase AdministratorCommented:
"when i press the button"

Which button?  I'm guessing you want a "when-button-pressed" trigger to have this logic, but I don't know which button you want this logic associated with.

Also, this looks like a syntax error in your trigger code:

      cursor upd_global is
             select empid from employee
              where cii.sin = bii.sin
              where  emcode||serial||empnumber = regexp_replace(:block.item.assoc_nsn,'-',null);

The "where emcode" on the last line here looks incorrect.  I thank that needs to be "and emcode", not "where emcode".
0
chalie001Author Commented:
Sorry my mistake it suppose to be and
0
Mark GeerlingsDatabase AdministratorCommented:
Which trigger in which form do you want this logic in?  And, why do you want to save this value to a global variable?  If you want to call a second form from a form the user is in *AND* you want to automatically query a record in the second form based on a value from the first form, then you could use a global variable to hold the value from the first form, so a when-new-form-instance trigger, and/or a pre-query trigger in the second form can retrieve the value from the global variable and automatically query a record (or records) based on this value.

But, if you just have multiple blocks (with or without multiple tab pages) in a single form, you don't need a global variable at all.
0
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
Databases

From novice to tech pro — start learning today.