Optimization of Codes in ABAP

Hello there,
Can anyone help me about my problem in optimizing my code in ABAP..
before i used SDF logical dbf..but simple select in BSIS,BKPF and BSEG tables are much faster than using logical dbf..but my main problem is it took a while also in processing a report while using a select statement..here is my sample code.
It took 2mins in processing a report...Hope someone can help me
Please give me some advice.
Thanks in advance
aVaDuDz
SELECT SINGLE *
  FROM skb1
  WHERE bukrs EQ p_bukrs
  AND saknr EQ p_saknr.
  IF sy-subrc EQ 0.
    SELECT blart belnr waers monat budat bukrs hkont buzei
           shkzg dmbtr wrbtr gjahr
    INTO CORRESPONDING FIELDS OF TABLE it_bsis
    FROM bsis
    WHERE bukrs EQ p_bukrs
    AND hkont EQ p_saknr
    AND gjahr IN p_gjahr
    AND monat IN p_monat.
    PERFORM add_record.
  ENDIF.
FORM add_record .
  LOOP AT it_bsis.
    g_percn = 1.
    CLEAR g_indic.
    g_indic = c_indic.
    REPLACE '&' WITH it_bsis-belnr INTO g_indic.
    REPLACE '%' WITH it_bsis-buzei INTO g_indic.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        percentage = g_percn
        text       = g_indic.
    READ TABLE it_data ASSIGNING <data>
         WITH KEY  belnr = it_bsis-belnr "document #
                   buzei = it_bsis-buzei. "Line Item
    IF sy-subrc <> 0.
      APPEND INITIAL LINE TO it_data ASSIGNING <data>.
      <data>-belnr = it_bsis-belnr. "document #
      <data>-buzei = it_bsis-buzei. "Line Item
    ENDIF.
    <data>-bukrs = it_bsis-bukrs. "Company
    <data>-hkont = it_bsis-hkont. "G/L Acct.
    <data>-gjahr = it_bsis-gjahr.
    <data>-waers = it_bsis-waers.
    <data>-belnr = it_bsis-belnr.
    <data>-monat = it_bsis-monat.
    <data>-budat = it_bsis-budat.
    <data>-blart = it_bsis-blart.
    IF it_bsis-shkzg ='H'.
      <data>-wrbtr = it_bsis-wrbtr * -1.
      <data>-dmbtr = it_bsis-dmbtr * -1.
    ELSE.
      <data>-wrbtr = it_bsis-wrbtr.
      <data>-dmbtr = it_bsis-dmbtr.
    ENDIF.
    SELECT SINGLE lifnr sgtxt
     FROM bseg
     INTO gs_vendor
     WHERE belnr  =  it_bsis-belnr
     AND gjahr IN p_gjahr
     AND lifnr NE ''.
    SELECT SINGLE lifnr name1 stcd1
     FROM lfa1
     INTO gs_lfa1
     WHERE lifnr = gs_vendor-lifnr.
    <data>-lifnr = gs_lfa1-lifnr.
    <data>-sgtxt = gs_vendor-sgtxt.
    <data>-name1 = gs_lfa1-name1.
    <data>-stcd1 = gs_lfa1-stcd1.
    SELECT SINGLE wt_withcd
    FROM with_item
    INTO gs_item
    WHERE belnr = it_bsis-belnr
    AND gjahr IN p_gjahr.
    IF sy-subrc EQ 0.
      <data>-mwskz = gs_item.
    ENDIF.
    SELECT SINGLE ppnam usnam bldat
    FROM bkpf
    INTO gs_bkpf
    WHERE belnr = it_bsis-belnr
    AND gjahr IN p_gjahr.
    <data>-ppnam = gs_bkpf-ppnam.
    <data>-usnam = gs_bkpf-usnam.
    <data>-bldat = gs_bkpf-bldat.
  ENDLOOP.
ENDFORM.                    " add_record

Hi,
Check this code. See the comments where i have mentioned "Add / Remove this".
For tables like BSEG, BKPF and WITH_ITEM you have to provide complete key to read from table. BUKRS should be the first field in select statement.
Also, you do not need to check LIFNR  NE '', when you select from BSEG. Just read the first line item. It is vendor / customer line item.
Also, <b>DO NOT USE SAPGUI_PROGRESS_INDICATOR inside loop</b>. It does affect performance.
Let me know if you still have performance issue.
SELECT SINGLE *
               FROM skb1
               WHERE bukrs EQ p_bukrs
               AND saknr EQ p_saknr.
IF sy-subrc EQ 0.
  SELECT blart belnr waers monat budat bukrs hkont buzei
  shkzg dmbtr wrbtr gjahr
  INTO CORRESPONDING FIELDS OF TABLE it_bsis
  FROM bsis
  WHERE bukrs EQ p_bukrs
  AND hkont EQ p_saknr
  AND gjahr IN p_gjahr
  AND monat IN p_monat.
  PERFORM add_record.
