Home » Developer & Programmer » Forms » Procedure (Oracle8i and Form6i)
Procedure [message #494531] Tue, 15 February 2011 10:30 Go to next message
mkhalil
Messages: 108
Registered: July 2006
Location: NWFP Peshawar Pakistan
Senior Member
Dear fellows,

I am facing a problem from the last 2 days. I have tried to correct and understand but unable to detect the mistake where i have done.

I have developed a form to enter the data of purchases/stock inward of a mobile frenchise. When they receive the stock of SIM from company in the form of from and to mobile numbers but they found some SIM NUMBERS MISSING in both end numbers. They also record those missing numbers but side by side the form should record all those numbers between from and to numbers except missing numbers.

I have header block, detail block, missing numbers block and received SIM block. The immage of that form is attached.

I have a proceedure
PROCEDURE MISSINGNO IS
cv_mismsisdn number;
v_msisdndif number := :invd.msisdndif - 1;
v_invdno number := :invd.invdno;
v_msisdnf number := :invd.msisdnf;
v_msisdnt number := :invd.msisdnt;
cursor c_mismsisdn is select mismsisdn from mismsisdn where invdno = v_invdno order by mismsisdn;
BEGIN
  open c_mismsisdn;
  if v_msisdnf is not null and v_msisdnt is not null then
	  for i in 0..v_msisdndif loop
	  	loop
	  		fetch c_mismsisdn into cv_mismsisdn;
	  		exit when v_msisdnf+i = cv_mismsisdn;
	  		exit when c_mismsisdn%notfound;
	  	end loop;
	  	if v_msisdnf+i != cv_mismsisdn then
	  		insert into recmsisdn(invdno,msisdn,status)
	  		values(:invd.invdno,v_msisdnf+i,'R');
	  	end if;
	  end loop;
	 end if;
 	close c_mismsisdn;
END;

The above proceedure has been called on Key-Next_item of missing number text item
begin
	delete from mismsisdn
	where invdno = :global.refno;
	delete from recmsisdn
	where invdno = :global.refno;
end;

begin
	if :system.cursor_record = to_char(:invd.misqty) then
		post;
		go_block('invd');
		last_record;
		MISSINGNO;
--		next_record;
--	else
	end if;
		next_record;
end;

where as the output on received block show that 3159572065 number has also been displayed where as this number is missing. This proceedure only count for the last missing number and left the others.

Please guide me in this regard. I realy appreciate the person who will give me a time in such bussy environment.
  • Attachment: Inward.GIF
    (Size: 92.38KB, Downloaded 632 times)
Re: Procedure [message #494534 is a reply to message #494531] Tue, 15 February 2011 11:01 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
I'm struggling to follow the logic of your procedure but I'm fairly sure it's wrong, I can't follow what you're doing with those loops.
I'd do something like this [pseudo code]:
DECLARE

  l_exists NUMBER;

BEGIN

FOR n IN :<start sim number>..:<end sim number> LOOP

  BEGIN

    --See if the sim is missing
    SELECT 1 INTO l_exists
    FROM <missing sim table>
    WHERE <sim number> = n;

  EXCEPTION WHEN no_data_found THEN
    --Not a missing sim so do insert
    insert into recmsisdn(invdno, msisdn, status)
    values(:invd.invdno, n, 'R');

  END;

END LOOP;

END;


Couple of other points on your procedure.
1) Don't declare variables for the sake of it. If you can reference the datablock item throughout do so, it'll make the code easier to follow.
2) variables should be typed to the corresponding database columns where ever possible. So cv_mismsisdn would be:
cv_mismsisdn mismsisdn.mismsisdn%TYPE;
Re: Procedure [message #494671 is a reply to message #494534] Wed, 16 February 2011 08:01 Go to previous message
mkhalil
Messages: 108
Registered: July 2006
Location: NWFP Peshawar Pakistan
Senior Member
Thanks master. I exectly understand your guidance and will be care full in future. Realy this makes the code easy to write and understand. Now my problem has been solved. Realy, I am very thankful to you.
Previous Topic: initial value issues in 10g forms
Next Topic: progress bar in oracle form 10g
Goto Forum:
  


Current Time: Tue Sep 17 16:18:59 CDT 2024