How to Optimize this code?

Hi All
I have a procedure which runs fine,but since the data in table XYZ,ABC runs into millions it becomes too slow..Can any one guide me in optimising the code.I have already created indexes on these columns.
CREATE OR REPLACE PROCEDURE test AS
    CURSOR c1 IS
        SELECT
            t.cutGrp,
            t.cutGrpCode,
            t.modelDesc,
            t.startdate,
            t.enddate,
            avg(t.price) price,
            avg(t.netprice) netprice,
            sum(t.awdQTY) awardqty,
            sum(t.planQTY) revplanqty,
        FROM
            ABC t
        GROUP BY
            t.cutGrp,
            t.cutGrpCode,
            t.modelDesc,
            t.startdate,
            t.enddate;
counter NUMBER := 0;
l_aggregate NUMBER;
BEGIN
     FOR rec IN c1
     LOOP
        counter := counter + 1;
        SELECT
            sum(t.anotherQTY) INTO l_aggregate
        FROM
             XYZ t
        WHERE
            t.cutstomer_Grp = rec.cutGrp
            AND t.cutGrp_Code = rec.cutGrpCode
            AND t.product_model = rec.modelDesc;
        UPDATE XYZ t
        SET
            t.testQTY = l_aggregate,
            t.testprice = rec.price,
            t.testnetprice = rec.netprice,
            t.testawardQTY = rec.awardqty,
            t.testplanQTY = rec.revplanqty,         
            t.fcstartdate = rec.startdate,
            t.fcenddate = rec.enddate
        WHERE
            t.cutstomer_Grp = rec.cutGrp
            AND t.cutGrp_Code = rec.cutGrpCode
            AND t.cutGrp_Code = rec.modelDesc;
    END LOOP;
    COMMIT WORK;
END test;
SHOW ERRORS;

Hi All
This the only query i could come up with...But this gives me error
ORA-30926 unable to get a stable set of rows in the source tables.Also this code does not address
SELECT
            sum(t.anotherQTY) INTO l_aggregate
        FROM
             XYZ t
        WHERE
            t.cutstomer_Grp = rec.cutGrp
            AND t.cutGrp_Code = rec.cutGrpCode
            AND t.product_model = rec.modelDesc;<b>This is what i came up with </b> so any code help is appreciated
