Raise Exception In For Loop

Currently my loop code is
FOR i IN 2..vt_records.count
        LOOP
          EXIT WHEN INSTR(vt_records(i), v_delimiter,2) = 0;
            csv_to_array(vt_records(i), vt_record, v_delimiter);
          --| Workaround for the case when the last column is null
          IF vt_record.count < v_expected_csv_cols
            THEN
              FOR i IN 1..(v_expected_csv_cols - vt_record.COUNT)
                LOOP
                  --RAISE_APPLICATION_ERROR(-20000, 'vt_Record.COUNT=' || vt_record.count || ' - loopcount=' || (v_expected_csv_cols-vt_record.COUNT));
                  vt_record(vt_record.COUNT+1) := NULL;
                END LOOP;
          END IF;
         begin
           INSERT INTO cit_interface_correlation (
           massupdateid,
           primarymatkey_hr,
           geokey_hr,
           depmatkey_hr,
           promokey_hr,
           statcalcday,
           usercorfactor,
           inst_user,
           inst_session,
           inst_date
           VALUES
           seq_cit_interface_correlation.nextval,
           vt_record(1),
           TRIM(vt_record(2)),
           TRIM(vt_record(3)),
           vt_record(4),
           TO_DATE(TRIM(vt_record(5)),'DD.MM.YYYY'),
           TRIM(vt_record(6)),
           v('APP_USER'),
           v('APP_SESSION'),
           sysdate
         end;
      END LOOP;
{code]
What I need to do is raise an exception if vt_record(5) is greater than sysdate.
If any line has a date greater than sysdate then the loop should fail and not carry on.
Cheers
Gus                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Like this?
for i in 2..vt_records.count
loop
     exit when instr(vt_records(i), v_delimiter,2) = 0;
     csv_to_array(vt_records(i), vt_record, v_delimiter);
     if vt_record.count < v_expected_csv_cols
     then
          for i in 1..(v_expected_csv_cols - vt_record.count)
          loop
               vt_record(vt_record.count+1) := null;
          end loop;
     end if;
     if vt_record(5) > sysdate then
          raise_application_error(-20001, 'vt_record(5) is greater than sysdate');
     else
          insert into cit_interface_correlation
               massupdateid,
               primarymatkey_hr,
               geokey_hr,
               depmatkey_hr,
               promokey_hr,
               statcalcday,
               usercorfactor,
               inst_user,
               inst_session,
               inst_date
          values
               seq_cit_interface_correlation.nextval,
               vt_record(1),
               trim(vt_record(2)),
               trim(vt_record(3)),
               vt_record(4),
               to_date(trim(vt_record(5)),'dd.mm.yyyy'),
               trim(vt_record(6)),
               v('APP_USER'),
               v('APP_SESSION'),
               sysdate
     end if;
end loop;

Similar Messages

  • Index out of Bounds Exception in for loop.

    Occasionaly with the code below, i get an index out of bounds error, index 1, size 1, however the for loop should ensure that it never calls the getActorLocation method if the index is the same size as the arrayList size.
    Im having one of those days, and i just cant see what error i have made.
    Perhaps i need coffee? lol
    Cheers
    James
    private void checkMemoryIntegrity(){
            Actor actor = actorList.get(actorIndex);
            ArrayList<Integer> inRangeList = getActorsInMemoryRange(actor, actor.getRange());
            inRangeList.trimToSize();
            for (int i = 0; i < inRangeList.size();i++){
                if (inRangeList.size() != 0){
                    actor = brainState.getActorLocation(i); //<<<<<<<<< problem line
                    if (!actorList.contains(actor)){
                        brainState.actorLocations.remove(i);
    public ArrayList <Integer> getActorsInMemoryRange(Actor actor, int range){
            int i = 0;
            int x = actor.getX();
            int y = actor.getY();
            ArrayList <Integer> inRangeList = new ArrayList <Integer> ();
            Actor compActor;
            while (i< brainState.actorLocations.size())
                compActor = brainState.getActorLocation(i);
                int xDist = x - compActor.getX();
                if ( (xDist >= (-1) * range) && (xDist <= range) ){
                    int yDist = y - compActor.getY();
                    if ( (yDist >= (-1) * range) && (yDist <= range) ){
                        inRangeList.add(i);
                i++;
            return inRangeList;
        }

    I was thinking it might be easier to do it this way:
    Iterator<Actor> i = actorLocations.iterator();
    while(i.hasNext())
        if (!actorList.contains(i.next())) {
            i.remove();
    }It sounds like you have an equals() method which compares the x and y locations of the actor. If not then you will have to enclose the remove in an if block which compares the actor location. Does that make sense?
    Edit: contains uses the equals method.
    Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that
    (o==null ? e==null : o.equals(e)).Edited by: Edward_Kimber on May 23, 2008 11:43 AM

  • Exception statement for looping query

    Hi this is my query to date:
    declare   
        cursor curs is
         select name_id_no, incident_date
         from MICHAELC.Food_Nov_01_final t
         --where rownum < 6
         for update of cat_latest;
        w_cat_latest        number(4,0);
        w_cat_latest_date   date;
        w_cat_max           number(4,0);
        w_cat_max_date      date;
        w_cat_min           number(4,0);
        w_cat_min_date      date;
    begin
        for i in curs loop
            -- get latest cat date
            select max(cat_score_date) into w_cat_latest_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score_date <= i.incident_date;
            -- get latest cat score
            select cat_score into w_cat_latest
            from rbn_cat
            where customer_no = i.name_id_no
            and cat_score_date = w_cat_latest_date
            and rownum = 1;
            --get maximum cat score
            select max(cat_score) into w_cat_max
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get maximum cat date
            select cat_score_date into w_cat_max_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_max
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            --get minimum cat score
            select min(cat_score) into w_cat_min
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get minimum cat date
            select cat_score_date into w_cat_min_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_min
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            update MICHAELC.Food_Nov_01_final
                set cat_latest = w_cat_latest
                   , cat_latest_date = w_cat_latest_date
                   , cat_max  = w_cat_max
                   , cat_max_date = w_cat_max_date
                   , cat_min    = w_cat_min
                   , cat_min_date = w_cat_min_date
            where current of curs;
        end loop;
    end;
    I receive the following error:
    Error report:
    ORA-01403: no data found
    ORA-06512: at line 37
    01403. 00000 - "no data found"
    *Cause:   
    *Action:
    I want to use an exception statement, something along the lines of
    exception when no_data_found then
                w_cat_latest_date     := NULL;
                w_cat_latest          := NULL;
                w_cat_max             := NULL;
                w_cat_max_date        := NULL;
                w_cat_min             := NULL;
                w_cat_min_date        := NULL;I'm just not really sure how to use the exception statement correctly and if it is the best way to handle this error. Thank-you for your time and help.
    Banner:
    Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Like this;-
    declare   
        cursor curs is
         select name_id_no, incident_date
         from MICHAELC.Food_Nov_01_final t
         --where rownum < 6
         for update of cat_latest;
        w_cat_latest        number(4,0);
        w_cat_latest_date   date;
        w_cat_max           number(4,0);
        w_cat_max_date      date;
        w_cat_min           number(4,0);
        w_cat_min_date      date;
    begin
        for i in curs loop
            -- get latest cat date
    BEGIN
            select max(cat_score_date) into w_cat_latest_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score_date <= i.incident_date;
    EXCEPTION
    when no_data_found then
                w_cat_latest_date     := NULL;
    END;       
    BEGIN
            -- get latest cat score
            select cat_score into w_cat_latest
            from rbn_cat
            where customer_no = i.name_id_no
            and cat_score_date = w_cat_latest_date
            and rownum = 1;
    EXCEPTION
    when no_data_found then
                w_cat_latest
         w_cat_latest:= NULL;
    END;       
    /*   you get the idea
            --get maximum cat score
            select max(cat_score) into w_cat_max
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get maximum cat date
            select cat_score_date into w_cat_max_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_max
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            --get minimum cat score
            select min(cat_score) into w_cat_min
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get minimum cat date
            select cat_score_date into w_cat_min_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_min
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            update MICHAELC.Food_Nov_01_final
                set cat_latest = w_cat_latest
                   , cat_latest_date = w_cat_latest_date
                   , cat_max  = w_cat_max
                   , cat_max_date = w_cat_max_date
                   , cat_min    = w_cat_min
                   , cat_min_date = w_cat_min_date
            where current of curs;
        end loop;
    end;
    /

  • FOR loop messes up the DBMS_UTILITY.FORMAT_ERROR_BACKTRACE

    Hello!
    I've encountered the following problem which could be resolved for now
    by eliminating FOR loop, but that's not a good solution.
    The problem is that if some exception is raised inside the `for' loop
    with cursor, and the outer block contains exception handler with
    `format_error_backtrace' call, the last one shows not the exact line
    where the exception was raised, but the loop beginning. Let me show
    you.
    The next block loops over some table and tries to assign one of the
    field's value to local variable with intentionally low
    precision. Please look at line where exception is raised:
    ========================================
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    x number(1);
      3  begin
      4    for x_r in (select xlong from xtable)
      5    loop
      6      dbms_output.put_line('Processing... '|| x_r.xlong);
      7      x := x_r.xlong;
      8    end loop;
      9* end;
    SQL> /
    Processing... 611911
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: number precision too large
    ORA-06512: at line 7========================================
    Next, I'll put exception handler with `format_error_message' call in
    it:
    ========================================
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    x number(1);
      3  begin
      4    for x_r in (select xlong from xtable)
      5    loop
      6      dbms_output.put_line('Processing... '|| x_r.xlong);
      7      x := x_r.xlong;
      8    end loop;
      9  exception
    10    when others then
    11      dbms_output.put_line(dbms_utility.format_error_backtrace);
    12* end;
    SQL> /
    Processing... 611911
    ORA-06512: at line 4========================================
    Now look how line number changed; instead of 7'th line it is 4'th
    now -- at the beginning of the loop.
    Now, let's expand this loop into explicit open/fetch/close sequence:
    ========================================
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    x number(1);
      3    cursor x_c is select xlong from xtable;
      4    x_r x_c%rowtype;
      5  begin
      6    open x_c;
      7    loop
      8      fetch x_c into x_r;
      9      exit when x_c%notfound;
    10      dbms_output.put_line('Processing... '|| x_r.xlong);
    11      x := x_r.xlong;
    12    end loop;
    13    close x_c;
    14  exception
    15    when others then
    16      dbms_output.put_line(dbms_utility.format_error_backtrace);
    17* end;
    SQL> /
    Processing... 611911
    ORA-06512: at line 11========================================
    Here we see that line number where exception was raised is now
    correct!
    I suppose the problem is in some hidden exception handling behind the
    `for' loop execution. Any help will be appreciated, thanks in advance!
    Message was edited by:
    uj2

    uj2,
    I think the reason is probably PL/SQL optimisation. Because you are using backtrace, it means you are on 10g. This means you have an automatic PLSQL_OPTIMIZE_LEVEL of 2. At this level, the compiler will re-write your cursor-for-loop to array fetches "under the covers", so my feeling is that the internal code re-organisation might have something to do with it.
    Can you try your cursor-for-loop example with these settings:
    ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL = 0;
    ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL = 1;
    Neither of these levels optimise cursor-for-loops.
    The reason your explicit fetch doesn't display the same behaviour is that the compiler doesn't optimise those.
    Of course I could be wrong, but this is where I'd start testing.
    Regards

  • FOR LOOP EXCEPTION not working !!! please help

    Hi,
    Why is the NO_DATA_FOUND execption not getting executed. ????
    Hereis the code....
    CURSOR newreccur IS
    SELECT * from emp_table;
    BEGIN
    v_file_handle := UTL_FILE.FOPEN('out','new.dat','W');
    BEGIN
    FOR emp_rec IN newreccur LOOP
    -- Write procurement records
    UTL_FILE.PUT(v_file_handle,'emp_rec.num');
    END LOOP;
    EXCEPTION WHEN NO_DATA_FOUND THEN
    dbms_output.put_line ('No data found ')
    END;
    EXCEPTION
    WHEN UTL_FILE.INVALID_PATH
    THEN
    DBMS_OUTPUT.PUT_LINE ( 'Invalid Path ' || TO_CHAR (SQLCODE) );
    UTL_FILE.FCLOSE_ALL;
    END;

    cursor for loops do not raise no_DatA_found - they simply stop looping when they run out of data. you can set a variable within the loop, and then check it after the loop if you need to know if data was returned or not.

  • Raising 2 alerts for 1 exception

    I am working on raising an alert using Alert framerwork
    with exception reporting and reporting agent .
    I have a query ( has projects ID & Approavl ate as free chars.) where we want to raise the alerts for the projects approved in last 30 days. I have defined a exception for this and it is working fine.
    I also  created a reporting agent on this query linking to alert categories. Rep. agent has Project ID and Approval date in the "Drilldown charecterstics"
    Problem:
    Query has only one exception , but when I run the reporting agent it is raising two alerts .
    Appreciate your help.
    Regards
    MB

    Hi ,
      If I remove the exception in the query,it is not raising the alert .
    Regards
    MB

  • Catching errors in Web Dynpro for Java when thrown from RFC Raise Exception

    Hello Developers,
    I'm looking for information that explains how a Web Dynpro for Java application responds and processes errors that are thrown from a Raise Exception event within an RFC.
    The Exceptions do not appear to be part of the Model and I can't identify how they get processed.
    When rfc HRXSS_CAT_WD_RECORD raises exception PERNR_NOT_LOCKED this exception is passed back to the calling webdynpro CAT DC that displays the exception on the web page along with the log. 
    I would like to display a friendlier message and without the log.  Any information on how to customize the handling of this error would be greatly appreciated.
    Thank you,
    Terry

    [see here|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.highlightedcontent?documenturi=%2flibrary%2fuser-interface-technology%2fwdJava%2FHowtoHandleExceptionsEffectivelyWhileWorkingwithWebDynproJava%28WDJ%29.pdf]

  • Writting exception within cursor for loop

    I have two cursor for loop as
    for rec1 in () loop --loop 1
    for rec2 in () loop --loop2
    <statements>
    end loop;
    end loop
    Now I want to handle exception within my second for loop so that after terminating the loop it will again go to the first loop...
    How to do it ? Please help......

    you may
    BEGIN
       FOR rec1 IN your_select1
       LOOP                                                              --loop 1
          BEGIN
             FOR rec2 IN your_select2
             LOOP                                                         --loop2
                statements;
             END LOOP;
          EXCEPTION
             WHEN OTHERS
             THEN
                log_error;
          END;
       END LOOP;
    END;or ...depending on your exact needs:
    BEGIN
       FOR rec1 IN your_select1
       LOOP                                                              --loop 1
          FOR rec2 IN your_select2
          LOOP
             BEGIN                                                        --loop2
                statements;
             EXCEPTION
                WHEN OTHERS
                THEN
                   log_error;
             END;
          END LOOP;
       END LOOP;
    END;

  • For loop issue and error exception

    I am finishing up a program and having a few issues....I can send my instructions so it may seem easier to what I want...the first issue deals with the for loop for the 2nd for loop in the actionperformed when i click on go it does not change any of the boxes to yellow
    Also when I check for errors it does not check with the code I have...I know it says on the instructions to use try\catch but I am just going to use if statements because I am not very familar with the try\catch and will accept some points takin off...any help with this by tonight id really appreciate it as long as noone is too busy...Thanks
    instructions:
    This will incorporate arrays, for loops, and Frames all in one.
    Create a panel containing an array of 16 TextArea components that change color to correspond with the start, stop, and step values entered by the user. Perform the following tasks to create the Checkerboard Array application shown below. When the user enters the start, stop, and step fields and then clicks the Go button, the results are also shown below.
    1.     Call your application Checkerboard.java
    2.     You will need the following variables� declare them as private:
    a.     16 component TextArea array
    b.     a Panel to hold the array
    c.     3 TextField components with length of 10
    d.     3 int variables to receive the start, stop, and step values
    e.     3 Labels to display the words Start, Stop, and Step
    f.     a Go button
    g.     a Clear button
    h.     a Panel to hold the 3 TextFields, 3 Labels, and the 2 Buttons
    3.     Create a constructor method to:
    a.     construct each of the components declared above and initializes the start, stop, and step variables to zero (when constructing the TextArea components, use the following parameters: null, 3, 5, 3)
    b.     set the Frame layout to BorderLayout
    c.     write a for loop to loop the array and set each of the 16 TextArea components in that array so they cannot be edited. In the same loop, set each of the TextArea components text to be 1 more than the index number. Also in this same loop, set the background of each of the TextArea components to white.
    d.     set the Panel for the TextArea components to GridLayout with 4 rows, 4 columns, and both gaps set to 10
    e.     set the Panel for the TextFields, Labels, and button to GridLayout with 3 rows, 3 columns, and both gaps set to 5
    f.     add the components to their respective Panels
    g.     make the buttons clickable
    h.     place the Panels in the Frame� put one in the NORTH and one in the CENTER
    i.     Enter the addWindowListener() method described in the chapter� this is the method that overrides the click of the X so it terminates the application
    4.     In your actionPerformed() method:
    a.     convert the data in your TextFields to int and store them in the variables declared above
    b.     write a loop that goes through the array setting every background color to blue
    c.     write another loop that�s based on the user inputs. Each time the loop is executed, change the background color to yellow (so� start your loop at the user�s specified starting condition. You�ll stop at the user�s specified stopping value. You�ll change the fields to yellow every time you increment your loop based on the step value. REMEMBER: Your displayed values are 1 off from your index numbers!!)
    5.     Write a main() method that creates an instance of the Checkerboard Frame.
    a.     set the bounds for the frame to 50, 100, 300, 400
    b.     set the title bar caption to Checkerboard Array
    c.     use the setVisible() method to display the application Frame during execution
    6.     After you get all of this complete, include error handling to make sure:
    a.     the values entered in the TextFields are valid integers
    b.     the start value is greater than or equal to 1 and less than or equal to 16
    c.     the stop value is greater than or equal to 1 and less than or equal to 16
    d.     the step value is greater than or equal to 1 and less than or equal to 16
    e.     the start condition is less than the stop condition
    f.     when an error occurs, give an error message in a dialog box that is specific to their error, remove the text from the invalid field, and put the cursor in that field so the user has a chance to re-enter� this can be accomplished by using multiple try/catch statements
    g.     only change the colors if the numbers are valid
    7.     Create a clear button as seen in the example below. This button should:
    a.     clear out all 3 TextFields
    b.     change the background color of all TextArea array elements to white
    c.     put the cursor in the start field
    8.     Document!!
    my code is:
    //packages to import
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    public class Checkerboard extends Frame implements ActionListener
         private Panel topPanel;
         private TextArea topDisplay[];
         private Panel bottomPanel;
         private TextField startField = new TextField(10);
         private TextField stopField = new TextField(10);
         private TextField stepField = new TextField(10);
         private Label startLabel = new Label ("Start");
         private Label stopLabel = new Label ("Stop");
         private Label stepLabel = new Label ("Step");
         private Button goButton;
         private Button clearButton;
         private boolean clearText;
         private boolean first;
         private int start;
         private int stop;
         private int step;
         //constructor methods
         public Checkerboard()
              //construct components and initialize beginning values
              topPanel = new Panel();
              topDisplay = new TextArea[16];
              goButton = new Button("Go");
              clearButton = new Button("Clear");
              first = true;
              bottomPanel = new Panel();
              int start = 0;
              int stop = 0;
              int step = 0;
              bottomPanel.add(startField);
              bottomPanel.add(stopField);
              bottomPanel.add(stepField);
              bottomPanel.add(startLabel);
              bottomPanel.add(stopLabel);
              bottomPanel.add(stepLabel);
              bottomPanel.add(goButton);
              goButton.addActionListener(this);
              bottomPanel.add(clearButton);
              clearButton.addActionListener(this);
              clearText = true;
              //set layouts for the Frame and Panels
              setLayout(new BorderLayout());
              topPanel.setLayout(new GridLayout(4, 4, 10, 10));
              bottomPanel.setLayout(new GridLayout(3, 3, 5, 5));
              //construct the Display
              for(int i = 0; i <= 15; i++)
                        topDisplay[i] = new TextArea(null, 3, 5, 3);
                        topDisplay.setText(String.valueOf(i+1));
                        topDisplay[i].setEditable(false);
                        topPanel.add(topDisplay[i]);
              //add components to frame
              add(topPanel, BorderLayout.NORTH);
              add(bottomPanel, BorderLayout.CENTER);
              //allow the x to close the application
              addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)
                                  System.exit(0);
                   } //end window adapter
         public static void main(String args[])
              Checkerboard f = new Checkerboard();
              f.setTitle("Checkerboard Array");
              f.setBounds(50, 100, 300, 400);
              f.setLocationRelativeTo(null);
              f.setVisible(true);
         } //end main
         public void actionPerformed(ActionEvent e)
              //test go
              String arg = e.getActionCommand();
              //go button was clicked
              if(arg.equals("Go"))
                   //convert data in TextField to int
                   int start = Integer.parseInt(startField.getText());
                   int stop = Integer.parseInt(stopField.getText());
                   int step = Integer.parseInt(stepField.getText());
                   if((start <= 1) && (start > 16))
                        JOptionPane.showMessageDialog(null, "You must enter start between 1 and 16", "Error", JOptionPane.ERROR_MESSAGE);
                        startField.setText(" ");
                        startField.requestFocus();
                   if ((stop < 1) && (stop > 16))
                        JOptionPane.showMessageDialog(null, "You must enter stop between 1 and 16", "Error", JOptionPane.ERROR_MESSAGE);
                        stopField.setText(" ");
                        stopField.requestFocus();
                   if ((step < 1) && (step > 16))
                        JOptionPane.showMessageDialog(null, "You must enter step between 1 and 16", "Error", JOptionPane.ERROR_MESSAGE);
                        stepField.setText(" ");
                        stepField.requestFocus();
                   if (start < stop)
                        JOptionPane.showMessageDialog(null, "Stop cannot be larger than start", "Error", JOptionPane.ERROR_MESSAGE);
                        startField.setText(" ");
                        stopField.setText(" ");
                        stepField.setText(" ");
                        startField.requestFocus();
                   for(int i = 0; i <=16; i++)
                   topDisplay[i].setBackground(Color.blue);
                   for(int i = start; i <= stop; step++)
                   topDisplay[i].setBackground(Color.yellow);
              } //end the if go
              //clear button was clicked
              if(arg.equals("Clear"))
                   clearText = true;
                   startField.setText("");
                   stopField.setText("");
                   stepField.setText("");
                   first = true;
                   setBackground(Color.white);
                   startField.requestFocus();
              } //end the if clear
         }//end action listener
    }//end class

    got the yellow boxes to come up but just one box.....so is there something wrong with my yellow set background because I am not seeing any more errors
    //packages to import
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    public class Checkerboard extends Frame implements ActionListener
         private Panel topPanel;
         private TextArea topDisplay[];
         private Panel bottomPanel;
         private TextField startField = new TextField(10);
         private TextField stopField = new TextField(10);
         private TextField stepField = new TextField(10);
         private Label startLabel = new Label ("Start");
         private Label stopLabel = new Label ("Stop");
         private Label stepLabel = new Label ("Step");
         private Button goButton;
         private Button clearButton;
         private boolean clearText;
         private boolean first;
         private int start;
         private int stop;
         private int step;
         //constructor methods
         public Checkerboard()
              //construct components and initialize beginning values
              topPanel = new Panel();
              topDisplay = new TextArea[16];
              goButton = new Button("Go");
              clearButton = new Button("Clear");
              first = true;
              bottomPanel = new Panel();
              int start = 0;
              int stop = 0;
              int step = 0;
              bottomPanel.add(startField);
              bottomPanel.add(stopField);
              bottomPanel.add(stepField);
              bottomPanel.add(startLabel);
              bottomPanel.add(stopLabel);
              bottomPanel.add(stepLabel);
              bottomPanel.add(goButton);
              goButton.addActionListener(this);
              bottomPanel.add(clearButton);
              clearButton.addActionListener(this);
              clearText = true;
              //set layouts for the Frame and Panels
              setLayout(new BorderLayout());
              topPanel.setLayout(new GridLayout(4, 4, 10, 10));
              bottomPanel.setLayout(new GridLayout(3, 3, 5, 5));
              //construct the Display
              for(int i = 0; i <= 15; i++)
                        topDisplay[i] = new TextArea(null, 3, 5, 3);
                        topDisplay.setText(String.valueOf(i+1));
                        topDisplay[i].setEditable(false);
                        topPanel.add(topDisplay[i]);
              //add components to frame
              add(topPanel, BorderLayout.NORTH);
              add(bottomPanel, BorderLayout.CENTER);
              //allow the x to close the application
              addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)
                                  System.exit(0);
                   } //end window adapter
              public static void main(String args[])
                        Checkerboard f = new Checkerboard();
                        f.setTitle("Checkerboard Array");
                        f.setBounds(50, 100, 300, 400);
                        f.setLocationRelativeTo(null);
                        f.setVisible(true);
                   } //end main
                   public void actionPerformed(ActionEvent e)
                        boolean done = false;
                        //test go
                        String arg = e.getActionCommand();
                        //go button was clicked
                        if(arg.equals("Go"))
                   //convert data in TextField to int
                   int start = Integer.parseInt(startField.getText());
                   int stop = Integer.parseInt(stopField.getText());
                   int step = Integer.parseInt(stepField.getText());
                   while(!done)
                        try
                             if((start <= 1) && (start > 16)) throw new NumberFormatException();
                             else done = true;
                        } //end try
                        catch (NumberFormatException f)
                             JOptionPane.showMessageDialog(null, "You must enter start between 1 and 16", "Error", JOptionPane.ERROR_MESSAGE);
                             startField.setText(" ");
                             startField.requestFocus();
                        } //end catch
                        try
                             if ((stop < 1) && (stop > 16)) throw new NumberFormatException();
                             else done = true;
                        } //end try
                        catch (NumberFormatException f)
                             JOptionPane.showMessageDialog(null, "You must enter stop between 1 and 16", "Error", JOptionPane.ERROR_MESSAGE);
                             stopField.setText(" ");
                             stopField.requestFocus();
                        } //end catch
                        try
                             if ((step < 1) && (step > 16)) throw new NumberFormatException();
                             else done = true;
                        } //end try
                        catch (NumberFormatException f)
                             JOptionPane.showMessageDialog(null, "You must enter step between 1 and 16", "Error", JOptionPane.ERROR_MESSAGE);
                             stepField.setText(" ");
                             stepField.requestFocus();
                        } //end catch
                        try
                             if (start > stop) throw new NumberFormatException();
                             else done = true;
                        } //end try
                        catch (NumberFormatException f)
                             JOptionPane.showMessageDialog(null, "Stop cannot be larger than start", "Error", JOptionPane.ERROR_MESSAGE);
                             startField.setText(" ");
                             stopField.setText(" ");
                             stepField.setText(" ");
                             startField.requestFocus();
                        } //end catch
              } //end while
                        for(int i = 0; i <=15; i++)
                        topDisplay[i].setBackground(Color.blue);
                        for(int i = start; i <= stop; step++)
                        topDisplay[i].setBackground(Color.yellow);
                   } //end the if go
                   //clear button was clicked
                   if(arg.equals("Clear"))
                        clearText = true;
                        startField.setText("");
                        stopField.setText("");
                        stepField.setText("");
                        first = true;
                        setBackground(Color.white);
                        startField.requestFocus();
                   } //end the if clear
         }//end action listener
    }//end class

  • How to ignore error and continue with next value in PL/SQL FOR loop?

    hi,
    When the DROP INDEX statement fails it have to continue with the next value in FOR loop without exiting from the loop. Can anyone tell me how to do this?
    DECLARE
    CURSOR aud_cur IS
    SELECT key_col_idx FROM audience_work where aud_ref_id between 106 and 109;
    BEGIN
    FOR aud_row IN aud_cur LOOP
    EXECUTE IMMEDIATE
    'DROP INDEX ' || aud_row.key_col_idx;
    END LOOP;
    END;
    Thanks,
    Noble

    DECLARE
      CURSOR aud_cur
      IS
      SELECT key_col_idx FROM audience_work where aud_ref_id between 106 and 109;
    BEGIN
      FOR aud_row IN aud_cur LOOP
        begin
          EXECUTE IMMEDIATE 'DROP INDEX ' || aud_row.key_col_idx;
        exception
          when others then
            if sqlcode = -01418 then
              dbms_output.put_line(' index does not exist ');
            else
              dbms_output.put_line(sqlcode);
              raise;
            end if; 
        end;
      END LOOP;
    END;
    /

  • Replace the following open/fetch/close statements with a cursor FOR loop

    Hi anyone could you please help me,
    I would like to replace the following open/fetch/close statements with a cursor FOR loop.
    Codes are:
    CREATE OR REPLACE PROCEDURE COMOES.orchid_shipment_interface IS
      -- get the com shipment header records
      CURSOR c_com_shphdr ( p_dwn_end_dt DATE ) IS
      SELECT custno client_id
           , plheadno plheadno
           , DECODE(carr_no,'FEDX',lading_no,'UPS',lading_no,carrier_pro_no) tracking_no
           , carr_no||'/'||carr_method carrier_id
           , plantid plant_id
           , carr_no
           , lading_no
           , del_custaddr ship_to_id
           , ol_type cfm_order_type
           , del_custno
           , shipterm    freight_terms
           , del_custattn attn_line
           , custaddr
        FROM com_plhead@com_pricing.world
       WHERE status = '9'
         AND (mod_dat) > p_dwn_end_dt;
      -- get the com shipment address records
      CURSOR c_com_shpadr (p_custaddr VARCHAR2) IS
      SELECT name1 addr_name
           , street1 addr_line1
           , street2 addr_line2
           , city city
           , state state_cd
           , zip zip
           , country country_cd
           , phone work_phone
           , email email1
        FROM com_address@com_pricing.world
       WHERE addr_id = p_custaddr;
      -- get the com shipment detail records
      CURSOR c_com_shpdtl ( p_plheadno NUMBER) IS
      SELECT pll.plheadno pllheadno
           , pll.pllineno ord_line_no
           , pll.ol_no erp_line_no
           , pll.ol_segno
           , pll.fg_id sku
           , pll.qty_shipped ship_qty
           , pll.ordno erp_ord_no
           FROM com_plline@com_pricing.world pll
       WHERE pll.plheadno = p_plheadno
         AND NOT EXISTS (SELECT '1'
                           FROM com_pkg_int_interface@com_pricing.world  cpi
                          WHERE pll.ordno = cpi.ordno
                            AND pll.ol_no = cpi.ol_no);
      -- type declaration
      -- type declaration of com table.
      TYPE t_com_shphdr IS TABLE OF c_com_shphdr%ROWTYPE INDEX BY BINARY_INTEGER;
      TYPE t_orchid_shphdr IS TABLE OF orchid_shipment_hdr_intf%ROWTYPE INDEX BY BINARY_INTEGER;
      TYPE t_com_shpadr IS TABLE OF c_com_shpadr%ROWTYPE INDEX BY BINARY_INTEGER;
      TYPE t_orchid_shpadr IS TABLE OF orchid_shipment_address_intf%ROWTYPE INDEX BY BINARY_INTEGER;
      TYPE t_com_shpdtl IS TABLE OF c_com_shpdtl%ROWTYPE INDEX BY BINARY_INTEGER;
      TYPE t_orchid_shpdtl IS TABLE OF orchid_shipment_dtl_intf%ROWTYPE INDEX BY BINARY_INTEGER;
      lv_company_code       com_customer.business_unit%TYPE;
      lv_erp_ord_no         com_plline.ordno%TYPE;
      lv_actual_ship_date   com_plline.confirm_date%TYPE;
      lv_po_no              com_oline.po_no%TYPE;
      lv_ord_date           com_oline.entrydate%TYPE;
      lv_hdr_batch_ctrl_no  download_batch_info.batch_ctrl_no%TYPE;
      lv_adr_batch_ctrl_no  download_batch_info.batch_ctrl_no%TYPE;
      lv_dtl_batch_ctrl_no  download_batch_info.batch_ctrl_no%TYPE;
      lv_sku_desc           com_salesitem.title%TYPE;
      lv_ord_qty            com_oldelseg.qty%TYPE;
      lr_com_shphdr    t_com_shphdr;
      lr_orchid_shphdr t_orchid_shphdr;
      lr_com_shpadr    t_com_shpadr;
      lr_orchid_shpadr t_orchid_shpadr;
      lr_com_shpdtl    t_com_shpdtl;
      lr_orchid_shpdtl t_orchid_shpdtl;
      -- variable declaration
      ln_shphdr_seq    NUMBER(10):= 0;
      ln_shpadr_seg    NUMBER(10):= 0;
      ln_shpdtl_seq    NUMBER(10):= 0;
      cnt              NUMBER(10):= 0;
      cnt1             NUMBER(10):= 0;
      ld_hdr_dwn_end_dt           download_batch_info.download_end_tstamp%TYPE;
      lc_hdr_dwn_status           download_batch_info.dwn_status%TYPE;
      ld_hdr_download_end_tstamp  DATE;
      ln_hdr_running_seq          NUMBER(10) := 0;
      ld_adr_dwn_end_dt           download_batch_info.download_end_tstamp%TYPE;
      lc_adr_dwn_status           download_batch_info.dwn_status%TYPE;
      ld_adr_download_end_tstamp  DATE;
      ln_adr_running_seg          NUMBER(10) := 0;
      ld_dtl_dwn_end_dt           download_batch_info.download_end_tstamp%TYPE;
      lc_dtl_dwn_status           download_batch_info.dwn_status%TYPE;
      ld_dtl_download_end_tstamp  DATE;
      ln_dtl_running_seq          NUMBER(10) := 0;
    BEGIN
      -- get the batch control number details from batch information table for shipment header
      BEGIN
        SELECT batch_ctrl_no
             , NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
             , dwn_status
          INTO lv_hdr_batch_ctrl_no
             , ld_hdr_dwn_end_dt
             , lc_hdr_dwn_status
          FROM comoes.download_batch_info
         WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF';
      EXCEPTION
        WHEN NO_DATA_FOUND THEN
          DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!');
          RAISE;
        WHEN TOO_MANY_ROWS THEN
          DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!');
          RAISE;
        WHEN OTHERS THEN
          DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!'||SQLERRM);
          RAISE;
      END;
      -- get the batch control number details from batch information table for shipment address
      BEGIN
        SELECT batch_ctrl_no
             , NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
             , dwn_status
          INTO lv_adr_batch_ctrl_no
             , ld_adr_dwn_end_dt
             , lc_adr_dwn_status
          FROM comoes.download_batch_info
         WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF';
      EXCEPTION
        WHEN NO_DATA_FOUND THEN
          DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!');
          RAISE;
        WHEN TOO_MANY_ROWS THEN
          DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!');
          RAISE;
        WHEN OTHERS THEN
          DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_ADDRESS_INTF in Download Batch Info table...!!!'||SQLERRM);
          RAISE;
      END;
      -- get the batch control number details from batch information table for shipment details
      BEGIN
        SELECT batch_ctrl_no
             , NVL(download_end_tstamp,TO_DATE('01/01/1980','MM/DD/YYYY'))
             , dwn_status
          INTO lv_dtl_batch_ctrl_no
             , ld_dtl_dwn_end_dt
             , lc_dtl_dwn_status
          FROM download_batch_info
         WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF';
      EXCEPTION
        WHEN NO_DATA_FOUND THEN
          DBMS_OUTPUT.PUT_LINE (' No Data Found for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!');
          RAISE;
        WHEN TOO_MANY_ROWS THEN
          DBMS_OUTPUT.PUT_LINE (' Too Many Rows found for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!');
          RAISE;
        WHEN OTHERS THEN
          DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_DTL_INTF in Download Batch Info table...!!!'||SQLERRM);
          RAISE;
      END;
      -- if previous run is not sucess then do nothing and return.
      OPEN c_com_shphdr ( ld_hdr_dwn_end_dt ) ;
      LOOP
        -- delete the collection for every cycle
        lr_com_shphdr.DELETE;
        lr_orchid_shphdr.DELETE;
        lr_com_shpadr.DELETE;
        lr_orchid_shpadr.DELETE;
        lr_com_shpdtl.DELETE;
        lr_orchid_shpdtl.DELETE;
        -- fetch the order header records to collection
        FETCH c_com_shphdr BULK COLLECT INTO lr_com_shphdr LIMIT 500;
        -- where there is no record in the collection the exit from the loop
        EXIT WHEN lr_com_shphdr.COUNT = 0;
        -- build your logic there to populate the data into order header collection.
          FOR i IN 1..lr_com_shphdr.COUNT
          LOOP
            -- accumulate header running sequence number
            ln_hdr_running_seq := ln_hdr_running_seq + 1;
            ln_shphdr_seq      := ln_hdr_running_seq;
             -- Get the business unit for the customer from com_customer
            BEGIN
              SELECT business_unit
                INTO lv_company_code
                FROM com_customer@com_pricing.world
               WHERE custno = lr_com_shphdr(i).del_custno;
            EXCEPTION
            WHEN OTHERS THEN
              lv_company_code := NULL;
            END;
            -- Get the ordno, confirm_date from COM_PLLINE
            BEGIN
            SELECT ordno
                 , confirm_date
              INTO lv_erp_ord_no
                 , lv_actual_ship_date
              FROM com_plline@com_pricing.world cpl
             WHERE cpl.plheadno = lr_com_shphdr(i).plheadno
               AND ROWNUM = 1;
            EXCEPTION
            WHEN OTHERS THEN
              lv_erp_ord_no       := NULL;
              lv_actual_ship_date := NULL;
            END;
            -- Get the po_no, Entry_date from COM_OLINE
            BEGIN
              SELECT po_no
                   , entrydate
                INTO lv_po_no
                   , lv_ord_date
                FROM com_oline@com_pricing.world col
               WHERE col.ordno = lv_erp_ord_no
                 AND ROWNUM = 1;
            EXCEPTION
            WHEN OTHERS THEN
              lv_po_no    := NULL;
              lv_ord_date := NULL;
            END;
            -- To assign the Bol Number from Lading Number
            IF lr_com_shphdr(i).carr_no NOT IN ('FEDX','UPS') THEN
               lr_orchid_shphdr(i).bol_no     := lr_com_shphdr(i).lading_no;
            ELSE
               lr_orchid_shphdr(i).bol_no     := NULL;
            END IF;
            -- For each order header get the Shipment Delivery Adderss
            OPEN c_com_shpadr ( lr_com_shphdr(i).custaddr);
            FETCH c_com_shpadr BULK COLLECT INTO lr_com_shpadr;
            -- where there is no record in the collection the exit from the loop
            EXIT WHEN lr_com_shpadr.COUNT = 0;
            -- biuld your logic here to populate the del address collection.
              FOR j IN 1..lr_com_shpadr.COUNT
              LOOP
                -- accumulate the loop count into temp variable, so that will through tell each set of order header.
                cnt := cnt + 1;
                -- accumolate the header running sequence number.
                ln_adr_running_seg := ln_adr_running_seg + 1;
                ln_shpadr_seg := ln_adr_running_seg;
                -- move the order address data into collection.
                lr_orchid_shpadr(cnt).client_id       := lr_com_shphdr(i).del_custno;
                lr_orchid_shpadr(cnt).ord_no          := lr_com_shphdr(i).plheadno;
                lr_orchid_shpadr(cnt).tracking_no     := lr_com_shphdr(i).tracking_no;
                lr_orchid_shpadr(cnt).addr_name       := lr_com_shpadr(j).addr_name;
                lr_orchid_shpadr(cnt).attn_line       := lr_com_shphdr(i).attn_line;
                lr_orchid_shpadr(cnt).addr_line1      := lr_com_shpadr(j).addr_line1;
                lr_orchid_shpadr(cnt).addr_line2      := lr_com_shpadr(j).addr_line2;
                lr_orchid_shpadr(cnt).addr_line3      := NULL;
                lr_orchid_shpadr(cnt).addr_line4      := NULL;
                lr_orchid_shpadr(cnt).addr_line5      := NULL;
                lr_orchid_shpadr(cnt).city            := lr_com_shpadr(j).city;
                lr_orchid_shpadr(cnt).state_cd        := lr_com_shpadr(j).state_cd;
                lr_orchid_shpadr(cnt).zip             := lr_com_shpadr(j).zip;
                lr_orchid_shpadr(cnt).zip_ext         := NULL;
                lr_orchid_shpadr(cnt).country_cd      := lr_com_shpadr(j).country_cd;
                lr_orchid_shpadr(cnt).tax_geo_cd      := NULL;
                lr_orchid_shpadr(cnt).work_phone      := lr_com_shpadr(j).work_phone;
                lr_orchid_shpadr(cnt).email1          := lr_com_shpadr(j).email1;
                lr_orchid_shpadr(cnt).cre_dat         := SYSDATE;
                lr_orchid_shpadr(cnt).cre_usr         := USER;
                lr_orchid_shpadr(cnt).batch_ctrl_no   := lv_adr_batch_ctrl_no;
              END LOOP;
            CLOSE c_com_shpadr;
            -- For each order header get the order detail/delivery segment data
            OPEN c_com_shpdtl ( lr_com_shphdr(i).plheadno );
            FETCH c_com_shpdtl BULK COLLECT INTO lr_com_shpdtl;
            -- where there is no record in the collection the exit from the loop
            EXIT WHEN lr_com_shpdtl.COUNT = 0;
            -- build your logic here to populate the order detail collection
              FOR k IN 1..lr_com_shpdtl.COUNT
              LOOP
                -- accumulate the loop count into a temp variable, so that will through till each set of Order Header.
                cnt1 := cnt1 + 1;
                -- accumulate header running sequence number
                ln_dtl_running_seq := ln_dtl_running_seq + 1;
                ln_shpdtl_seq := ln_dtl_running_seq;
                -- Get Quantity for the delvery from delevery segment table.
                BEGIN
                  SELECT NVL(Qty,0)
                    INTO lv_ord_qty
                    FROM com_oldelseg@com_pricing.world cds
                   WHERE cds.ordno = lr_com_shpdtl(k).erp_ord_no
                     AND cds.ol_no = lr_com_shpdtl(k).erp_line_no
                     AND cds.ol_segno = lr_com_shpdtl(k).ol_segno;
                EXCEPTION
                  WHEN OTHERS THEN
                    lv_ord_qty := NULL;
                END;
                -- Get Title for the salesitem from the salesitem table.
                BEGIN
                  SELECT Title
                    INTO lv_sku_desc
                    FROM com_salesitem@com_pricing.world cs
                   WHERE cs.fg_id = lr_com_shpdtl(k).sku;
                EXCEPTION
                  WHEN OTHERS THEN
                    lv_sku_desc := NULL;
                END;
                -- move the Order detail data into collection
                lr_orchid_shpdtl(cnt1).client_id         := lr_com_shphdr(i).client_id;
                lr_orchid_shpdtl(cnt1).ord_no            := lr_com_shphdr(i).plheadno;
                lr_orchid_shpdtl(cnt1).ord_line_no       := lr_com_shpdtl(k).ord_line_no;
                lr_orchid_shpdtl(cnt1).erp_line_no       := lr_com_shpdtl(k).erp_line_no;
                lr_orchid_shpdtl(cnt1).sku               := lr_com_shpdtl(k).sku;
                lr_orchid_shpdtl(cnt1).tracking_no       := lr_com_shphdr(i).tracking_no;
                lr_orchid_shpdtl(cnt1).container_no      := NULL;
                lr_orchid_shpdtl(cnt1).ord_qty           := lv_ord_qty;
                lr_orchid_shpdtl(cnt1).ship_qty          := lr_com_shpdtl(k).ship_qty;
                lr_orchid_shpdtl(cnt1).price_point       := NULL;
                lr_orchid_shpdtl(cnt1).pick_invoice_no   := NULL;
                lr_orchid_shpdtl(cnt1).cancel_qty        := NULL;
                lr_orchid_shpdtl(cnt1).bldg_id           := NULL;                              --lr_com_shpdtl(k).bldg_id;
                lr_orchid_shpdtl(cnt1).sku_company       := NULL;                              --lr_com_shpdtl(k).sku_company;
                lr_orchid_shpdtl(cnt1).sku_desc          := lv_sku_desc;
                lr_orchid_shpdtl(cnt1).icc_cd1           := NULL;                              --lr_com_shpdtl(k).icc_cd1;
                lr_orchid_shpdtl(cnt1).erp_ord_no        := lr_com_shpdtl(k).erp_ord_no;
                lr_orchid_shpdtl(cnt1).cre_dat           := SYSDATE;
                lr_orchid_shpdtl(cnt1).cre_usr           := USER;
                lr_orchid_shpdtl(cnt1).batch_ctrl_no     := lv_dtl_batch_ctrl_no;
              END LOOP;
            CLOSE c_com_shpdtl;
            -- build the logic to populate Order Header
            lr_orchid_shphdr(i).client_id              := lr_com_shphdr(i).client_id;
            lr_orchid_shphdr(i).ord_no                 := lr_com_shphdr(i).plheadno;
            lr_orchid_shphdr(i).tracking_no            := lr_com_shphdr(i).tracking_no;
            lr_orchid_shphdr(i).container_no           := NULL;                            -- container number is not maintained in COM
            lr_orchid_shphdr(i).carrier_id             := lr_com_shphdr(i).carrier_id;
            lr_orchid_shphdr(i).plant_id               := lr_com_shphdr(i).plant_id;
            lr_orchid_shphdr(i).erp_ord_no             := lv_erp_ord_no;
            lr_orchid_shphdr(i).erp_ord_no2            := NULL;
            lr_orchid_shphdr(i).po_no                  := lv_po_no;
            lr_orchid_shphdr(i).ship_to_id             := lr_com_shphdr(i).ship_to_id;
            lr_orchid_shphdr(i).ship_to_addr_id        := lr_com_shphdr(i).custaddr;
            lr_orchid_shphdr(i).scac                   := NULL;                             --lr_com_shphdr(i).scac;
            lr_orchid_shphdr(i).actual_ship_date       := lv_actual_ship_date;
            lr_orchid_shphdr(i).cfm_order_type         := lr_com_shphdr(i).cfm_order_type;
            lr_orchid_shphdr(i).company_code           := lv_company_code;
            lr_orchid_shphdr(i).no_of_order_lines      := NULL;                             --lr_com_shphdr(i).no_of_order_lines;
            lr_orchid_shphdr(i).pick_invoice_no        := NULL;
            lr_orchid_shphdr(i).ord_date               := lv_ord_date;
            lr_orchid_shphdr(i).orig_tender_date       := NULL;
            lr_orchid_shphdr(i).orig_delv_date         := NULL;
            lr_orchid_shphdr(i).delivery_flag          := NULL;
            lr_orchid_shphdr(i).delv_date_from         := NULL;
            lr_orchid_shphdr(i).delv_date_to           := NULL;
            lr_orchid_shphdr(i).orig_carr_cd           := NULL;
            lr_orchid_shphdr(i).routing_comment        := NULL;
            lr_orchid_shphdr(i).segment_type           := NULL;
            lr_orchid_shphdr(i).back_order_flag        := NULL;
            lr_orchid_shphdr(i).addr_override_flag     := NULL;
            lr_orchid_shphdr(i).fmx_assigned_carr      := NULL;
            lr_orchid_shphdr(i).fmx_assigned_ship_date := NULL;
            lr_orchid_shphdr(i).fmx_assigned_delv_date := NULL;
            lr_orchid_shphdr(i).freight_terms          := lr_com_shphdr(i).freight_terms;
            lr_orchid_shphdr(i).fmx_load_id            := NULL;
            lr_orchid_shphdr(i).asn_type               := NULL;
            lr_orchid_shphdr(i).icc_cd1                := NULL;                             --lr_com_shphdr(i).icc_cd1;
            lr_orchid_shphdr(i).trans_type             := NULL;
            lr_orchid_shphdr(i).ref_no1                := NULL;
            lr_orchid_shphdr(i).ref_no2                := NULL;
            lr_orchid_shphdr(i).ref_no3                := NULL;
            lr_orchid_shphdr(i).ref_no4                := NULL;
            lr_orchid_shphdr(i).cre_dat                := SYSDATE;
            lr_orchid_shphdr(i).cre_usr                := USER;
            lr_orchid_shphdr(i).batch_ctrl_no          := lv_hdr_batch_ctrl_no;
            -- logic to get total boxes and weight.
            BEGIN
              SELECT SUM(no_cartons), SUM(weight)
                INTO lr_orchid_shphdr(i).total_boxes
                   , lr_orchid_shphdr(i).weight
                FROM com_plline@com_pricing.world pll
               WHERE pll.plheadno = lr_com_shphdr(i).plheadno;
            EXCEPTION
             WHEN OTHERS THEN
                lr_orchid_shphdr(i).total_boxes := NULL;
                lr_orchid_shphdr(i).weight      := NULL;
            END;
          END LOOP;
        -- initialize the variables for next loop cycle.
        cnt := 0;
        cnt1 := 0;
        -- populate the shipment header interface table.
        FOR x IN 1..lr_orchid_shphdr.COUNT
        LOOP
          ld_hdr_download_end_tstamp := lr_orchid_shphdr(x).cre_dat;
          INSERT INTO orchid_shipment_hdr_intf
                    (record_qualifier
                    ,client_id
                    ,ord_no
                    ,tracking_no
                    ,container_no
                    ,bol_no
                    ,carrier_id
                    ,plant_id
                    ,erp_ord_no
                    ,erp_ord_no2
                    ,po_no
                    ,ship_to_id
                    ,ship_to_addr_id
                    ,scac
                    ,actual_ship_date
                    ,cfm_order_type
                    ,company_code
                    ,no_of_order_lines
                    ,pick_invoice_no
                    ,total_boxes
                    ,weight
                    ,ord_date
                    ,orig_tender_date
                    ,orig_delv_date
                    ,delivery_flag
                    ,delv_date_from
                    ,delv_date_to
                    ,orig_carr_cd
                    ,routing_comment
                    ,segment_type
                    ,back_order_flag
                    ,addr_override_flag
                    ,fmx_assigned_carr
                    ,fmx_assigned_ship_date
                    ,fmx_assigned_delv_date
                    ,freight_terms
                    ,fmx_load_id
                    ,asn_type
                    ,upl_status
                    ,icc_cd1
                    ,trans_type
                    ,ref_no1
                    ,ref_no2
                    ,ref_no3
                    ,ref_no4
                    ,cre_dat
                    ,cre_usr
                    ,batch_ctrl_no)
            VALUES
                    ( 10
                    ,lr_orchid_shphdr(x).client_id
                    ,lr_orchid_shphdr(x).ord_no
                    ,lr_orchid_shphdr(x).tracking_no
                    ,lr_orchid_shphdr(x).container_no
                    ,lr_orchid_shphdr(x).bol_no
                    ,lr_orchid_shphdr(x).carrier_id
                    ,lr_orchid_shphdr(x).plant_id
                    ,lr_orchid_shphdr(x).erp_ord_no
                    ,lr_orchid_shphdr(x).erp_ord_no2
                    ,lr_orchid_shphdr(x).po_no
                    ,lr_orchid_shphdr(x).ship_to_id
                    ,lr_orchid_shphdr(x).ship_to_addr_id
                    ,lr_orchid_shphdr(x).scac
                    ,lr_orchid_shphdr(x).actual_ship_date
                    ,lr_orchid_shphdr(x).cfm_order_type
                    ,lr_orchid_shphdr(x).company_code
                    ,lr_orchid_shphdr(x).no_of_order_lines
                    ,lr_orchid_shphdr(x).pick_invoice_no
                    ,lr_orchid_shphdr(x).total_boxes
                    ,lr_orchid_shphdr(x).weight
                    ,lr_orchid_shphdr(x).ord_date
                    ,lr_orchid_shphdr(x).orig_tender_date
                    ,lr_orchid_shphdr(x).orig_delv_date
                    ,lr_orchid_shphdr(x).delivery_flag
                    ,lr_orchid_shphdr(x).delv_date_from
                    ,lr_orchid_shphdr(x).delv_date_to
                    ,lr_orchid_shphdr(x).orig_carr_cd
                    ,lr_orchid_shphdr(x).routing_comment
                    ,lr_orchid_shphdr(x).segment_type
                    ,lr_orchid_shphdr(x).back_order_flag
                    ,lr_orchid_shphdr(x).addr_override_flag
                    ,lr_orchid_shphdr(x).fmx_assigned_carr
                    ,lr_orchid_shphdr(x).fmx_assigned_ship_date
                    ,lr_orchid_shphdr(x).fmx_assigned_delv_date
                    ,lr_orchid_shphdr(x).freight_terms
                    ,lr_orchid_shphdr(x).fmx_load_id
                    ,lr_orchid_shphdr(x).asn_type
                    ,00
                    ,lr_orchid_shphdr(x).icc_cd1
                    ,lr_orchid_shphdr(x).trans_type
                    ,lr_orchid_shphdr(x).ref_no1
                    ,lr_orchid_shphdr(x).ref_no2
                    ,lr_orchid_shphdr(x).ref_no3
                    ,lr_orchid_shphdr(x).ref_no4
                    ,lr_orchid_shphdr(x).cre_dat
                    ,lr_orchid_shphdr(x).cre_usr
                    ,lr_orchid_shphdr(x).batch_ctrl_no);
        END LOOP;
        -- populate the shipment address interface table.
        FOR y IN 1..lr_orchid_shpadr.COUNT
        LOOP
          ld_adr_download_end_tstamp := lr_orchid_shpadr(y).cre_dat;
          INSERT INTO orchid_shipment_address_intf
                      ( record_qualifier
                      , client_id
                      , ord_no
                      , tracking_no
                      , addr_name
                      , attn_line
                      , addr_line1
                      , addr_line2
                      , addr_line3
                      , addr_line4
                      , addr_line5
                      , city
                      , state_cd
                      , zip
                      , zip_ext
                      , country_cd
                      , tax_geo_cd
                      , work_phone
                      , email1
                      , cre_dat
                      , cre_usr
                      , batch_ctrl_no)
               VALUES ( 14
                      , lr_orchid_shpadr(y).client_id
                      , lr_orchid_shpadr(y).ord_no
                      , lr_orchid_shpadr(y).tracking_no
                      , lr_orchid_shpadr(y).addr_name
                      , lr_orchid_shpadr(y).attn_line
                      , lr_orchid_shpadr(y).addr_line1
                      , lr_orchid_shpadr(y).addr_line2
                      , lr_orchid_shpadr(y).addr_line3
                      , lr_orchid_shpadr(y).addr_line4
                      , lr_orchid_shpadr(y).addr_line5
                      , lr_orchid_shpadr(y).city
                      , lr_orchid_shpadr(y).state_cd
                      , lr_orchid_shpadr(y).zip
                      , lr_orchid_shpadr(y).zip_ext
                      , lr_orchid_shpadr(y).country_cd
                      , lr_orchid_shpadr(y).tax_geo_cd
                      , lr_orchid_shpadr(y).work_phone
                      , lr_orchid_shpadr(y).email1
                      , lr_orchid_shpadr(y).cre_dat
                      , lr_orchid_shpadr(y).cre_usr
                      , lr_orchid_shpadr(y).batch_ctrl_no);
        END LOOP;
        -- populate the shipment detail interface table.
        FOR z IN 1..lr_orchid_shpdtl.COUNT
        LOOP
          ld_dtl_download_end_tstamp := lr_orchid_shpdtl(z).cre_dat;
          INSERT INTO orchid_shipment_dtl_intf
                      ( record_qualifier
                      , client_id
                      , ord_no
                      , ord_line_no
                      , erp_line_no
                      , sku
                      , tracking_no
                      , container_no
                      , ord_qty
                      , ship_qty
                      , price_point
                      , pick_invoice_no
                      , cancel_qty
                      , bldg_id
                      , sku_company
                      , sku_desc
                      , icc_cd1
                      , erp_ord_no
                      , cre_dat
                      , cre_usr
                      , batch_ctrl_no)
               VALUES ( 20
                      , lr_orchid_shpdtl(z).client_id
                      , lr_orchid_shpdtl(z).ord_no
                      , lr_orchid_shpdtl(z).ord_line_no
                      , lr_orchid_shpdtl(z).erp_line_no
                      , lr_orchid_shpdtl(z).sku
                      , lr_orchid_shpdtl(z).tracking_no
                      , lr_orchid_shpdtl(z).container_no
                      , lr_orchid_shpdtl(z).ord_qty
                      , lr_orchid_shpdtl(z).ship_qty
                      , lr_orchid_shpdtl(z).price_point
                      , lr_orchid_shpdtl(z).pick_invoice_no
                      , lr_orchid_shpdtl(z).cancel_qty
                      , lr_orchid_shpdtl(z).bldg_id
                      , lr_orchid_shpdtl(z).sku_company
                      , lr_orchid_shpdtl(z).sku_desc
                      , lr_orchid_shpdtl(z).icc_cd1
                      , lr_orchid_shpdtl(z).erp_ord_no
                      , lr_orchid_shpdtl(z).cre_dat
                      , lr_orchid_shpdtl(z).cre_usr
                      , lr_orchid_shpdtl(z).batch_ctrl_no);
        END LOOP;
        COMMIT;
      END LOOP;
      CLOSE c_com_shphdr;
      -- set the status to success
      UPDATE comoes.download_batch_info
         SET batch_ctrl_no = orchid_plhead_btch_ctrl_seq.NEXTVAL
           , dwn_status = '90'
           , download_end_tstamp = NVL(ld_hdr_download_end_tstamp,SYSDATE)
       WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF'
         AND batch_ctrl_no = lv_hdr_batch_ctrl_no;
      UPDATE comoes.download_batch_info
         SET batch_ctrl_no = orchid_address_btch_ctrl_seq.NEXTVAL
           , dwn_status = '90'
           , download_end_tstamp = NVL(ld_hdr_download_end_tstamp,SYSDATE)
       WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF'
         AND batch_ctrl_no = lv_adr_batch_ctrl_no;
      UPDATE comoes.download_batch_info
         SET batch_ctrl_no = orchid_plline_btch_ctrl_seq.NEXTVAL
           , dwn_status = '90'
           , download_end_tstamp = NVL(ld_dtl_download_end_tstamp,SYSDATE)
       WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF'
         AND batch_ctrl_no = lv_dtl_batch_ctrl_no;
      -- Update the download status to success in the interface table.
      -- Shipment Header
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN
        -- load is not sucess then set the status to fail
        UPDATE comoes.download_batch_info
           SET dwn_status = '99'
         WHERE download_id = 'ORCHID_SHIPMENT_HDR_INTF'
           AND batch_ctrl_no = lv_hdr_batch_ctrl_no;
        UPDATE comoes.download_batch_info
           SET dwn_status = '99'
         WHERE download_id = 'ORCHID_SHIPMENT_ADDRESS_INTF'
           AND batch_ctrl_no = lv_adr_batch_ctrl_no;
        UPDATE comoes.download_batch_info
           SET dwn_status = '99'
         WHERE download_id = 'ORCHID_SHIPMENT_DTL_INTF'
           AND batch_ctrl_no = lv_dtl_batch_ctrl_no;
        COMMIT;
        DBMS_OUTPUT.PUT_LINE('Following error occured while executing ORCHID_SHIPMENT_INTF procedure...!!!'||SQLERRM);
        RAISE;
    END orchid_shipment_interface;Edited by: BluShadow on 03-Aug-2011 13:28
    added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                &nb

    Please read the Forum FAQ on how to ask a question, particularly how to format code
    SQL and PL/SQL FAQ
    SQL and PL/SQL FAQ
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE (' Following error occured while getting batch control number for ORCHID_SHIPMENT_HDR_INTF in Download Batch Info table...!!!'||SQLERRM);
    RAISE;http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html

  • Re: Raising Exceptions Vs returning erro[Ref:C809787]

    Hi Steve !
    Probably the following explanation might help in resolving the issue raised by
    you:
    At a more abstract level, there is only one thing, i.e. the EVENT. According to
    it's definition, an event is a relatively infrequent occurrence in one portion (lets
    call it event raiser) of the application, which some other portion (or portions,
    lets call them event handlers) (of the same application) are interested to respond
    to it. Now there are two scenarios:
    (A) Event raiser and Event handler(s) are being executed under different threads
    of control (Asynchronous) and
    (B) Event raiser and Event Handler(s) are being executed under same thread of
    control (Synchronous).
    So, Exception Handling belongs to scenario B where the method raising the
    exception (Event Raiser or exception raiser) and the method handling it (Event
    Handler or exception block) are under the same thread of control. More ever it has
    to be insured that at a time only one handler (first the inner most one) receives
    the message.
    Fort&eacute; provides a generic Event handling mechanism (Post Event and Event Loop) to
    handle the scenario A (which is the more generic one). But it also provides a
    specialized Event Handling mechanism (Raise Exception and Exception block) to
    efficiently handle the relatively simple scenario B. Why I am saying that the later
    is efficient because it won't be needing to register the event queue address of the
    interested task (after all there is only one task involved) and put the event
    message in queue.
    Finally let me mentioned that it is just my view based on the understanding I
    have and it may not be true. Only a person from fort&eacute; can confirm it. I will really
    appreciate if somebody correct and or refine it.
    Wish a Very Very Happy New Year to all Fort&eacute; Users
    Regard,
    Kailash.
    [email protected] wrote:
    I would agree with Eric entirely. Exceptions seem to me to be a much more
    complete solution to the problem of error handling. A little bit of effort up
    front in making clear the strategy for exception handling and specifying the
    exceptions that can be raised by a class\method will provide an excellent method
    for error handling.
    In the case of ensuring exceptions are always handled, a top level handler for
    GenericException will usually do the job, allowing you to write error
    information out to logs, screen, etc, and then shut down gracefully.
    The only issue I would raise with exceptions is that they are not propagated
    outside an asynchronous task. If an exception is not handled within an
    asynchronous, it will not propagate to the task that started that asynchronous
    task. Forte provides return and exception events when starting asynchronous
    tasks to cope with this, but it seems a shame to have one method of dealing with
    errors (exceptions) for synchronous behaviour, and another (events) for
    asynchronous behaviour.
    Steve Elvin
    Systems Developer
    Frontline Ltd.
    UK
    Mark,
    The problem with return codes is that there is an underlying assumption
    that the receiver will always catch and interpret that error code. This
    may or may not be good thing, depending on how you architect your
    application. If, on the other hand, you want to ensure that an error is
    always handled, if not by the receiver then by the Forte, Exceptions are
    the way to go. To extend this mechanism further, I would subclass
    GenericException and created my own error code attribute on that
    subclass. That way the receiver has the choice of interpreting the
    exception based on that error code, and wrapping it in a
    MessageDialog/window or do the usual 'errormgr.showerrors()'.
    Exceptions seem a more flexible approach to me. That is, if you can live
    with the fact that by using it, you're violating the 'exceptions for
    behavioral anomalies' software engineering principle !
    Best wishes.
    Eric Pereira
    Forte Consultant
    ----Original Message Follows----
    From: "Kallambella, Ajith" <[email protected]>
    To: "'Mark Sundsten'" <[email protected]>, [email protected]
    Cc: [email protected]
    Subject: RE: Raising Exceptions Vs returning error codes
    Date: Wed, 30 Dec 1998 08:52:39 -0500
    Reply-To: "Kallambella, Ajith" <[email protected]>
    Mark,
    Identifying conditions where you would rather use an exception
    to an error_code ( and vice-versa ) normally depends on
    your application design. Usually exceptions
    are used to handle behavioral anomalies which are
    not expected during the normal course of execution of
    the program, and which would affect the continuity of
    your algorithm if ignored. Examples would be a fatal
    error, a semantically invalid( but syntactically-valid
    token ) etc.
    Error_codes and return status's can be used to handle
    anticipated and recoverable errors. Example would
    be presentation layer validations. In any normal
    UI system, the user is expected to make errors and it
    would be annoying to throw an exception( and to handle
    it ), every time user enters wrong data. A well
    modeled client layer should not only handle
    data-validation errors , but should be smart enough
    to encourage users to input correct or
    "near-correct" data. Examples could be
    making use of look-up windows etc. Interestingly,
    Express uses exceptions to handle data-validations.
    As you see, exceptions fit well into your processing
    logic where severity of damage caused by an error
    is more. Where as error_codes fit well into presentation
    logic( and some not-so-critical processing logic ) where
    errors are usually recoverable and normal path of
    execution can be easily restored.
    Hope this helps. I would be very interested to hear
    what others have to say.
    Ajith Kallambella. M
    Forte Systems Engineer,
    International Business Corporation.
    -----Original Message-----
    From: Mark Sundsten [mailto:[email protected]]
    Sent: Tuesday, December 29, 1998 2:10 PM
    To: [email protected]
    Cc: [email protected]
    Subject: Raising Exceptions vs returning error codes
    When dealing with error handling, I find myself struggling with the
    choice
    of
    raising exceptions (and handling them) from the caller
    vs returning an error code of somekind.
    When would you want to use one over the other?
    Should you always use exception handling?
    Any discussion would be appreciated.
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    Get Your Private, Free Email at http://www.hotmail.com
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>-
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Hi Steve !
    Probably the following explanation might help in resolving the issue raised by
    you:
    At a more abstract level, there is only one thing, i.e. the EVENT. According to
    it's definition, an event is a relatively infrequent occurrence in one portion (lets
    call it event raiser) of the application, which some other portion (or portions,
    lets call them event handlers) (of the same application) are interested to respond
    to it. Now there are two scenarios:
    (A) Event raiser and Event handler(s) are being executed under different threads
    of control (Asynchronous) and
    (B) Event raiser and Event Handler(s) are being executed under same thread of
    control (Synchronous).
    So, Exception Handling belongs to scenario B where the method raising the
    exception (Event Raiser or exception raiser) and the method handling it (Event
    Handler or exception block) are under the same thread of control. More ever it has
    to be insured that at a time only one handler (first the inner most one) receives
    the message.
    Fort&eacute; provides a generic Event handling mechanism (Post Event and Event Loop) to
    handle the scenario A (which is the more generic one). But it also provides a
    specialized Event Handling mechanism (Raise Exception and Exception block) to
    efficiently handle the relatively simple scenario B. Why I am saying that the later
    is efficient because it won't be needing to register the event queue address of the
    interested task (after all there is only one task involved) and put the event
    message in queue.
    Finally let me mentioned that it is just my view based on the understanding I
    have and it may not be true. Only a person from fort&eacute; can confirm it. I will really
    appreciate if somebody correct and or refine it.
    Wish a Very Very Happy New Year to all Fort&eacute; Users
    Regard,
    Kailash.
    [email protected] wrote:
    I would agree with Eric entirely. Exceptions seem to me to be a much more
    complete solution to the problem of error handling. A little bit of effort up
    front in making clear the strategy for exception handling and specifying the
    exceptions that can be raised by a class\method will provide an excellent method
    for error handling.
    In the case of ensuring exceptions are always handled, a top level handler for
    GenericException will usually do the job, allowing you to write error
    information out to logs, screen, etc, and then shut down gracefully.
    The only issue I would raise with exceptions is that they are not propagated
    outside an asynchronous task. If an exception is not handled within an
    asynchronous, it will not propagate to the task that started that asynchronous
    task. Forte provides return and exception events when starting asynchronous
    tasks to cope with this, but it seems a shame to have one method of dealing with
    errors (exceptions) for synchronous behaviour, and another (events) for
    asynchronous behaviour.
    Steve Elvin
    Systems Developer
    Frontline Ltd.
    UK
    Mark,
    The problem with return codes is that there is an underlying assumption
    that the receiver will always catch and interpret that error code. This
    may or may not be good thing, depending on how you architect your
    application. If, on the other hand, you want to ensure that an error is
    always handled, if not by the receiver then by the Forte, Exceptions are
    the way to go. To extend this mechanism further, I would subclass
    GenericException and created my own error code attribute on that
    subclass. That way the receiver has the choice of interpreting the
    exception based on that error code, and wrapping it in a
    MessageDialog/window or do the usual 'errormgr.showerrors()'.
    Exceptions seem a more flexible approach to me. That is, if you can live
    with the fact that by using it, you're violating the 'exceptions for
    behavioral anomalies' software engineering principle !
    Best wishes.
    Eric Pereira
    Forte Consultant
    ----Original Message Follows----
    From: "Kallambella, Ajith" <[email protected]>
    To: "'Mark Sundsten'" <[email protected]>, [email protected]
    Cc: [email protected]
    Subject: RE: Raising Exceptions Vs returning error codes
    Date: Wed, 30 Dec 1998 08:52:39 -0500
    Reply-To: "Kallambella, Ajith" <[email protected]>
    Mark,
    Identifying conditions where you would rather use an exception
    to an error_code ( and vice-versa ) normally depends on
    your application design. Usually exceptions
    are used to handle behavioral anomalies which are
    not expected during the normal course of execution of
    the program, and which would affect the continuity of
    your algorithm if ignored. Examples would be a fatal
    error, a semantically invalid( but syntactically-valid
    token ) etc.
    Error_codes and return status's can be used to handle
    anticipated and recoverable errors. Example would
    be presentation layer validations. In any normal
    UI system, the user is expected to make errors and it
    would be annoying to throw an exception( and to handle
    it ), every time user enters wrong data. A well
    modeled client layer should not only handle
    data-validation errors , but should be smart enough
    to encourage users to input correct or
    "near-correct" data. Examples could be
    making use of look-up windows etc. Interestingly,
    Express uses exceptions to handle data-validations.
    As you see, exceptions fit well into your processing
    logic where severity of damage caused by an error
    is more. Where as error_codes fit well into presentation
    logic( and some not-so-critical processing logic ) where
    errors are usually recoverable and normal path of
    execution can be easily restored.
    Hope this helps. I would be very interested to hear
    what others have to say.
    Ajith Kallambella. M
    Forte Systems Engineer,
    International Business Corporation.
    -----Original Message-----
    From: Mark Sundsten [mailto:[email protected]]
    Sent: Tuesday, December 29, 1998 2:10 PM
    To: [email protected]
    Cc: [email protected]
    Subject: Raising Exceptions vs returning error codes
    When dealing with error handling, I find myself struggling with the
    choice
    of
    raising exceptions (and handling them) from the caller
    vs returning an error code of somekind.
    When would you want to use one over the other?
    Should you always use exception handling?
    Any discussion would be appreciated.
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    Get Your Private, Free Email at http://www.hotmail.com
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>-
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • Raising exceptions in PL/SQL

    Hi Friends
    I have the following code:
    declare
    var1....
    var2....
    cursor c1
    begin
    insert stmt;
    update stmt;
    update stmt;
    for r1 in c1 loop
    end loop;
    end;
    I will be having about 6-7 million rows every month to process. To raise exceptions, I am thinking of either of the following options:
    Option 1_
    declare
    var1....
    var2....
    var3 exception;
    var4 exception;
    var5 exception;
    cursor c1
    begin
    insert stmt;
    update stmt;
    IF SQL%NOTFOUND then
    var3;
    end if;
    update stmt;
    IF SQL%NOTFOUND then
    var4;
    end if;
    for r1 in c1 loop
    end loop;
    IF SQL%NOTFOUND then
    var5;
    end if;
    Exception
    when var3 then blah blah
    when var4 then blah blah
    when var5 then blah blah
    end;
    Option 2_
    declare
    var1....
    var2....
    cursor c1
    begin
    insert stmt;
    update stmt;
    update stmt;
    for r1 in c1 loop
    end loop;
    Exception
    when others then blah blah
    end;
    In terms of performance, which option is better? And is there any better option?
    Thanks....

    In terms of performance, which option is better? And is there any better option?If you consider in terms of performance i think you cant find any difference in both ways.
    But your both code does not do the same thing. They are entirely different. They are not the same.
    For example, If your UPDATE statement fails with a Too many rows error what will happen.
    In the first procedure the procedure will raise the error to the client. But in the second case the error is caught by the WHEN OTHERS block.
    So now here the real thing is what you do in the WHEN OTHERS block. Do you suppress the error? Do you return NULL? What do you do, That is what matters.
    Your Bla..Bla..Bla.. part in the EXCEPTION is very important. Most of them do mistake there.
    WHEN OTHERS is a great feature. But it must be used properly. Its like a very sharp knife. If you dont use it properly there will be blood.

  • Cursor For loop question

    Hi,
    I have a cursor in my plsql and I am trying to get the record through a FOR loop. I know that for loop will take care of opening, fetching and closing the cursor implicitly.
    Ex.
    declare
    cursor c1 is
    select * from emp;
    begin
    for l_rec in c1 loop
    end loop;
    My question is i want to check whether the cursor in the for loop is returning any record or not using IF condition.
    where and how i will find that?
    Can anyone help how to do that.
    Rds,
    Nag

    without using boolean variables.Obvious question, WHY?
    If you are so particular..
    SQL> declare
      2   cursor c1 is
      3        select empno, ename, job
      4        from emp
      5        where empno = 7839123;
      6   ex exception;
      7   rec c1%rowtype;
      8  begin
      9   open c1;
    10   fetch c1 into rec;
    11   if c1%notfound then
    12    raise ex;
    13   end if;
    14   loop
    15    dbms_output.put_line(rec.empno||'-->'||rec.ename||'-->'||rec.job);
    16    fetch c1 into rec;
    17    exit when c1%notfound;
    18   end loop;
    19  exception
    20   when ex then
    21    dbms_output.put_line('cur not found');
    22  end;
    23  /
    cur not found
    PL/SQL procedure successfully completed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • For Loop

    Hi,
    I have a very simple problem, which I am almost embarrassed to ask, about numeric For Loop.
    I am trying to retrieve the first 5 rows from a table with a few selected columns without using a defined cursor. Any suggestion? Thanks in advance.
    Alan

    First, then post the other solution...
    Personally, I would use...but they are really quite similar.
    FOR i IN 1..10 LOOP
              BEGIN
             IF (i = 5) THEN
                RAISE le_continue;
             END IF;
                   common_func.display_output(i);
                   EXCEPTION
                        WHEN le_continue THEN
                             NULL;          
              END;
       END LOOP;Thanks,
    Jason

Maybe you are looking for