ENDIF.
*       FORM add_record                                               *
FORM add_record .
  LOOP AT it_bsis.
    g_percn = 1.
    CLEAR g_indic.
    g_indic = c_indic.
    REPLACE '&' WITH it_bsis-belnr INTO g_indic.
    REPLACE '%' WITH it_bsis-buzei INTO g_indic.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              percentage = g_percn
              text       = g_indic.
    READ TABLE it_data ASSIGNING <data>
    WITH KEY belnr = it_bsis-belnr "document #
    buzei = it_bsis-buzei. "Line Item
    IF sy-subrc <> 0.
      append initial line to it_data assigning <data>.
      <data>-belnr = it_bsis-belnr. "document #
      <data>-buzei = it_bsis-buzei. "Line Item
    ENDIF.
    <data>-bukrs = it_bsis-bukrs. "Company
    <data>-hkont = it_bsis-hkont. "G/L Acct.
    <data>-gjahr = it_bsis-gjahr.
    <data>-waers = it_bsis-waers.
    <data>-belnr = it_bsis-belnr.
    <data>-monat = it_bsis-monat.
    <data>-budat = it_bsis-budat.
    <data>-blart = it_bsis-blart.
    IF it_bsis-shkzg ='H'.
      <data>-wrbtr = it_bsis-wrbtr * -1.
      <data>-dmbtr = it_bsis-dmbtr * -1.
    ELSE.
      <data>-wrbtr = it_bsis-wrbtr.
      <data>-dmbtr = it_bsis-dmbtr.
    ENDIF.
    SELECT SINGLE
                 lifnr
                 sgtxt FROM bseg
                       INTO gs_vendor
                       WHERE bukrs = it_bsis-bukrs " --> Add this
                       AND belnr = it_bsis-belnr
                       AND gjahr IN p_gjahr
                       AND buzei = '001'.    " --> Add this
*                       AND lifnr NE ''.     " --> Remove this
    SELECT SINGLE lifnr name1 stcd1
    FROM lfa1
    INTO gs_lfa1
    WHERE lifnr = gs_vendor-lifnr.
    <data>-lifnr = gs_lfa1-lifnr.
    <data>-sgtxt = gs_vendor-sgtxt.
    <data>-name1 = gs_lfa1-name1.
    <data>-stcd1 = gs_lfa1-stcd1.
    SELECT SINGLE wt_withcd
    FROM with_item
    INTO gs_item
    WHERE bukrs = it_bsis-bukrs  " --> Add this
    AND belnr = it_bsis-belnr
    AND gjahr IN p_gjahr.
    IF sy-subrc EQ 0.
      <data>-mwskz = gs_item.
    ENDIF.
    SELECT SINGLE ppnam usnam bldat
    FROM bkpf
    INTO gs_bkpf
    WHERE bukrs = it_bsis-bukrs   " --> Add this
    AND belnr = it_bsis-belnr
    AND gjahr IN p_gjahr.
    <data>-ppnam = gs_bkpf-ppnam.
    <data>-usnam = gs_bkpf-usnam.
    <data>-bldat = gs_bkpf-bldat.
  ENDLOOP.
ENDFORM.
Regards,
RS

Similar Messages

  • Requied code in abap to display sales order header text

    hi all,
    can anybody help me to send the code in abap to display sales order header text.

    Use FM, Read_text. Pass the necessary parameters like object name, id, language. You can see some of the infos in by clicking the scroll-like button.
    Reward points if useful

  • Optimization of code

    Hi ,
    Please help me to optimize this code w.r.t performance tuning.  thanks in advance
    SELECT   v~aufpl
             v~aplzl
             V~FSAVD
             V~FSEDD
             V~ISDD
             V~IEDD
             V~MGVRG
             V~GMNGA
             V~MEINH
             c~ltxa1
             c~objnr
             C~ARBID
             s~werks
             s~arbpl
             s~vornr
             s~aufnr
             s~matnr
             o~cy_seqnr
             o~dispo
             D~VERWE
             u~usr04
             u~use04
             INTO  TABLE itab
             FROM ( ( ( ( ( afvv AS v INNER JOIN afvc AS c  ON v~aufpl EQ c~aufpl and  v~aplzl eq c~aplzl )
             inner join s022 as s  on c~objnr eq s~objnr  ) INNER JOIN
             AFko  AS O ON v~AUFPL EQ O~AUFPL AND S~AUFNR EQ O~AUFNR AND S~MATNR EQ O~PLNBEZ ) INNER JOIN CRHD
             AS D ON C~ARBID EQ D~OBJID AND S~ARBPL EQ D~ARBPL AND S~WERKS EQ D~WERKS )
             inner join afvu as u on v~aufpl eq u~aufpl and v~aplzl eq u~aplzl )
                                          WHERE  s~vornr in s_vornr
                                          and    s~werks in s_werks
                                          and   s~arbpl in s_arbpl
                                          AND   D~VERWE  IN S_VERWE
                                          and    o~aufnr in s_aufnr
                                          and    o~cy_seqnr in s_seqnr
                                          and   o~dispo in s_dispo
                                          and   c~ltxa1 in s_ltxa1
                                          and  V~fsavd in p_fsavd
                                          and  V~Fsedd in p_fsedd.
    Anoop

    Please do not confuse a view which is only a definition in the data dictionary and a view which actually
    contains data in the database.
    My comment above was correct, if you read the statement in the comment above:
    >Unless it's a materialized view (which SAP doesn't support), the performance gain through a view is more or less insignificant
    >(as far as my experience goes). It may profit a little bit from datebase buffering though, but only if the view is frequently used.
    two different kinds of views !!
    And for the KNA1VV I see a join in the explain (DB6 database):
    SELECT FROM kna1vv :
        0 SELECT STATEMENT ( Estimated Costs =  2,292E+03 [timerons] )
               1 RETURN
                   2 MSJOIN
                       3 [O] FETCH KNA1
                           4 IXSCAN KNA1~0 #key columns:  1
                       5 <i> FILTER
                           6 FETCH KNVV
                               7 IXSCAN KNVV~0 #key columns:  1
    same for DD03VV now on Oracle
    SELECT STATEMENT ( Estimated Costs = 11 , Estimated #Rows = 201 )
            5 COUNT STOPKEY
              Filter Predicates
                4 TABLE ACCESS BY INDEX ROWID DD03L
                  Estim. CPU-Costs = 4.509 Estim. IO-Costs = 0
                    3 NESTED LOOPS
                      ( Estim. Costs = 10 , Estim. #Rows = 201 )
                      Estim. CPU-Costs = 133.703 Estim. IO-Costs = 10
                        1 TABLE ACCESS FULL DD02L
                          ( Estim. Costs = 2 , Estim. #Rows = 69.173 )
                          Estim. CPU-Costs = 39.023 Estim. IO-Costs = 2
                          Filter Predicates
                        2 INDEX RANGE SCAN DD03L~1
                          Search Columns: 2
                          Estim. CPU-Costs = 1.824 Estim. IO-Costs = 0
                          Access Predicates
    There are materialized views, but I doubt that this is valid performance optimization in most cases.
    Siegfried

  • Access code  for abap

    Hi everyone,
    Can you please guys post the access code for abap to mscagin at yahoo com
    thanks
    sri

    What do you mean by access code? Is this the same as a developer key?

  • T.code for ABAP Varaints

    Hi,
    Can anybody tell me the transaction code for ABAP varaints.
    In Se38 , Giving a program name and selecting the radiobutton varaints and click on display.
    We get  varaints screen. I need the transaction code for that screen.
    Regards,
    Sai

    Hi,
    This screen is only called from function module RS_VARIANT_SCREEN (easily found by using 'where-used').  This in turn is called from a number of places (SE38, SA38 etc) but I don't know of a transaction that goes to the variant screen directly.
    After all, the screen is only used if you populate the program name first, like in SE38 for example.
    Regards,
    Nick

  • Program Name which helps to hide the code of abap program

    Hello Experts,
              Could anybody help me in finding the name of the program on running which we can hide the CODE OF Abap program

    Here´s a snippet demonstrating how to hide the ABAP code of a given program
    REPORT z_hide_abap
      NO STANDARD PAGE HEADING.
    DATA: gt_code(72)  TYPE c OCCURS 0,
          gv_code      LIKE LINE OF gt_code,
          gt_code2(72) TYPE c OCCURS 0.
    PARAMETERS: program LIKE sy-repid.
    START-OF-SELECTION.
      READ REPORT program INTO gt_code.
      IF sy-subrc NE 0.
        MESSAGE e398(00) WITH 'Report' program 'not found.'.
    *   ATTENTION:
    *   READ REPORT on a hidden source code return SY-SUBRC=8 !!!
      ENDIF. "IF sy-subrc NE 0
      READ TABLE gt_code INDEX 1 INTO gv_code.
    * append *special* 1st line to hide cource code
      APPEND '*@#@@[SAP]' TO gt_code2.
      LOOP AT gt_code INTO gv_code.
        APPEND gv_code TO gt_code2.
      ENDLOOP.
      INSERT REPORT program FROM gt_code2.
    Reward points if helpful.

  • Can somebody tell me what is g-code in abap language

    hi,
    please help me about  g-code in abap language.
    thank u,
    subhasis,.

    I think,
    g-code means custom code.
    Custom one's will be started with Z, however Z is pronounced as "Zee".
    So, this seems to be relevant to customs.
    You may post this issue in ABAP group to get appropriate answer.
    warm regards
    sairam akundi

  • Change code in ABAP debugger mode ?

    Hello ABAP Experts,
    How to change the code in the abap Debugger mode.
    Suggestions appreciated.
    Thanks,
    BWer

    You can not change the code in ABAP debugger. But you can change the value of variable/ internal table / structure in ABAP Debugger. Also you can not change the constant and if you are debugging the function module, you can not change the import parameters while debugging.
    Regards,
    Pratik

  • Sudoku code in ABAP

    Hi,
    every one
    plz send sudoku code in ABAP as it is very urgent
    my mail id is [email protected]
    send screen downloded files also

    Check this link to get all details -
    http://forum.codecall.net/database-database-programming/121-sudoku-can-solved-using-sql-take-look.html
    Re: Just a wild idea
    http://www.di-mgt.com.au/src/sudoku.bas.html
    http://www.di-mgt.com.au/sudoku.html#source

  • HTML code to ABAP in WD for OCI

    Hello All,
    How can I convert the below code in ABAP. The example below is what needs to be generated by the catalog engine, after the user is done with picking items in his shopping basket. But, this code is in ITS in HTML format and I need to accomplish similar task in ABAP. Kindly let me know how can I do this in ABAP.
    <HTML>
    <HEAD>
    SAP Open Catalog Interface: HTML - Example
    <BODY bgcolor="#DED6C2">
    <FORM action="<%=Request.QueryString("HOOK_URL")%>" method=post target=_top>
    <input type="hidden" name="NEW_ITEM-VENDOR[1]" value = "1768">
    <input type="hidden" name="NEW_ITEM-VENDORMAT[1]" value = "648570">
    <input type="hidden" name="NEW_ITEM-MANUFACTCODE[1]" value = "4711">
    <input type="hidden" name="NEW_ITEM-MANUFACTMAT[1]" value = "4712">
    <input type="hidden" name="NEW_ITEM-EXT_QUOTE_ITEM[2]" value = "">
    <input type="hidden" name="NEW_ITEM-EXT_PRODUCT_ID[2]" value = "">
    <input type="submit" value="Transfer Items to B2B shopping basket" id=submit1 name=submit1><br>
    </FORM>
    </BODY>
    </HTML>
    Thks & Rgds,
    Hemal
    Edited by: Hemal Gandhi on Jan 11, 2010 7:27 PM

    hi ,
    u donot need to create this code in webdynpro
    in ur WDA ( transaction SE80) , create a View
    go to the layout tab , right click on the Root Element Container and choose insert element .
    create the similar layout as u have for ur HTML
    in ur Context tab , create a context node and as many context attributes under it as there are input fields
    bind the Value property of ur Input field to the context attribute
    now ur layout is created ..
    now create a application for ur application , choose test , and ur layout wud be dispalyed in a browser
    choose View->Source ,u can see  the similar HTML code
    regards,
    amit

  • How do i optimize the code

    Here is the code for indexing.
    i want to optimize the code.
    please give me some suggestions.
    thank you
    mitesh...
    package search_engine;
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    import java.awt.*;
    import javax.swing.*;
    public class Indexer implements Runnable
    public static boolean stopFlag=true;
    String dirName="c:/search/repository";
    File file=new File(dirName);
    String fList[]=file.list();
    FileReader indCountRead;
    StreamTokenizer countTok;
    public void run()
                   int fileNum;
                   try{
    FileReader indCountRead=new FileReader("c:/search/resources/indexcount.txt");
    StreamTokenizer countTok=new StreamTokenizer(indCountRead);
    countTok.resetSyntax();
                             countTok.wordChars(33,65535);
                             countTok.whitespaceChars(0,' ');
                             countTok.eolIsSignificant(false);
    countTok.nextToken();
    fileNum=Integer.parseInt(countTok.sval);
    indCountRead.close();
                        while(stopFlag && fileNum <= fList.length)
         String s="c:/search/repository/doc"+fileNum+".txt";
         FileReader fr;
                        StreamTokenizer tok;
                        Table tab;
                        try
                                  fr=new FileReader(s);
                                  tok=new StreamTokenizer(fr);
                                  tok.resetSyntax();
                                  tok.wordChars(33,65535);
                                  tok.whitespaceChars(0,' ');
                                  tok.eolIsSignificant(false);
              //FrameMain.indFrame.jTextFieldFile.setText("File:"+s);
                             tab=new Table();
                                  tok.nextToken();
         String s1=tok.sval;
                                  while(tok.nextToken()!=tok.TT_EOF)
                                       //FrameMain.indFrame.jTextFieldToken.setText("Token:"+tok.toString());
         if(tab.avoidToken(tok.sval)==false)
                                       if(tab.matchedRecord(tok.sval,s1)==false)
                                            tab.insertRecord(tok.sval,s1);
                                       else tab.updateRecord(tok.sval,s1);
                             }//while end
    }//end of try
    catch(IOException e)
    //System.out.println("File Error1"+e.getMessage());
    //FrameMain.indFrame.jTextFieldFile.setText("ERROR:"+e.getMessage());
                                  fileNum++;
                   }//end outer while     
    //IndexerFrame.jTextFieldFile.setText("");
    //FrameMain.indFrame.jTextFieldToken.setText("");
    //FrameMain.indFrame.jButtonStop.setEnabled(false);
    //FrameMain.indFrame.jButtonRun.setEnabled(false);
    //FrameMain.indFrame.jLabelWarning.setText("");
                             FileWriter indCountWrite=new FileWriter("c:/search/resources/indexcount.txt",false);
                             Integer count=new Integer(fileNum);
                             indCountWrite.write(count.toString(),0,count.toString().length());
                             indCountWrite.close();     
    if (fileNum>fList.length)
    //IndexerFrame.jLabelPop.setText("ALL FILES INDEXED !! ");
    stopFlag=true;
                   }//end of outer try
    catch(Exception e)
              //FrameMain.indFrame.jTextFieldFile.setText("ERROR:"+e.getMessage());
         }//end of run
    }//end of indexer
              class Table
                        String connectionAddress=
                             "jdbc:odbc:mitesh";
                        Connection con;
                        Statement stmt;
                        ResultSet rs;
                        public boolean avoidToken(String token)
                        if(token.equalsIgnoreCase("is")||
                        token.equalsIgnoreCase("are")||
                        token.equalsIgnoreCase("am")||
                        token.equalsIgnoreCase("was")||
                        token.equalsIgnoreCase("were")||
                        token.equalsIgnoreCase("have")||
                        token.equalsIgnoreCase("has")||
                        token.equalsIgnoreCase("had")||
                        token.equalsIgnoreCase("may")||
                        token.equalsIgnoreCase("might")||
                        token.equalsIgnoreCase("must")||
                        token.equalsIgnoreCase("shall")||
                        token.equalsIgnoreCase("will")||
                        token.equalsIgnoreCase("would")||
                        token.equalsIgnoreCase("should")||
                        token.equalsIgnoreCase("can")||
                        token.equalsIgnoreCase("could")||
                        token.equalsIgnoreCase("ought")||
                        token.equalsIgnoreCase("to")||
                        token.equalsIgnoreCase("do")||
                        token.equalsIgnoreCase("did")||
                        token.equalsIgnoreCase("does")||
                        token.equalsIgnoreCase("a")||
                        token.equalsIgnoreCase("an")||
                        token.equalsIgnoreCase("the")||
                        token.equalsIgnoreCase("in")||
                        token.equalsIgnoreCase("of")||
                        token.equalsIgnoreCase("at")||
                        token.equalsIgnoreCase("as")||
                        token.equalsIgnoreCase("into")||
                        token.equalsIgnoreCase("for")||
                        token.equalsIgnoreCase("from")||
                        token.equalsIgnoreCase("while")||
                        token.equalsIgnoreCase("if")||
                        token.equalsIgnoreCase("then")||
                        token.equalsIgnoreCase("."))
                                  return true;
                        else
                                  return false;
              public void insertRecord(String key,String fileAddress)
                             String insertString;
                             insertString="insert into INDEXER"+
                             " values('"+key.toLowerCase()+"','"+fileAddress+"',1)";
              try
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//myDriver.ClassName");
              catch(java.lang.ClassNotFoundException e)
                        System.err.print("ClassNotFoundException: ");
                        System.err.println(e.getMessage());
              try
                        con=DriverManager.getConnection(connectionAddress,"",
                        stmt=con.createStatement();
                        stmt.executeUpdate(insertString);
                        stmt.close();
                        con.close();
              catch(SQLException ex)
                        System.err.println("SQLException2: "+ex.getMessage());
              public boolean matchedRecord(String key,String fileAddress)
                        boolean flag=false;
                        String query;
                             query=" select KEYWORD,URLADDRESS from INDEXER "+
                             "where KEYWORD='"+key.toLowerCase()+"' and URLADDRESS='"+fileAddress+"'";
              try
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              catch(java.lang.ClassNotFoundException e)
                        System.err.print("ClassNotFoundException: ");
                        System.err.println(e.getMessage());
              try
                        con=DriverManager.getConnection(connectionAddress,"",
                        stmt=con.createStatement();
    rs=stmt.executeQuery(query);
                        if(rs.next()==true)
                             flag= true;
                             //System.out.println(flag);
                        else
                             flag= false;
                             //System.out.println(flag);
                        stmt.close();
                        con.close();
              catch(SQLException ex)
                        System.err.println( "SQLException3: "+ex.getMessage());
                        return flag;
              public void updateRecord(String key,String fileAddress)
                             String updateString;
                             updateString="update INDEXER"+
                             " set FREQUENCY=FREQUENCY+1" + " where KEYWORD='"+key.toLowerCase()+"' and URLADDRESS='"+fileAddress+"'";
              try
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              catch(java.lang.ClassNotFoundException e)
                        System.err.print("ClassNotFoundException: ");
                        System.err.println(e.getMessage());
              try
                        con=DriverManager.getConnection(connectionAddress,"",
                        stmt=con.createStatement();
                        stmt.executeUpdate(updateString);
                        stmt.close();
                        con.close();
              catch(SQLException ex)
                        System.err.println("SQLException4: "+ex.getMessage());
              }

    i even want to search for Html files.
    for that i have written a code for it, and we all call it as crawler.
    Please check out.
    thank you
    mitesh....
    import java.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
    import java.io.PrintWriter;
    public class Crawler{
    String ret;
    public static final String DISALLOW = "Disallow:";
    //public static final int SEARCH_LIMIT = 150;
    public static int fileCounter=1;
    CrawlTable tab;
         public Crawler() {
         tab=new CrawlTable();
         URLConnection.setDefaultAllowUserInteraction(false);
    Properties props= new Properties(System.getProperties());
    props.put("http.proxySet", "true");
    props.put("http.proxyHost", "webcache-cup");
    props.put("http.proxyPort", "8080");
    Properties newprops = new Properties(props);
    System.setProperties(newprops);
    String avoidHTMLTag(String s){
    StringBuffer sb=new StringBuffer();
    sb.ensureCapacity((s.length())*2);
    sb.append(s);
    int start = 0;
    int end = 0;
    try{
                             while (((start = sb.indexOf("<",start)) != -1)|((end = sb.indexOf(">",start)) != -1))
                             {          try{
                                            if(end<start)
                                                 continue;
                   sb.replace(start,end+1," ");
                   start--;
                   end=start;
                   catch( Exception ex)
                   System.out.println("ERROR:HTML FORMAT");
                             String s1=new String (sb);
         return s1;
    catch(Exception e)
    ret="WRONG HTML FORMAT";
    return "";
    }//end of htmlavoid
    public String start (String strURL)
         try
    FileReader clCountRead=new FileReader("c:/search/resources/crawlcount.txt");
    StreamTokenizer countTok=new StreamTokenizer(clCountRead);
    countTok.resetSyntax();
         countTok.wordChars(33,65535);
         countTok.whitespaceChars(0,' ');
         countTok.eolIsSignificant(false);
    countTok.nextToken();
    Crawler.fileCounter=Integer.parseInt(countTok.sval);
         clCountRead.close();
         //String strURL= CrawlerFrame.jTextFieldUrlAddress.getText();
         //out.println("CRAWLER STARTING....");
         //CrawlerFrame.jListURL.removeAll();
         int counter=0;
         boolean condition;
         URL url;
    try
              url = new URL(strURL);
              if (!tab.contains(strURL))
              // test to make sure it is robot-safe!
                   //if (robotSafe(url))
              tab.insertRecord(strURL);
    catch (MalformedURLException e)
              if(!strURL.equals("")){
    ret="ERROR: invalid URL " + strURL;
              //CrawlerFrame.jTextFieldUrlAddress.setText("");
         while(((condition=tab.isRecordFalse())||strURL.length()!=0))
                   if(condition)
                        strURL = tab.retrieveFirst();
                        //CrawlerFrame.jTextFieldUrlAddress.setText(strURL);
                        tab.updateRecord(strURL);
                        //setStatus("searching " + strURL);
                   //CrawlerFrame.jListURL.add(strURL);
                   else
                        strURL="";
                   if (strURL.length() == 0)
    //ret="Enter a starting URL then press RUN";
                   break;
              try
                   url = new URL(strURL);
              catch (MalformedURLException e)
    ret="ERROR: invalid URL " + strURL;
                   tab.delete(strURL);
                   //CrawlerFrame.jTextFieldUrlAddress.setText("");
                   strURL="";
                   continue;
              //tab.updateRecord(strURL);
              // CrawlerFrame.jListURL.add(strURL);
              // can only search http: protocol URLs
              if (url.getProtocol().compareTo("http") != 0)
                   break;
              // test to make sure it is before searching
              //if (!robotSafe(url))
                   //break;
              try
                   // try opening the URL
                   URLConnection urlConnection = url.openConnection();
                   urlConnection.setAllowUserInteraction(false);
                   InputStream urlStream = url.openStream();
                   String type
                   = URLConnection.guessContentTypeFromName(url.getFile());
                   if (type == null)
                   break;
                   if (type.compareTo("text/html") != 0)
                   break;
                   byte b[] = new byte[1000];
                   int numRead = urlStream.read(b);
                   String content = new String(b, 0, numRead);
                   while (numRead != -1)
                   //if (Thread.currentThread() != CrawlerFrame.clThread)
                        //break;
                   numRead = urlStream.read(b);
                   if (numRead != -1)
                        String newContent = new String(b, 0, numRead);
                        content += newContent;
    String fileString=content;
    fileString=fileString.replace('(',' ');
    fileString=fileString.replace(')',' ');
    fileString=fileString.replace(',',' ');
    fileString=fileString.replace('.',' ');
    fileString=fileString.replace(':',' ');
    fileString=fileString.replace('?',' ');
    fileString=fileString.replace('!',' ');
    fileString=fileString.replace('@',' ');
    fileString=fileString.replace('\'',' ');
    fileString=fileString.replace('\"',' ');
    fileString=strURL+" "+fileString;
    //fileString.replace('',' ');
    File htmlDoc=new File("c:/search/repository/doc"+fileCounter+".txt");
    FileWriter fp=new FileWriter(htmlDoc);
    fp.write(avoidHTMLTag(fileString));
    //fp.write(fileString);
    fp.close();
    fileCounter++;
                   urlStream.close();
                   //if (Thread.currentThread() != CrawlerFrame.clThread)
                   //break;
                   String lowerCaseContent = content.toLowerCase();
                   int index = 0;
                   while ((index = lowerCaseContent.indexOf("<a", index)) != -1)
                   if ((index = lowerCaseContent.indexOf("href", index)) == -1)
                        break;
                   if ((index = lowerCaseContent.indexOf("=", index)) == -1)
                        break;
                   //if (Thread.currentThread() !=CrawlerFrame.clThread)
                        //break;
                   index++;
                   String remaining = content.substring(index);
                   StringTokenizer st
                   = new StringTokenizer(remaining, "\t\n\r\">#");
                   String strLink = st.nextToken();
                   URL urlLink;
                   try
                        urlLink = new URL(url, strLink);
                        strLink = urlLink.toString();
                   catch (MalformedURLException e)
                        //setStatus("ERROR: bad URL " + strLink);
                        tab.delete(strLink);
                        //CrawlerFrame.jTextFieldUrlAddress.setText("");
                        strURL="";
                        continue;
                        if (urlLink.getProtocol().compareTo("http") != 0)
                             break;
                        //if (Thread.currentThread() != CrawlerFrame.clThread)
                             //break;
                        try
                             // try opening the URL
                             URLConnection urlLinkConnection
                             = urlLink.openConnection();
                             urlLinkConnection.setAllowUserInteraction(false);
                             InputStream linkStream = urlLink.openStream();
                             String strType
                             = urlLinkConnection.guessContentTypeFromName(urlLink.getFile());
                             linkStream.close();
                             // if another page, add to the end of search list
                             if (strType == null)
                             break;
                             if (strType.compareTo("text/html") == 0) {
                             // check to see if this URL has already been
                             // searched or is going to be searched
                             if (!tab.contains(strLink))
                                  // test to make sure it is robot-safe!
                                  //if (robotSafe(urlLink))
                                  tab.insertRecord(strLink);
                        catch (IOException e)
                             ret="ERROR: couldn't open URL " + strLink;
                             continue;
                        if (strURL.length() == 0)
                        //ret="Enter a starting URL then press RUN";
                        /////return;
                        break;
                        }//end of try
                   } catch (IOException e)
                        ret="ERROR1: couldn't open URL " + strURL;
              tab.delete(strURL);
              //CrawlerFrame.jTextFieldUrlAddress.setText("");
              strURL="";
              continue;
         }//end while
         //setStatus("done");
    //CrawlerFrame.jButtonStop.setEnabled(false);
    //CrawlerFrame.jButtonRun.setEnabled(true);
    FileWriter clCountWrite=new FileWriter("c:/search/resources/crawlcount.txt",false);
              Integer count=new Integer(fileCounter);
              clCountWrite.write(count.toString(),0,count.toString().length());
              clCountWrite.close();
    //CrawlerFrame.clThread = null;
         }//end of try
         catch(Exception e)
              ret="ERROR:"+e.getMessage();
    return(ret);
    //end of run
    }//end of classCrawler
    class CrawlTable
    String connectionAddress="jdbc:odbc:mitesh";
         Connection con;
         Statement stmt;
         ResultSet rs;
         public void insertRecord(String urlAddress)
              String insertString;
              insertString="insert into CRAWLER (URLADDRESS,ISCRAWLED)"+
              " values('"+urlAddress+"',false)";
    try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException e)
              System.err.print("ClassNotFoundException: ");
              System.err.println(e.getMessage());
    try
    con=DriverManager.getConnection(connectionAddress,"","");
              stmt=con.createStatement();
              stmt.executeUpdate(insertString);
              stmt.close();
              con.close();
    catch(SQLException ex)
              System.err.println("SQLException2: "+ex.getMessage());
    public void delete(String urlAddress)
              String deleteString;
              deleteString="delete from CRAWLER where URLADDRESS='"+urlAddress+"'";
    try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException e)
              System.err.print("ClassNotFoundException: ");
              System.err.println(e.getMessage());
    try
    con=DriverManager.getConnection(connectionAddress,"","");
              stmt=con.createStatement();
              stmt.executeUpdate(deleteString);
              stmt.close();
              con.close();
    catch(SQLException ex)
              System.err.println("SQLException2: "+ex.getMessage());
    public boolean isRecordFalse()
         boolean flag=false;
         String query;
              query=" select URLADDRESS from CRAWLER "+
              "where ISCRAWLED=false";
    try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException e)
              System.err.print("ClassNotFoundException: ");
              System.err.println(e.getMessage());
    try
    con=DriverManager.getConnection(connectionAddress,"","");
              stmt=con.createStatement();
    rs=stmt.executeQuery(query);
              if(rs.next()==true)
                   flag= true;
                   //System.out.println(flag);
              else
                   flag= false;
                   //System.out.println(flag);
              stmt.close();
              con.close();
    catch(SQLException ex)
              System.err.println( "SQLException3: "+ex.getMessage());
              return flag;
    public String retrieveFirst()
         String query,s="";
              query=" select URLADDRESS from CRAWLER where "+
              "ISCRAWLED=false order by SERIAL";
    try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException e)
              System.err.print("ClassNotFoundException: ");
              System.err.println(e.getMessage());
              return null;
    try
    con=DriverManager.getConnection(connectionAddress,"","");
              stmt=con.createStatement();
    rs=stmt.executeQuery(query);
              if(rs.next()==true)
              s=rs.getString("URLADDRESS");
              stmt.close();
              con.close();
    catch(SQLException ex)
              System.err.println( "SQLException3: "+ex.getMessage());
              return null;
              return s;
    public boolean contains(String strURL)
         boolean flag=false;
         String query;
              query=" select URLADDRESS from CRAWLER "+
              "where URLADDRESS='"+strURL+"'";
    try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException e)
              System.err.print("ClassNotFoundException: ");
              System.err.println(e.getMessage());
    try
    con=DriverManager.getConnection(connectionAddress,"","");
              stmt=con.createStatement();
    rs=stmt.executeQuery(query);
              if(rs.next()==true)
                   flag= true;
                   //System.out.println(flag);
              else
                   flag= false;
                   //System.out.println(flag);
              stmt.close();
              con.close();
    catch(SQLException ex)
              System.err.println( "SQLException3: "+ex.getMessage());
              return flag;
    public void updateRecord(String urlAddress)
              String updateString;
              updateString="update CRAWLER"+
              " set ISCRAWLED=true" + " where URLADDRESS='"+urlAddress+"'";
    try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException e)
              System.err.print("ClassNotFoundException: ");
              System.err.println(e.getMessage());
    try
    con=DriverManager.getConnection(connectionAddress,"","");
              stmt=con.createStatement();
              stmt.executeUpdate(updateString);
              stmt.close();
              con.close();
    catch(SQLException ex)
              System.err.println("SQLException4: "+ex.getMessage());
    }

  • SY - System fields and return codes in ABAP

    Hi
    I'm new to ABAP, where do I find what the meaning of the system field return codes are ?
    example SY-SUBRC returns a number of codes 0, 2, 4, 8 etc what do they mean.
    Is there a resource somewhere that provides this information for all the system fields.
    I have searched high and low and have found little, they must be defined somwhere ?
    cheers Hugh

    Here is a listing of all of the system fields.
    http://help.sap.com/saphelp_scm50/helpdata/en/7b/fb96c8882811d295a90000e8353423/frameset.htm
    As for what the return codes( 0, 4, 8) for SY-SUBRC mean,  that is a little tricky.  The meanings of the values are dependent on what statement was used previously. They would mean different things when used with different statements.  For example, if you check SY-SUBRC after a FIND statement, the return code value 4, would mean something different than if you had check the SY-SUBRC value after doing an OPEN DATASET.  So you need to look at the specific statements in help.sap.com and see what it says about the SY-SUBRC values for each statement.
    http://help.sap.com/saphelp_scm50/helpdata/en/43/41341147041806e10000000a1553f6/frameset.htm
    Regards,
    Rich Heilman

  • Code in abap query

    hi.
    i need to create an ABAP/sap query. when i created the InfoSet i used logical db-pnp.
    if i want to get only the employees which entered my organization during the last month where should i add the ABAP code, under which section => extras -> code. i have there several options - data, initialization, at selection-screen output, start of selection etc, what to choose??????????
    please help me,
    thanks,
    Ami

    Hi,
       You can write the code in START-OF-SELECTION comparing dates.
        Can you please explain what actually your requirement is?
            When run a query, only the data which satisfies the selection criteria are displayed.
    Reward points to all useful answers.
    Regards,
    Satish

  • Generated code WebDynpro ABAP

    Hi all,
    I am setting up a tool that counts the number of specific lines written for a SAP project, for KPI purpose. It is already working for reports, includes, functions (group and functions), classes, BSP applications and so on....
    I am now looking for a way to count the lines of codes written in a Webdynpro ABAP application. Does anyone knows where is the code generated? In what format (classes, reports) ?
    Quick and Helpful answers will be highly rewarded.
    Yann

    Hi Yann,
    Code will be generated as class. IF you want the class name of current webdynpro component  that is generated, right click on the webdynpro component -> select check -> extended syntax check. New window will be opened in which program name will be specified. Remove the "" ==CP" suffix and remaining part is the class name of the current webdynpro component.
    Thanks,
    Prashanth

  • How to insert code in ABAP program ( Z program) by ABAP coding.

    Hello,
    In ABAP is there any way to insert some code lines into an existing ABAP program (Z*) , We will insert in masse some code lines into a liste of program automatically ?
    Thanks in advance

    Hi,
    This thing you can achieve by using the Code Template . If you are using New ABAP editor you can in the bottom right side after the scrolling bar. Click on that add the code you need to insert .
    Hope this might help you.
    With Regards,
    Sumodh.P

Maybe you are looking for

  • Could not create pool connection with MySql

    When starting weblogic server I obtain the following error message when the conection pool for a MySql database should be established. What's the mistake I am doing? #The examples in the weblogic.properties put a "server=DEMO to the props. What is th

  • "Could not ascertain code page" Error.

    Hello, I have created an program for getting FI docs from BSEG table and downloading into excel file after doing some processing on the fetched data. The job, if run as a dialog process, works ok. But if scheduled to run in the background, gives the

  • Unable to download using download manager

    i want to know how to download oracle 10g r2(10.2.0.1.0) using download manager.i have used getright and flashget but no use.in getright i am getting a error message and in flashget i got a downloaded file of only 4kb.can please anyone help me.. i am

  • Although javascript is enabled zoo paradise game tells me to enable it

    i am trying to play the game zoo paradise on Facebook. it doesn't start and it tells me "if you have the latest flash but still see this message,please make sure javascript in enabled on your browser." Javascript on my Firefox is enabled and i downlo

  • No Profit Center defaulted to posted FI doc-HELP!

    Hi Gurus, An FI doc was posted w/o Profit Center,  because we found-out that posting comes first before config.   Therefore when we view KE5T,  said posted doc didn't take effect. Currently the pd. for the posted doc was already closed.  How can we c