Home » Developer & Programmer » Forms » get column sum if its records are checked (10g)  () 1 Vote
get column sum if its records are checked [message #329396] Wed, 25 June 2008 05:54 Go to next message
amdabd
Messages: 91
Registered: November 2007
Location: My Computer
Member
hi,
I'm trying to get the sum of numeric column in tabular form
if its record are checked .
please, complete or correct my errors.
thanks
  • Attachment: chk_sum.fmb
    (Size: 52.00KB, Downloaded 133 times)
Re: get column sum if its records are checked [message #329458 is a reply to message #329396] Wed, 25 June 2008 08:41 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
I will complete or correct your work if you agree to do mine.
Can I send you my work for today?

If you have a specific issue, describe it and ask about that specific thing. Don't ask people to do your work for you, unless you are willing to pay them your salary.
Re: get column sum if its records are checked [message #329539 is a reply to message #329396] Wed, 25 June 2008 13:27 Go to previous messageGo to next message
amdabd
Messages: 91
Registered: November 2007
Location: My Computer
Member
Frank wrote on Wed, 25 June 2008 08:41
Don't ask people to do your work for you, unless you are willing to pay them your salary.


Perhaps, I misused words, but I'd never ask any body to do my job, Mr.Frank.

I used the forum to learn more, as other did, and really it enhance my knowledge,

NOT TO LET OTHER DO MY JOB

I think, I've t ask -Mr.Frank- in '5466' message you sent to this forum " asking for " and " answer " questions how many times did you pay to get information and answer for your question?

OR JUST YOU ANSWER THIS QUESTION!!
thanks

[Updated on: Wed, 25 June 2008 13:28]

Report message to a moderator

Re: get column sum if its records are checked [message #329548 is a reply to message #329539] Wed, 25 June 2008 14:42 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
As I indicated, my conclusion was based on the fact that you did not make clear what it was you tried; where it went wrong.
The idea of a forum is that someone asks a question and hopes other people will put in effort to answer that and help out with the problem presented.
This implies that the forum-community can expect some effort from the person asking the question first; after all, that is the one seeking help.
Adding an fmb and asking people to correct and improve it is NOT what I consider putting effort in a question.

Why not explain what you did? Tell what you tried, why it failed, etc.
Re: get column sum if its records are checked [message #329637 is a reply to message #329396] Thu, 26 June 2008 02:22 Go to previous messageGo to next message
amdabd
Messages: 91
Registered: November 2007
Location: My Computer
Member
sure, Frank

I'm trying to get the value of field within a record if this record is checked.

I use the following code within WHEN-CHECKBOX-CHANGED
DECLARE
   v_sum   NUMBER;
BEGIN
   IF CHECKBOX_CHECKED ('emp.chk1')
   THEN
      SELECT NVL (:emp.sal, 0)
        INTO v_sum
        FROM DUAL;

      :emp.di_sum := NVL (:emp.di_sum, 0) + v_sum;
   ELSE
      SELECT NVL (:emp.sal, 0)
        INTO v_sum
        FROM DUAL;

      :emp.di_sum := NVL (:emp.di_sum, 0) - v_sum;
   END IF;
END;

however, it return or omit the value of the current record all the time,
rather than adding or omitting the checked or unchecked one.

./fa/4520/0/
thanks
  • Attachment: chk_sum.JPG
    (Size: 34.43KB, Downloaded 288 times)
Re: get column sum if its records are checked [message #329656 is a reply to message #329637] Thu, 26 June 2008 02:45 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
That is probably because :emp.di_sum is part of the :emp record, which means that it has an occurrence per record.
Tips:
- Use a field that is global to the block (or the form)
- be careful of initialisations
- don't use "select from dual" to do assignments (:sum_field = nvl(:sum_field, 0) + nvl(:emp.sal, 0) is all you need)
Re: get column sum if its records are checked [message #329657 is a reply to message #329637] Thu, 26 June 2008 02:51 Go to previous messageGo to next message
wency
Messages: 450
Registered: April 2006
Location: Philippines
Senior Member

any code from other trigger like when-new-item-instance? I suspect :emp.di_sum value has been modified before that code fires. what is the value of that item right before the computation? message the value right after the word begin to check.
Re: get column sum if its records are checked [message #329660 is a reply to message #329637] Thu, 26 June 2008 02:55 Go to previous messageGo to next message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Create another (control) block (let's call it "sum_sal") and move "di_sum" item over there. Initialize it in the WHEN-NEW-FORM-INSTANCE trigger as
:sum_sal.di_sum := 0;

WHEN-CHECKBOX-CHANGED trigger doesn't have to be THAT complicated; this is enough:
if checkbox_checked('emp.chk1')
then
   :sum_sal.di_sum := :sum_sal.di_sum + nvl(:emp.sal, 0);
end if;

However, do you realize that summary will be increased if you check-uncheck-check-uncheck-check-... the same checkbox all over again?

[EDIT] Yes, you DO realize (but I didn't, sorry); so, a "working" trigger might look like this:
if checkbox_checked('emp.chk1')
then
   :sum_sal.di_sum := :sum_sal.di_sum + :emp.sal;
else
   :sum_sal.di_sum := :sum_sal.di_sum - :emp.sal;
end if;
Also, I apologize for reposting almost everything what's already been said in the past few minutes by other forum members, but - today OraFAQ Forum is extremely slow, or MY connection sucks and posting or viewing messages lasts forever. I just didn't see what you guys have said. Sorry again.

[Updated on: Thu, 26 June 2008 03:05]

Report message to a moderator

Re: get column sum if its records are checked [message #329675 is a reply to message #329656] Thu, 26 June 2008 03:40 Go to previous messageGo to next message
amdabd
Messages: 91
Registered: November 2007
Location: My Computer
Member
thanks everybody
now, it works properly.
Yes, the main error was

Frank wrote on Thu, 26 June 2008 02:45
That is probably because :emp.di_sum is part of the :emp record, which means that it has an occurrence per record.

  • Attachment: chk_sum.fmb
    (Size: 48.00KB, Downloaded 128 times)

[Updated on: Thu, 26 June 2008 03:58]

Report message to a moderator

Re: get column sum if its records are checked [message #329728 is a reply to message #329675] Thu, 26 June 2008 06:18 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
See now the point I tried to make in my first reply?
Now that you made the problem clear, and showed some effort yourself, three people were willing to help you out!
It is not as easy as one might think to ask a good question in a forum Smile
Re: get column sum if its records are checked [message #329768 is a reply to message #329396] Thu, 26 June 2008 07:57 Go to previous message
amdabd
Messages: 91
Registered: November 2007
Location: My Computer
Member
OK , dear Frank Smile I got it

thanks,

Previous Topic: Executing Package Procedure from Oracle forms
Next Topic: Problem with using an LOV in form for insertion of data.
Goto Forum:
  


Current Time: Sun Dec 04 04:50:00 CST 2016

Total time taken to generate the page: 0.09567 seconds