Home » Developer & Programmer » Forms » to save last record and exit loop
icon8.gif  to save last record and exit loop [message #224648] Wed, 14 March 2007 22:56 Go to next message
aries73
Messages: 4
Registered: March 2007
Junior Member
i have a table abc_report and based on this i have created a form with database block abc_report. Heare all items except one (chk) is database items of table abc_report.
When i write fllowing coding in when button pressed last record does not saved.
pl. help.
BEGIN
GO_BLOCK('abc_REPORT');
FIRST_RECORD;
loop
if ((:abc_report.CHK='Y') OR (:abc_report.CHK='y')) then
UPDATE abc_REPORT
SET abc_DATE=sysdate
WHERE emno = :abc_REPORT.emno
AND (:abc_REPORT.CHK='Y' OR :abc_REPORT.CHK='y') ;
NEXT_RECORD;
else
next_record;
end if;
exit when (:system.last_record='TRUE');
end loop;
COMMIT;
END;
Re: to save last record and exit loop [message #224674 is a reply to message #224648] Thu, 15 March 2007 02:08 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Your procedure "doesn't commit" the last record (actually, it does, but you didn't change 'abc_date' value) because you exit the loop BEFORE the last record is changed.

Now, this could be done the other way - simply COMMIT the form (without this code) and update the table using the database trigger. However, if you insist on keeping this code in a form, you might try with something like this:
BEGIN

  GO_BLOCK('abc_report');
  FIRST_RECORD;
  
  LOOP
    IF upper(:abc_report.chk) = 'Y'
    THEN
       :abc_report.date := sysdate;
    END IF;
    
    IF :system.last_record = 'FALSE'   --> note this! You've checked whether it is TRUE
    THEN
       NEXT_RECORD;
    ELSE
       EXIT;
    END IF;
    
  END LOOP;
  
  COMMIT;
  
END; 
Re: to save last record and exit loop [message #224932 is a reply to message #224648] Fri, 16 March 2007 00:05 Go to previous message
aries73
Messages: 4
Registered: March 2007
Junior Member
thanks
Previous Topic: Conversion FORMS 3.0 to Forms 6.0
Next Topic: DESPERATE: FRM-40508
Goto Forum:
  


Current Time: Sun Feb 02 12:49:52 CST 2025