Home » Developer & Programmer » Forms » save button (Forms oracle 10g)
save button [message #542033] Sat, 04 February 2012 01:20 Go to next message
furqan
Messages: 115
Registered: January 2012
Location: Hyderabad
Senior Member
hi
i have a save button in my form.on save button i have returned
when-button-pressed trigger.


update ship_dtl sd set sd.rec_qty = sd.rec_qty + :ship_dtl.rec_qty
where sd.mat_code = :ship_dtl.mat_code;

when iam entering a record first time its ok.second time with same
mat_code it is updating the rec_qty as well as adding a new record too.

please help.
Re: save button [message #542035 is a reply to message #542033] Sat, 04 February 2012 01:49 Go to previous messageGo to next message
ranamirfan
Messages: 535
Registered: January 2006
Location: Pakistan / Saudi Arabia
Senior Member

My Opinion - This type of Updation always Use Database Level triggers.
Update ship_dtl sd
Set sd.rec_qty = nvl(sd.rec_qty,0) + nvl(:ship_dtl.rec_qty,0) 
where sd.mat_code = :ship_dtl.mat_code;


Regards,
Irfan
Re: save button [message #542036 is a reply to message #542035] Sat, 04 February 2012 02:11 Go to previous messageGo to next message
furqan
Messages: 115
Registered: January 2012
Location: Hyderabad
Senior Member
i tried the your code...
but still the same..

first if i enter rec_qty=10
second if i enter rec_qty=2
third if i enter rec_qty=2

its showing 3 records
one with rec_qty=14
second with rec_qty=4
third with rec_qty=2

i want just want one record to be displayed with rec_qty=14

some problem in update query.

help me please
Re: save button [message #542041 is a reply to message #542036] Sat, 04 February 2012 02:17 Go to previous messageGo to next message
ranamirfan
Messages: 535
Registered: January 2006
Location: Pakistan / Saudi Arabia
Senior Member

Could you Post your Trigger code.?
Re: save button [message #542043 is a reply to message #542041] Sat, 04 February 2012 02:19 Go to previous messageGo to next message
furqan
Messages: 115
Registered: January 2012
Location: Hyderabad
Senior Member
begin
if (:ship_mstr.bill_type in ('First Inventory')) then
Update ship_dtl sd
Set sd.rec_qty = nvl(sd.rec_qty,0) + nvl(:ship_dtl.rec_qty,0)
where sd.mat_code = :ship_dtl.mat_code;
:system.message_level := 5;
commit;
end if;

GEN_ALERT;
end;
Re: save button [message #542058 is a reply to message #542043] Sat, 04 February 2012 03:43 Go to previous messageGo to next message
ranamirfan
Messages: 535
Registered: January 2006
Location: Pakistan / Saudi Arabia
Senior Member

Sample Code for database Level trigger.
CREATE OR REPLACE TRIGGER DML_SHIP_DTL 
BEFORE INSERT ON SHIP_DTL 
REFERENCING OLD AS Old NEW AS New 
FOR EACH ROW 
BEGIN

 IF INSERTING THEN
 
  UPDATE SHIP_DTL
  SET REC_QTY=NVL(REC_QTY,0)+NVL(:NEW.REC_QTY,0)
  WHERE MAT_CODE=:NEW.MAT_CODE;
  
  
 END IF;
 
END;


Hope it'll help you.

Regards,
Irfan
Re: save button [message #542066 is a reply to message #542058] Sat, 04 February 2012 04:00 Go to previous messageGo to next message
furqan
Messages: 115
Registered: January 2012
Location: Hyderabad
Senior Member
Irfan sir ...

as iam new to form and learning...dont know much...
shud i place this code on save button(when_button_pressed) and compile
or somewhere else.

thanx in advance and thanx really a lot in taking interest in my topic.

regards
Re: save button [message #542081 is a reply to message #542066] Sat, 04 February 2012 05:14 Go to previous messageGo to next message
furqan
Messages: 115
Registered: January 2012
Location: Hyderabad
Senior Member
waiting irfan sirji
Re: save button [message #542083 is a reply to message #542081] Sat, 04 February 2012 05:27 Go to previous messageGo to next message
ranamirfan
Messages: 535
Registered: January 2006
Location: Pakistan / Saudi Arabia
Senior Member

Quote:

i tried the your code...
but still the same..

first if i enter rec_qty=10
second if i enter rec_qty=2
third if i enter rec_qty=2

its showing 3 records
one with rec_qty=14
second with rec_qty=4
third with rec_qty=2

i want just want one record to be displayed with rec_qty=14

some problem in update query.

help me please


As my Understanding you have Master - Detail form.
Now you want to total receive qty.
Then You should make report for seeing total qty as following query.
Select Sum(Nvl(Rec_Qty,0)) Received_Qty ,Mat_Code
from Ship_Dtl
Group by Mat_Code;

Regards,
Irfan

[Updated on: Sat, 04 February 2012 05:28]

Report message to a moderator

Re: save button [message #542085 is a reply to message #542083] Sat, 04 February 2012 05:32 Go to previous messageGo to next message
furqan
Messages: 115
Registered: January 2012
Location: Hyderabad
Senior Member
yes for sure i hav master n detail form.no i dont want to
total rec_qty.just in case iam using same mat_code and entering rec_Qty
then it shud update only the existing rec_qty by adding the newly entered rec_qty.
Re: save button [message #542101 is a reply to message #542085] Sat, 04 February 2012 08:32 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Would you mind to post tables' description? It *must* contain referential integrity constraint so that we'd see how these tables are related. If the data model is correctly set (which includes primary / unique keys), then Forms is capable of creating a master-detail form (using a wizard) which will let you manipulate data correctly. You won't be able to enter duplicate values (because unique index will prevent it). Values that don't exist can be entered freely. The ones that already exist in a table should NOT be inserted but fetched from a database (by executing a query in a form) and then UPDATED.

That's how it is supposed to be done.

If you need to manipulate data manually by considering whether something exists or not, maybe the data model is incorrectly set.
Re: save button [message #542218 is a reply to message #542101] Sun, 05 February 2012 23:42 Go to previous message
furqan
Messages: 115
Registered: January 2012
Location: Hyderabad
Senior Member
Thanx sir...when you post this...reading your post i just got clicked and made some changes in tables and got it...

Thanx a lot irfan sir and littlefoot sir...

i really appreciate your help. thankx
Previous Topic: Forms logo
Next Topic: update block based "from clause query"
Goto Forum:
  


Current Time: Fri Aug 23 17:01:34 CDT 2024