MERGE INTO sgforecastrecord b
USING (
SELECT
     cutGrp
     cutGrpCode ,
     modelDesc,
     startdate,
     enddate,
     avg(price) price,
     avg(netprice) netprice,
     sum(awdQTY) awardqty,
     sum(planQTY) revplanqty     
FROM
      ABC
GROUP BY
     cutGrp,
     cutGrp,
     modelDesc,
     startdate,
     enddate
) t
on           (
     t.cutstomer_Grp = b.cutGrp
        AND t.cutGrp_Code = b.cutGrpCode
            AND t.product_model = b.modelDesc;
WHEN MATCHED THEN
     UPDATE  set 
          b.testprice = t.price,
           b.testnetprice = t.netprice,
            b.testawardQTY = t.awardqty,
            b.testplanQTY = t.revplanqty,         
            b.fcstartdate = t.startdate,
            b.fcenddate = t.enddate
                                                                            

Similar Messages

  • How to optimize this code + is design proper

    Well I have to implement tree programming here , what i mean by tree
    programming is i have data stored in tree format i,e I have parent
    object which will have child objects of same type the level of depth can
    go any long:
    I am able to store objects in tree format and also able to display properly Here
    is code but I am facing problems when i have to filter some child nodes based on some conditions:
    I have two question is this code fine is there anything wrong with desin Plus how to handle removing child node in tree scenation where child can be in any place.Below is code
    package menu;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import com.chartis.gp.support.util.BrokerSupportUtil;
    import com.chartis.gp.support.vo.Links;
    import com.chartis.kernel.user.UserVO;
    import com.chartis.kernel.utils.Utils;
    public class Utility{
         /* IN this class NavModel,CModel,CNode are some dummy classes
          * which help us read contents form some resources which are stored in dummy format
          * as Example of tree format stored data below is the example
          *    tree
          *       child1
          *       child2
          *       child3
          *              child3-1
          *                       child:q
          *                       child:r
          *                               child:a
          *              child3-2
          *       child4
         private static void populateChildLinks(NavModel navModel, Object objectNode, Links parent ){
              try{
                   List<Links> childLinks = new ArrayList<Links>();
                   Iterator it = navModel.getChildren( objectNode );
                   while( it.hasNext() ){
                        NavNode node = (NavNode) it.next();
                        CNode contentNode = node.getContentNode();
                        Links links = new Links();
                        links.setNodeName( contentNode.getNodeName() );
                        childLinks.add( links );
                        if( navModel.hasChildren( node ) ){
                             populateChildLinks( node, links );
                   parent.setChildren( childLinks );
              catch( Exception e ){
         private static Links createCategoryLinks(String categoryLinkName){
              Links categoryLinks = new Links();
              categoryLinks.setNodeName( categoryLinkName );
              return categoryLinks;
         public static Links setupLinks(String categoryLinkName,String name) {
              Links categoryLinks=null;
              CModel contentModel = new CModel();
              NavModel navModel = new NavModel();
              categoryLinks = Utility.createCategoryLinks( categoryLinkName);
              Object objectNode = contentModel.getLocator().findByUniqueName(name);
              if( objectNode != null ){
                   if( navModel.hasChildren( objectNode ) ){
                        populateChildLinks( navModel,objectNode, categoryLinks );
                  // This is where i am facing issue once i get list of links of childs
              // i have to delete how can i find that particular child in the list
              // do i have to iterate through all the links and delete or  which
              // way is better
         private static void filterLinks( Links parentNode,
                   List<Links> childNodeList ){
              List<Links> filteredResourceList = new ArrayList<Links>();
              if(  childNodeList!=null ){
                   Iterator<Links> childNodeIt = childNodeList.iterator();
                   while( childNodeIt.hasNext() ){
                        Links childNode = (Links) childNodeIt.next();
                        if(childNode.getChildren().size() >0 ){
                           filterLinks( childNode, childNode.getChildren() );
                        boolean removeNode = filterContents( childNode);
                        if(! removeNode ){
                             filteredResourceList.add( childNode );
              Iterator<Links> filteredResourceIt = filteredResourceList.iterator();
              while( filteredResourceIt.hasNext() ){
                   Links childNode = (Links) filteredResourceIt.next();
                   parentNode.getChildren().remove( childNode );
         // Let us consider this as some dummy method which returns true or false based on some conditions
         private static boolean filterContents( menu.Links childNode ){
              return false;
      package menu;
    import java.util.List;
    public class Links{
          private String nodeName;
         private List<Links> children;
         public List<Links> getChildren(){
              return children;
         public void setChildren( List<Links> children ){
              this.children = children;
         public String getNodeName(){
              return nodeName;
         public void setNodeName( String nodeName ){
              this.nodeName = nodeName;
    package menu;
    public class TreeDisplay{
         public static void main( String[] args ){
          Links link = Utility.setupLinks( "SomeName", "ResiyrbceBane");
           Utility.filterLinks( link, link.getChildren() );
    }Is the utility class with so many static class is ok?

    Vicky wrote:
    Thanks TPD
    If you could write more on it , it will be great i rarely find ocasations of using interfaces , however i don't think creating a new tree with valid node could be better solution as you have to create a new tree keeping the same hierarchy .The advantage is that all other components do not need to know that they work with a filtered tree.
    Certainly you can do it the other way around bye passing the tree and the filter to eg. the <tt>NotePrinter</tt> Object, but than all components working with the tree meight neet to know that ther are Node filters.
    I just came up with the Idea to give the nodes themselfes knowlege of the Filter via <tt>setFilter(Filter<Links> myFilter)</tt>. You would call this on the root node and in the <tt>getChildren()</tt> method you would check if the child apllies to the filter and pass that filter to the eliable childs before putting them into a new collection which is returned to the caller. Ofcause you should initialise the <tt>this.filter</tt> property in <tt>Links</tt> with a <tt>ALL_NODES</tt> constant.
    Also you should resist the tamptation to make the <tt>this.filter</tt> property in <tt>Links</tt> static. This would save you one line of code in the <tt>getCildren()</tt> method by the cost that you cannot have different trees with different filters in the same JVM.
    This kind of interference between threads is pretty hard to find later in production environments...
    bye
    TPD

  • Performance Tuning Issues  ( How to Optimize this Code)

    _How to Optimize this Code_
    FORM MATL_CODE_DESC.
      SELECT * FROM VBAK WHERE VKORG EQ SAL_ORG AND
                               VBELN IN VBELN AND
                               VTWEG IN DIS_CHN AND
                               SPART IN DIVISION AND
                               VKBUR IN SAL_OFF AND
                               VBTYP EQ 'C' AND
                               KUNNR IN KUNNR AND
                               ERDAT BETWEEN DAT_FROM AND DAT_TO.
        SELECT * FROM VBAP WHERE VBELN EQ VBAK-VBELN AND
                                 MATNR IN MATNR.
          SELECT SINGLE * FROM MAKT WHERE MATNR EQ VBAP-MATNR.
          IF SY-SUBRC EQ 0.
            IF ( VBAP-NETWR EQ 0 AND VBAP-UEPOS NE 0 ).
              IF ( VBAP-UEPVW NE 'B' AND VBAP-UEPVW NE 'C' ).
                MOVE VBAP-VBELN TO ITAB1-SAL_ORD_NUM.
                MOVE VBAP-POSNR TO ITAB1-POSNR.
                MOVE VBAP-MATNR TO ITAB1-FREE_MATL.
                MOVE VBAP-KWMENG TO ITAB1-FREE_QTY.
                MOVE VBAP-KLMENG TO ITAB1-KLMENG.
                MOVE VBAP-VRKME TO ITAB1-FREE_UNIT.
                MOVE VBAP-WAVWR TO ITAB1-FREE_VALUE.
                MOVE VBAK-VTWEG TO ITAB1-VTWEG.
                MOVE VBAP-UEPOS TO ITAB1-UEPOS.
              ENDIF.
            ELSE.
              MOVE VBAK-VBELN TO ITAB1-SAL_ORD_NUM.
              MOVE VBAK-VTWEG TO ITAB1-VTWEG.
              MOVE VBAK-ERDAT TO ITAB1-SAL_ORD_DATE.
              MOVE VBAK-KUNNR TO ITAB1-CUST_NUM.
              MOVE VBAK-KNUMV TO ITAB1-KNUMV.
             SELECT SINGLE * FROM KONV WHERE KNUMV EQ VBAK-KNUMV AND
                                             KSTEU = 'C' AND
                                             KHERK EQ 'A' AND
                                             KMPRS = 'X'.
             IF SY-SUBRC EQ 0.
               ITAB1-REMARKS = 'Manual Price Change'.
             ENDIF.
              SELECT SINGLE * FROM KONV WHERE KNUMV EQ VBAK-KNUMV AND
                                              KSTEU = 'C' AND
                                              KHERK IN ('C','D') AND
                                              KMPRS = 'X' AND
                                              KRECH IN ('A','B').
              IF SY-SUBRC EQ 0.
                IF KONV-KRECH EQ 'A'.
                  MOVE : KONV-KSCHL TO G_KSCHL.
                  G_KBETR = ( KONV-KBETR / 10 ).
                  MOVE G_KBETR TO G_KBETR1.
                  CONCATENATE G_KSCHL G_KBETR1 '%'
                              INTO ITAB1-REMARKS SEPARATED BY SPACE.
                ELSEIF KONV-KRECH EQ 'B'.
                  MOVE : KONV-KSCHL TO G_KSCHL.
                  G_KBETR = KONV-KBETR.
                  MOVE G_KBETR TO G_KBETR1.
                  CONCATENATE G_KSCHL G_KBETR1
                              INTO ITAB1-REMARKS SEPARATED BY SPACE.
                ENDIF.
              ELSE.
                ITAB1-REMARKS = 'Manual Price Change'.
              ENDIF.
              CLEAR : G_KBETR, G_KSCHL,G_KBETR1.
              MOVE VBAP-KWMENG TO ITAB1-QTY.
              MOVE VBAP-VRKME TO ITAB1-QTY_UNIT.
              IF VBAP-UMVKN NE 0.
                ITAB1-KLMENG = ( VBAP-UMVKZ / VBAP-UMVKN ) * VBAP-KWMENG.
              ENDIF.
              IF ITAB1-KLMENG NE 0.
                VBAP-NETWR = ( VBAP-NETWR / VBAP-KWMENG ).
                MOVE VBAP-NETWR TO ITAB1-INV_PRICE.
              ENDIF.
              MOVE VBAP-POSNR TO ITAB1-POSNR.
              MOVE VBAP-MATNR TO ITAB1-MATNR.
              MOVE MAKT-MAKTX TO ITAB1-MAKTX.
            ENDIF.
            SELECT SINGLE * FROM VBKD WHERE VBELN EQ VBAK-VBELN AND
                                            BSARK NE 'DFUE'.
            IF SY-SUBRC EQ 0.
              ITAB1-INV_PRICE = ITAB1-INV_PRICE * VBKD-KURSK.
              APPEND ITAB1.
              CLEAR ITAB1.
            ELSE.
              CLEAR ITAB1.
            ENDIF.
          ENDIF.
        ENDSELECT.
      ENDSELECT.
    ENDFORM.                               " MATL_CODE_DESC

    Hi Vijay,
    You could start by using INNER JOINS:
    SELECT ......
                FROM (                    VBAK
                             INNER JOIN VBAP
                                           ON VBAPVBELN = VBAKVBELN
                             INNER JOIN MAKT
                                           ON MAKTMATNR = VBAPMATNR AND
                                                 MAKT~SPRAS = SYST-LANGU )
                INTO TABLE itab
              WHERE VBAK~VBELN IN VBELN
                   AND VBAK~VTWEG IN DIS_CHN
                   AND VBAK~SPART IN DIVISION
                   AND VBAK~VKBUR IN SAL_OFF
                   AND VBAK~VBTYP EQ 'C'
                   AND VBAK~KUNNR IN KUNNR
                   AND VBAK~ERDAT BETWEEN DAT_FROM AND DAT_TO
                   AND VBAP~NETWR EQ 0
                   AND VBAP~UEPOS NE 0
    Regards,
    John.

  • How to optimize this select statement  its a simple select....

    how to optimize this select statement  as the records in earlier table is abt i million
    and this simplet select statement is not executing and taking lot of time
      SELECT  guid  
                    stcts      
      INTO table gt_corcts
      FROM   corcts
      FOR all entries in gt_mege
      WHERE  /sapsll/corcts~stcts = gt_mege-ctsex
      and /sapsll/corcts~guid_pobj = gt_Sagmeld-guid_pobj.
    regards
    Arora

    Hi Arora,
    Using Package size is very simple and you can avoid the time out and as well as the problem because of memory.  Some time if you have too many records in the internal table, then you will get a short dump called TSV_TNEW_PAGE_ALLOC_FAILED.
    Below is the sample code.
    DATA p_size = 50000
    SELECT field1 field2 field3
       INTO TABLE itab1 PACKAGE SIZE p_size
       FROM dtab
       WHERE <condition>
    Other logic or process on the internal table itab1
    FREE itab1.
    ENDSELECT.
    Here the only problem is you have to put the ENDSELECT.
    How it works
    In the first select it will select 50000 records ( or the p_size you gave).  That will be in the internal table itab1.
    In the second select it will clear the 50000 records already there and append next 50000 records from the database table.
    So care should be taken to do all the logic or process with in select and endselect.
    Some ABAP standards may not allow you to use select-endselect.  But this is the best way to handle huge data without short dumps and memory related problems. 
    I am using this approach.  My data is much more huge than yours.  At an average of atleast 5 millions records per select.
    Good luck and hope this help you.
    Regards,
    Kasthuri Rangan Srinivasan

  • Anyone knows how to make this code to netbeans??

    anyone knows how to make this code to netbeans?? i just want to convert it into netbeans... im not really advance with this software... anyway..just reply if you have any idea...or steps how to build it... etc.... thanks guys...
       import javax.swing.*;
       import javax.swing.table.*;
       import java.awt.*;
       import java.awt.event.*;
       import java.util.regex.*;
       public class FilterTable {
         public static void main(String args[]) {
           Runnable runner = new Runnable() {
             public void run() {
               JFrame frame = new JFrame("Sorting JTable");
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               Object rows[][] = {
                 {"AMZN", "Amazon", 41.28},
                 {"EBAY", "eBay", 41.57},
                 {"GOOG", "Google", 388.33},
                 {"MSFT", "Microsoft", 26.56},
                 {"NOK", "Nokia Corp", 17.13},
                 {"ORCL", "Oracle Corp.", 12.52},
                 {"SUNW", "Sun Microsystems", 3.86},
                 {"TWX",  "Time Warner", 17.66},
                 {"VOD",  "Vodafone Group", 26.02},
                 {"YHOO", "Yahoo!", 37.69}
               Object columns[] = {"Symbol", "Name", "Price"};
               TableModel model =
                  new DefaultTableModel(rows, columns) {
                 public Class getColumnClass(int column) {
                   Class returnValue;
                   if ((column >= 0) && (column < getColumnCount())) {
                     returnValue = getValueAt(0, column).getClass();
                   } else {
                     returnValue = Object.class;
                   return returnValue;
               JTable table = new JTable(model);
               final TableRowSorter<TableModel> sorter =
                       new TableRowSorter<TableModel>(model);
               table.setRowSorter(sorter);
               JScrollPane pane = new JScrollPane(table);
               frame.add(pane, BorderLayout.CENTER);
               JPanel panel = new JPanel(new BorderLayout());
               JLabel label = new JLabel("Filter");
               panel.add(label, BorderLayout.WEST);
               final JTextField filterText =
                   new JTextField("SUN");
               panel.add(filterText, BorderLayout.CENTER);
               frame.add(panel, BorderLayout.NORTH);
               JButton button = new JButton("Filter");
               button.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                   String text = filterText.getText();
                   if (text.length() == 0) {
                     sorter.setRowFilter(null);
                   } else {
                     try {
                       sorter.setRowFilter(
                           RowFilter.regexFilter(text));
                     } catch (PatternSyntaxException pse) {
                       System.err.println("Bad regex pattern");
               frame.add(button, BorderLayout.SOUTH);
               frame.setSize(300, 250);
               frame.setVisible(true);
           EventQueue.invokeLater(runner);
       }

    its okay onmosh.....what we need to
    this...forum....is to have a good......relationship
    of programmers......and to start with .....we need to
    have a good attitude........right.....???.....no
    matter how good you are in programming but if you did
    not posses the right kind of attitude....everything
    is useless.....in the first place....all we
    want....is just to ask...some....help....but
    conflicts......but unluckily......we did not expect
    that there are members in here which......not
    good...to follow.....just as suggestion for those
    people not having the right kind of attidude...why
    can't you do in a very nice message sharing in a very
    nice....way....why we need to put some
    stupid....stuff...words.....can't you live with out
    ******* ****....its not.....lastly especially you
    have your children right now and people around...that
    somehow......idiolize...you even me....is one of
    them......but showing but attitude....is not
    good......tnx....hope you'll take it this....in the
    positive side.....be optimistic...guys....the
    world..is not yours....all of us will just past
    away....always..remember that one.....treasure..our
    stay in this....temporary home.....which...is
    world....Whoa. That post seems to be killing my brain.
    URK
    Join........us..........do not be..........afraid.......

  • Can someone please tell me on how to modify this code so that I dont have to enter the file name at all?

    Hello
    can someone please tell me how to modify this code so that I dont have to enter the file path at all? When i give the same file path constants to both the read and write VIs I'm getting an error message.
    Attachments:
    read and write.vi ‏11 KB

    Yup use the low level File I/O opening the reference once, and closing it once.  
    As for the path selection you have an unwired input which is the path to use.  Programatically set that and you won't be prompted to select a path.  Usually this is done with a path constant to a folder, then using the Build Path, to set the file name in that folder.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to optimize this RW code? (full version)

    Hello: (Sorry for the wrong previous post, hope the moderator delete it)
    I have this code:
    import java.io.*;
    class Number
        private byte val=0;
        public void Read(DataInputStream ar) throws Exception {val=ar.readByte();}
        public void Read(RandomAccessFile ar) throws Exception {val=ar.readByte();}
        public void Write(RandomAccessFile ar) throws Exception {ar.writeByte(val);}
        public void Write(DataOutputStream ar) throws Exception {ar.writeByte(val);}
    }As you can see, I have methods for storing and writing into RandomAccessFiles and DataStreams. The code for RW is the same for both media. Is there any way to use the same code for Read(DataInputStream ar) and Read(RandomAccessFile ar)? Note that actually my class is more complex and can contain many data for RW: integers, doubles, objects, so that's why I want to simplify it. I thought about this possibility:
    public void Read(Object ar)  throws Exception  
          if(ar instanceof RandomAccessFile) val= ((RandomAccessFile)ar).readByte();
          if(ar instanceof DataInputStream ) val= ((DataInputStream )ar).readByte();
    public void Write(Object ar)  throws Exception  
          if(ar instanceof RandomAccessFile) val= ((RandomAccessFile)ar).writeByte(val);
          if(ar instanceof DataOutputStream ) val= ((DataOutputStream )ar).writeByte(val);
    }But as you can see I have to make casts and repeat the code, I only got the advantage of having one single method.
    Any suggestion?
    Thanks!

    Both DataOutputStream and RandomAccessFile implement the interfaces DataOutput, so you could do:
    public void write(DataOutput out) throws Exception  
      out.writeByte(value);
    }(the other case, RandomAccessFile and DataInputStream, use DataInput)

  • How to implement this code in labview?

    How do implement this pseudo code in labview? Please keep in mind "a" and "c" in the code below ARE VARIABLES
    for i =0 to i=maxvalue
           if i <= a 
               output = output2
           else if i > a AND i<=c
               output = output2
           else if i < c 
               output = output3
           else i = d
               output = output4
    I understance i can use a case structures and modify the label, but i do not know how to make the label dependent on a variable value. 
    Thanks 

    Try an array of boudaries and use threshold array. See this old example:
    Now just iterate over an array of values using a FOR loop.
    LabVIEW Champion . Do more with less code and in less time .

  • How to optimize this sql by writing MINUS function.

    Hi all,
    how to optimize the sql by writing MINUS function.
    these are my tables
    1. CREATE TABLE POSTPAID
    RECORD VARCHAR2(2000 BYTE),
    FLAG NUMBER
    Record format:
    Mobile no in 1:10 of that length
    2. CREATE TABLE SUBSCRIBER
    PHONE_NO VARCHAR2(10 BYTE)
    My requirement is following sql need write using ‘minus’ as this one is very slow
    select record record from POSTPAID where substr(record,9,10) NOT in (select PHONE_NO from SUBSCRIBER)
    Thanks

    Why are you very particular about using "MINUS". You can optimize the sql by using "NOT EXISTS" instead of "NOT IN" as below:
    SELECT RECORD FROM POSTPAID A WHERE NOT EXISTS (SELECT 1 FROM SUBSCRIBER B WHERE SUBSTR(A.RECORD,9,10) = B.PHONE_NO)

  • How to write this code ?

    I need to write 3 classes that each one can get to the other with the same instance of the class , so how do i write this code ?
    thanks a lot

    try out singleton pattern with all the three classes. following link may help...
    http://www.javareference.com/jrexamples/viewexample.jsp?id=25

  • How to test this code ???

    Hi All,
    One quick question:
    ..>>>>How do you test below InterfaceImpl classes in a simple program to test the code ???
    //below is the sample of the example I am running .
    Thanks
    Jack
    //interface 1
    same package;
    interface someInterfaceName1 {
    public void setLastName();
    public String getLastName();
    //inerface 2
    same package;
    interface someInterfaceName2{
    public void setBillingAddress(somename1 billing){
    public void setShippingAddress(somename1 shipping){
    // implementation class1
    samepackage;
    public class someInterfaceName1Impl implements someInterfaceName1 {
    private String lastName="";
    someInterfaceName1Impl();
    public void setLastName(String lastName){
    this.lastName=lastName;
    public String getLastName(){
    return LastName;
    //implementatio class2 for interface 2
    samepackage;
    class someInterfaceName2Impl implements someInterfaceName2
    public void setBillingAddress(interface1 billto){
    billto.setlastName(someValue); --?????
    public void setShippingAddress(interface1 shipto) {
    shipto.setFirstName(someValue); --- ?????
    //How to test the code ??
    package samepackage;
    class testMyCode {
    public static void main(String args[]){
    // how do you get the interfaces implementation here to test with dummy values ????

    Something along these lines (but departing from your code a bit...) public static void test() {
        Interface1 ifc1 = new Impl1();
        String tmpStr;
        int tmpInt;
        ifc1.setName("joe");
        tmpStr = ifc1.getName();
        if (!("joe".equals(tmpStr))) {
            System.err.println("set/getName failed. Put in joe but got out " + tmpStr);
        ifc1.setBirthdate("May 1 1980");
        tmpInt = ifc1.getAge();
        if (tmpInt != 24) {
            System.err.println("setBirthdate/getAge failed. Put in May 1 1980, expected 24 but got " + tmpInt);
        try {
            tmpStr = "Booger 99, 19seventy-beer";
            ifc1.setBirthdate(tmpStr);
            //shouldn't get here
           System.err.println("setBirthdate accepted invalid date: " + tmpStr);
        catch (InvalidBirthdateException exc) {
            // we want this, since it means our code properly rejected a bad date
    } Or, when you start writing serious code, look into junit
    &#12472;

  • How to transport this code to an applet

    Hi friends..
    the following page has a program to capture images from a web-cam.. can u help me how to transport that code into an applet. So that i can import that applet into an html page, where the live video can be streamed.
    the link is :- http://forum.java.sun.com/thread.jspa?threadID=247253&start=0&tstart=0
    i tried this code. but on html page the code is not being initialized, though the program is getting compiled correctly.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import javax.media.*;
    import javax.media.format.*;
    import javax.media.util.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.applet.*;
    import com.sun.image.codec.jpeg.*;
    public class applet extends JApplet{
       static final int    WIDTH  = 320;
        static final int    HEIGHT = 320;
        //public intoApplet d = null;
        public static void main(String args[]){
             JFrame frame = new JFrame("Code Converter");
             applet a = new applet();
             a.init();
             frame.getContentPane().add(a);
             frame.setSize(WIDTH, HEIGHT);
             frame.setVisible(true);
        public void init() {
          System.out.println("Applet initializing");
          intoApplet d = new intoApplet();
          getContentPane().add(d);
        public void start() {
            System.out.println("Applet starting");
        public void stop() {
            System.out.println("Applet stopping");
        public void destroy() {
            System.out.println("Applet destroyed");
    public class intoApplet extends JPanel //implements ActionListener
      public Player player = null;
      public CaptureDeviceInfo di = null;
      public MediaLocator ml = null;
      public JButton capture = null;
      public Buffer buf = null;
      public Image img = null;
      public VideoFormat vf = null;
      public BufferToImage btoi = null;
      //public ImagePanel imgpanel = null;
      public intoApplet()
           System.out.print("into swing...");
        setLayout(new BorderLayout());
        setSize(320,320);
        String str1 = "vfw:Logitech USB Video Camera:0";
        String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
        di = CaptureDeviceManager.getDevice(str2);
        //ml = di.getLocator();
        ml = new MediaLocator("vfw://0");
        try
          player = Manager.createRealizedPlayer(ml);
          player.start();
          Component comp;
          if ((comp = player.getVisualComponent()) != null)
            add(comp,BorderLayout.NORTH);
          //add(capture,BorderLayout.CENTER);
          //add(imgpanel,BorderLayout.SOUTH);
        catch (Exception e)
          e.printStackTrace();
    public void playerclose()
        player.close();
        player.deallocate();
    }Message was edited by:
    rahulsah

    Maybe this topic helps (JUnit into Applet):
    http://forum.java.sun.com/thread.jspa?threadID=5130219&messageID=9469005#9469005

  • How to make this code go faster?

    Hi,
    I have this code and its really slow. My question is how to make it faster since its taking about 10 hours.
    Code:
      loop at ti_equi.
        select matnr sernr lief_nr kunde datum uzeit bwart posnr
    appending corresponding fields of table ti_ser01
          from z_objk_ser01
         where sernr eq ti_equi-sernr
           and matnr eq ti_equi-matnr.
      endloop.
      delete ti_ser01 where not ( kunde in s_kunnr and
                                  bwart = '631' ).
      sort ti_ser01 by matnr sernr datum descending uzeit descending.
      delete adjacent duplicates from ti_ser01 comparing matnr sernr.
    What this code does is fetch all these fields and then just keeps the one that's been modified at last.
    I have created an index by sernr and matnr in table objk which makes it just a little bit faster.
    Any helpful answer will be appreciated.
    Regards,
    Roberto
    Edited by: Julius Bussche on Jan 27, 2009 4:29 PM
    Code tags added. Please use more meaningfull subject titles

    Hi roberto
    please avoid select statment inside loop.
    use code
    data: index type sy-tabix.
    data : ti-ser011 type standard table of zobjk-ser01 with header line.
    select matnr sernr lief_nr kunde datum uzeit bwart posnr
          from z_objk_ser01 into table ti_ser01.
    sort ti_ser01 by sernr matnr.
    sort ti_equi by sernr matnr.
    index = 1.
    loop at ti_equi.
        loop at ti_ser01 from index
         if  ti_ser01-sernr = ti_equi-sernr
              and ti_ser01-matnr = ti_equi-matnr.
            move-corresponding ti_ser01 to ti_ser011.
            append ti_ser011.
            index = sy-tabix.
            exit.  
         endif.
        endloop.
    endloop.
    here i have used one more internal table ti_ser011.
    you can delete specific record from ti_ser01 internal table on condition. at that time u don't need to create any other internal table like ti-ser011.
    in place of loop select statement---endloop.
    you can use this code. I think it will help you.
    please find if it is udeful.

  • How to fix this code?

    Hello,
    I am trying to display country, state within each country,
    then person in each state...using cfoutput and group.
    i am getting this error...How can i fix this code?
    The &lt;cfif&gt; tag requires an end tag to nest
    within &lt;cfoutput&gt;, which began on line 21, column
    26.<p>The CFML compiler was
    processing:<ul><li>The body of a cfoutput tag beginning
    on line 26, column 34.<li>The body of a cfoutput tag
    beginning on line 26, column 34.</ul>

    Rather then including <cfif county_q.state neq ''> in
    your CF code eliminate any records with an empty state in your
    query. The sample appears to have a country, state, and name value
    for every record.
    If this is not possible please post a more code including:
    1. Your query
    2. A sample of your data with and without an empty state
    value

  • Please make suggestions on how to improve this code.

    Hello Experts,
    I am currently modifying a report where a certain code is giving
    me run time error. When I debugged the program, the internal table
    has 20,000+ records. Now, is there any alternative to this code?
    I really need to speed this up. Help would be greatly appreciated and rewarded.
    LOOP AT it_cdpos INTO wa_cdpos.
        l_matnr = wa_cdpos-objectid+00(18).
        l_charg = wa_cdpos-objectid+22(10).
        l_zustd = wa_cdpos-value_new+00(01).
        READ TABLE it_batch INTO wa_batch
             WITH KEY matnr = l_matnr
                      charg = l_charg.
        IF sy-subrc EQ 0.
          l_tabix = sy-tabix.
          wa_batch-zustd = l_zustd.
          MODIFY it_batch FROM wa_batch INDEX l_tabix
                 TRANSPORTING zustd.
        ELSE.
          wa_batch-matnr = l_matnr.
          wa_batch-charg = l_charg.
          wa_batch-zustd = l_zustd.
          wa_batch-code  = 'A'.              "selected within period
          APPEND wa_batch TO it_batch.
        ENDIF.
      ENDLOOP.

    Check the SQL statement from which u get the result otherwise
    the code which u sent is optimized or u can use the binary search option for the Read statement for MATNR
    while the rest of the code is optimized....
    or u can use
    loop at it_cdpos assinging <fs>.
                 <FS>-cols = value.
    <b>note: in this case <FS>-col = value</b>
    u wont have to use <b>modify</b> statement for internal table for updating the line contents
    since assinging it to field-symbol will dynamically modifies the contents.
    <b>this method is faster than the below modify process </b>
    endloop.

Maybe you are looking for

  • Global educate quotes?

    Pages doesn't seem to have a command to globally find all straight quotes and turn them into curly quotes. Is there a way to do this without resorting to another program? If not, what's the smallest, lightest-weight text manipulator program you would

  • Very Low Battery

    When i connect my ipod to the computer it comes up please wait very low battery even when its fully charged and nothing happens

  • How to call a VB dll with boolean parameter in labview

    hi ,      I havea problem with labview calling dll.      I need to call a customer's dll(VB) , but I find labview have no  boolean type parameter, so how can I do it ?      I have used labview 7.1 and only have dll without source code. sonic Sonic Di

  • How to add key figuers before chracteristic

    Hi all, i would like to now if it is possible to add key figuers before chracteristics in a report. The report look like this (CH - characteristic, KF - key figure): CH1 CH2 CH3 CH4 CH5 KF1 KF2 KF3 KF4 KF5 but it should look like this: CH1 CH2 KF1 KF

  • Does ZAM Client work with Windows 7 and/or OS X Snow Leopard

    Or will there be support for either of those environments? Installer seems to work OK, but client does not report to the Collector.