Global variable in form

chalie001
chalie001 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Administrator
Commented:
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];
Mark GeerlingsDatabase Administrator

Commented:
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;
Mark GeerlingsDatabase Administrator

Commented:
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.
Ensure you’re charging the right price for your IT

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

Author

Commented:

Author

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;
Mark GeerlingsDatabase Administrator
Commented:
"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".

Author

Commented:
Sorry my mistake it suppose to be and
Mark GeerlingsDatabase Administrator
Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial