Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    6

    Unanswered: LOOP EXITING(Urgent)

    Dear all,

    I have a form with two buttons OK and CANCEL.
    If i click OK i will start a big loop say 50lacs records.
    Now while the loop is running and if i click cancel the loop should exit...
    Now what is the problem is that...the cancel button is not responding to me unless the loop exits.


    Regards

    JIJU

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    I did this once, but it was many years ago. The solution involved using Timers. I can't remember all the details (and certainly not the syntax) but it was something like this:
    Code:
    -- Define a global variable (or could use a forms item or package variable):
    :GLOBAL.CONTINUE:='TRUE';
    
    -- Start process by setting up a repeating timer:
    create_timer(...,REPEAT);
    
    -- when-timer-expired trigger:
    Process one row (one loop iteration)
    If job finished OR :GLOBAL.CONTINUE != 'TRUE' then
      cancel timer;
    end if;
    
    -- when-button-pressed trigger on Cancel button:
    :GLOBAL.CONTINUE:='FALSE'
    This should mean that between each timer firing the user is able to press the Cancel button. You may have to experiment with the milliseconds parameter of create_timer.

  3. #3
    Join Date
    Nov 2005
    Posts
    6

    It is not working

    Hai,

    When I try this, it is not working. I cann't even press the cancel button.


    Regards

    JIJU

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    I just tried it and it works for me. Here is the very simple form I created (sorry, I can't attach the source file for some reason):
    Code:
    Block BLOCK2:
      Item COUNTER (Text)
      Item GO (Button):
        WHEN-BUTTON-PRESSED:
          declare
            t timer;
          begin
            t := create_timer('mytimer',50,repeat);
            :block2.counter := 0;
          end;
      Item CANCEL (Button):
        WHEN-BUTTON-PRESSED:
          declare
            t timer;
          begin  
            t := find_timer('mytimer');
            if not id_null(t) then
              delete_timer(t);
              message('Job cancelled by user.');
            end if;
          end;
    WHEN-TIMER-EXPIRED trigger on form:
      declare
        t timer;
      begin
        :block2.counter := :block2.counter + 1;
        if :block2.counter > 600 then
          t := find_timer('mytimer');
          delete_timer(t);
          message('Job complete');
        end if;
      end;
    I have run this both in client/server mode and in web mode, and it works both ways like this:
    1) When you press Go it starts counting up to 600 fairly quickly and then stops
    2) At any time you can press Cancel and stop the count

    For a real process you would have to process a single iteration of the process in the WHEN-TIMER-EXPIRED trigger something like this:
    Code:
      declare
        t timer;
        l_fiished boolean := false;
      begin
        l_finished := mypackage.process_one_row;
        if l_finished then
          t := find_timer('mytimer');
          delete_timer(t);
          message('Job complete');
        end if;
      end;
    You might have to experiment with the milliseconds paramater in create_timer to get the best value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •