looping comparison row by row [message #346569] |
Mon, 08 September 2008 22:49 |
fadhzone
Messages: 61 Registered: April 2008
|
Member |
|
|
Hi All..
Below is my script in procedure (actually i want to put it in key next item trigger):
PROCEDURE PROC_CHECK_DATE IS
l_month1 VARCHAR2(3);
l_mth VARCHAR2(3);
l_month VARCHAR2(3);
l_lnno NUMBER;
BEGIN
GO_BLOCK('BL_HDR');
l_lnno := :SYSTEM.CURSOR_RECORD;
FIRST_RECORD;
LOOP
IF l_lnno = 1 THEN
l_month1 := TO_CHAR(:BL_HDR.CHQ_DATE,'MON');
END IF;
l_month := TO_CHAR(:BL_HDR.CHQ_DATE,'MON');
IF l_month <> l_month1 THEN
GO_ITEM('BL_HDR.CHQ_DATE');
:PARAMETER.AL_BTN := Msg.Show_Msg('Cheque Month Is Not Match With First Row',msg.CAUTION);
RAISE Form_Trigger_Failure;
END IF;
EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
END;
..but it looks like it doesn't compare it all...i want to compare month row by row to make sure it will not save the different month.the month must follow the 1st row.
i really2 hope somebody will help me.
[EDITED by LF: added [code] tags]
[Updated on: Mon, 08 September 2008 23:42] by Moderator Report message to a moderator
|
|
|
Re: looping comparison row by row [message #346583 is a reply to message #346569] |
Mon, 08 September 2008 23:52 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Well, the procedure code *seems* to be OK. I'd slightly rewrite it (remove unnecessary variables, put the first record's month out of the loop (as GO_BLOCK puts us into the first record anyway).
PROCEDURE PROC_CHECK_DATE IS
l_month1 VARCHAR2(3);
l_month VARCHAR2(3);
BEGIN
GO_BLOCK('BL_HDR');
l_month1 := TO_CHAR(:BL_HDR.CHQ_DATE,'MON');
LOOP
l_month := TO_CHAR(:BL_HDR.CHQ_DATE,'MON');
IF l_month <> l_month1 THEN
GO_ITEM('BL_HDR.CHQ_DATE');
:PARAMETER.AL_BTN := Msg.Show_Msg('Cheque Month Is Not Match With First Row',msg.CAUTION);
RAISE Form_Trigger_Failure;
END IF;
EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
END;
It might be worth knowing which trigger calls this procedure. You have mentioned the KEY-NEXT-ITEM, but - do you really use it? Basically, item validation (which is what you, actually, do) should be done in the WHEN-VALIDATE-ITEM trigger because, if user navigates through the forum using the mouse, KEY-NEXT-ITEM will not fire; or, he/she might navigate backwards through items so you should use KEY-PREV-ITEM (previous item) trigger. So, leave these triggers alone and use WHEN-VALIDATE-ITEM instead. Or, possibly, do the validation before committing (but that might cause more problems as there might be many "invalid" months which should be trapped much earlier.
|
|
|
Re: looping comparison row by row [message #346584 is a reply to message #346569] |
Mon, 08 September 2008 23:55 |
|
sasipalarivattom
Messages: 121 Registered: June 2007 Location: Cochin ( INDIA )
|
Senior Member |
|
|
Hi Dear,
Please try this code...
Quote: |
PROCEDURE PROC_CHECK_DATE IS
l_month1 VARCHAR2(3);
l_mth VARCHAR2(3);
l_month VARCHAR2(3);
l_lnno NUMBER;
BEGIN
GO_BLOCK('BL_HDR');
FIRST_RECORD;
l_month1 := TO_CHAR(:BL_HDR.CHQ_DATE,'MON');
LOOP
l_month := TO_CHAR(:BL_HDR.CHQ_DATE,'MON');
IF l_month <> l_month1 THEN
GO_ITEM('BL_HDR.CHQ_DATE');
:PARAMETER.AL_BTN := Msg.Show_Msg('Cheque Month Is Not Match With First Row',msg.CAUTION);
RAISE Form_Trigger_Failure;
END IF;
EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
END;
|
Regards,
Sasi...
Oh... No.
Littlefoot Overtook Me....
[Updated on: Tue, 09 September 2008 00:02] Report message to a moderator
|
|
|
Re: looping comparison row by row [message #346588 is a reply to message #346569] |
Tue, 09 September 2008 01:10 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
Why do this 'row by row'? On the first row store the month that is entered. Then in each subsequent row validate the month and make sure it matches the stored month.
David
|
|
|