INSERT works for only last record of the Internal table ...??

I am trying to insert data from an internal table JTAB to a Databse Table
in CRM. The name of the databse table in CRM is CRMD_PARTNER
For this i first declared an internal table JTAB with same structure as that of
the databse table CRMD_PARTNER
DATA: BEGIN OF JTAB OCCURS 0,
     INCLUDE STRUCTURE CRMD_PARTNER,
      END OF JTAB.
Then I filled my JTAB with the required entries. For filling the JTAB i am
getting data from couple of other tables and filling the internal table JTAB
     loop at ktab.
here i am filling values in JTAB and then i say APPEND JTAB.
        endloop.
     Till here every thing works well and my internal table JTAB has all values that
I need to insert to the CRMD_PARTNER table. Also my JTAB has vales for all primary key fields.
Now I write a condition like below.
if not jtab[] inital.
MODIFY CRMD_PARTNER from TABLE JTAB.
COMMIT WORK.
endif.
Here comes the problem...once this code is executed and once program totally executes...
i always see that only last record in JTAB is being inserted to the databse table CRMD_PARTNER.
When i check in the debugger ..i see that the loop is being executed only once
and the SY-TABIX of JTAB is being always set to the length of JTAB and
that is why only last  record is being inseretd to the table CRMD_PARTNER.
Now what should i do ..to insert all records of JTAB to CRMD_PARTNER table?
is there a way i can restet the SY-TABIX and make the modify statement work for all records of JTAB?
Finally i hardcoded the values in JTAB then i dont have any problem and all records of JTAB are being
inserted into the database table.
only if i am dynamically fetching the values into JTAB(by Putting in loop..endloop statements and
pushing values to JTAB and APPENDING JTAB ) i have a problem .
in this case also my JTAB is being correctly filled with values ..but when i try to
insert theses values to CRMD_PARTNER with MODIFY stmt ..only always last record is being inserted.
i tried with INSERT instead of MODIFY and i am getting runtime error.
kindly pease help.
Regards,
Jessica Sam

yes a@s i am really struggling from last 3 days.
I actually want to create a sales order in CRM and want to
assign ship to party for each line item in a sales order in CRM
for that i used the standard bapi BAPI_BUSPROCESSND_CREATEMULTI and i am able
to create an order successfully, but i see that the ship toparty
that i give at header is being copied to each line item.
but this is not what is expected.
So finally i tracked in which table the ship to party gets stored in each line item
and then tried to insert the records directly into databse. and it worked
but only if i am hardcoding..but not when i am dynamically fecthing the values into JTAB for insertion,
Can yoy help ..if you have any idea why insert/modify is processing only last record?
any help will be highly appreciated.
Regards,
Jessica Sam

Similar Messages

  • Getting the last record from the internal table

    When we use a READ statement it always picks up the first record which fulfill its condition but in my case I want to pick up the last record that fulfills it condition
    I have a internal table like
    id     type
    N1      A
    N1      T
    N1      A
    N1      6 ----> LAST RECORD
    my code is
    read table itab wIth key id = netobjid.
    for eg if netobjid = N1 , then I want to read the last record that corresponds to N1 ie ID N1 TYPE - 6...
    How to do that?

    HI
    actually i have done same requirement like this ...
    Take  one count variable into your internal table ..you pass the number of records into cont variable for every time  u enter the loop .
    Sort the internal table with count variable descending . ( AS we cant sort the internal table with sy-tabix)
    Then use read statement with sy-index = 1 .
    USe below logic ,............
    data  :  count  type i value '0'.
    LOOP at int .
    count = count + 1 .
    endloop.
    sort int count descending .
    read int  with  index = 1 .

  • Read the last record of an internal table

    Hello All,
    I need to read the last entry of the internal table? Is it possible to achieve this without using loop - endloop?
    In the following example, I need to get the Batch '110776' and store it in a variable.
    ITAB:
    MATNR|CHARG
    010780|110770
    010780|110772
    010780|110773
    010780|110774
    010780|110775
    010780|110776
    Thanks.

    Use DESCRIBE to get the number of entires in variable last_entry
    and then use read table ....index last_entry

  • To delete the last line of the internal table

    How to delete the last line of the internal table.???????
    The list which gets displayed from the internal table adds a dummy line at the last which shows zeros and zeros.all the otheer selections are perfect.i just want to delete the last line which comes as zero zero.is there any way to do it...

    Quite Easy......Use Describe command to Count the Total Number of Table Lines, and then Delete the Last Line using Index.
    Data L like sy-tabix.
    Describe Table Itab Lines L.
    Delete itab index L.

  • How to insert record inside the internal table in below code

    Hi all,
    My requirement is to find the sub-total and need to insert in between the internal table.
    You can see the output ....where I want the sub-total F2 when 1 & 2 combindely , 3 , 4& 5 combindely .Please check it and let me know is it possible
    when i am using modification  it is not creating extra row inside the table instead it is modifying one row and putting the total there.
    For ex: the origianl output is
    F1   F2       F3
    A      1          1
    B      1          1
    F      2          1
    D      3          1
    E      4          1
    C      5          1
    We want to display all the total of f2 of 1-2 , 3 , 4-5
    so expcected output is
    F1   F2       F3
    A      1          1
    B      1          1
    F      2          1
         *              3  ->This is the sub-total of 1& 2 of f2
    D      3          1
            *           1 ->this is the sub-total of 3
    E      4          1
    C      5          1
          *             2 -> this is the sub-total of 4 & 5
    = space
    But coming output is
    A 1          1
    B 1          1
    *             3 -> it is modifying the F row and inserting the total .Total is comong correct but is shoule insert  instead of modifying the record!!
      *           1
    E  4          1
    *             2
    Please help how to insert the row total at the end of the chage of field
    Please find the below code ..Due to space problem i am attaching below
    Sas

    Here is the solution ....i Got the answer Thanks for your helping hands friends
    REPORT  YTEST_MODIFY.
    DATA: BEGIN OF ITAB OCCURS 1,
    TOT TYPE C,
    F1 TYPE C,
    F2 TYPE C,
    F3 TYPE I ,
    END OF ITAB.
    DATA: BEGIN OF JTAB OCCURS 1,
    F1 TYPE C,
    F2 TYPE C,
    F3 TYPE I ,
    END OF JTAB.
    START-OF-SELECTION.
      ITAB-F1 = 'A'.
      ITAB-F2 =  1.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'B'.
      ITAB-F2 =  1.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'C'.
      ITAB-F2 =  5.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'D'.
      ITAB-F2 =  3.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'E'.
      ITAB-F2 =  4.
      ITAB-F3 =  1.
      APPEND ITAB.
      ITAB-F1 = 'F'.
      ITAB-F2 =  2.
      ITAB-F3 =  1.
      APPEND ITAB.
      SORT ITAB BY F2.
      LOOP AT ITAB.
        WRITE:/1 ITAB-F1 ,
              8 ITAB-F2 ,
              10 ITAB-F3 .
      ENDLOOP.
      LOOP AT ITAB.
        IF ITAB-F2 = 1 OR ITAB-F2 = 2.
          ITAB-TOT = 1.
          MODIFY ITAB.
        ELSEIF ITAB-F2 = 3.
          ITAB-TOT = 3.
          MODIFY ITAB.
        ELSEIF ITAB-F2 = 4 OR ITAB-F2 = 5.
          ITAB-TOT = 4.
          MODIFY ITAB.
        ENDIF.
      ENDLOOP.
      SKIP 2.
      SORT ITAB BY TOT.
      DATA : L_SUM(2) TYPE C,
             L_ROW(2) TYPE C.
      LOOP AT ITAB.
        MOVE-CORRESPONDING ITAB TO JTAB.
        APPEND JTAB.
        L_SUM = L_SUM + ITAB-F3 .
        AT END OF TOT.
          CLEAR JTAB.
          JTAB-F3 = L_SUM .
          APPEND JTAB.
          CLEAR L_SUM.
        ENDAT.
      ENDLOOP.
      LOOP AT JTAB.
        WRITE:/1 JTAB-F1 ,
              8 JTAB-F2 ,
              10 JTAB-F3 .
      ENDLOOP.
    *  DATA: a TYPE i , b .
    *  LOOP AT itab.
    *    IF b = 0.
    *      a = a + itab-f3.
    *    ENDIF.
    *    AT END OF tot.
    *      MOVE space TO itab-f1.
    *      MOVE space TO itab-f2.
    *      MOVE a TO itab-f3.
    *      MODIFY itab .
    *      CLEAR a.
    *      b = 1.
    *    ENDAT.
    *    b = 0.
    *  ENDLOOP.
    *  LOOP AT itab.
    *    MOVE-CORRESPONDING itab TO jtab.
    *    APPEND jtab.
    *  ENDLOOP.
    *  ULINE.
    *  LOOP AT jtab.
    *    WRITE: / jtab-f1 , jtab-f2 , jtab-f3.
    *  ENDLOOP.

  • How to collect similar record from the internal table

    I need to collect exact matched records from 1 internal table to another internal table by searching 5 fields. I need to have records which are exactly matched for 5 fields. i have written a code wich is mention below it gave me only similar records but not 100% matched record.. would you like to help me. any correction, suggetion,. Will be great help to me.

    To get exact match of 5 records, do as follows.
    Check whether internal table gives only one record or not after READ statement.If internal table gives more than one entry for READ then the results will be improper.
    I think there is no need of READ statement on same internal table within LOOP. I commented the same in code.
    sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.
    loop at i_bp_p into wa_i_bp_p.
    *lv_tabix = sy-tabix.
    *read table i_bp_p index lv_tabix into wa_i_bp_p.read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber
    idtype = wa_i_bp_p-idtype binary search.
    if sy-subrc = 0.
    read table i_but000 into wa_but000 with key title = wa_i_bp_p-title
    initials = wa_i_bp_p-initials
    name_last = wa_i_bp_p-name_last binary search.
    if sy-subrc = 0.
    read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code
    rbcode = wa_i_bp_p-rbcode binary search.
    if sy-subrc = 0.
    move-corresponding wa_i_bp_p to i_bp_p100.
    append i_bp_p100.
    endif.
    endif.
    endif.
    endloop.
    sort i_bp_p100 by partner.
    loop at i_bp_p100.
    write : /10 i_bp_p100-partner,
    20 i_bp_p100-title,
    30 i_bp_p100-initials,
    40 i_bp_p100-name_last,
    53 i_bp_p100-idnumber,
    70 i_bp_p100-idtype,
    85 i_bp_p100-rbcode,
    95 i_bp_p100-f50code.
    endloop.
    sort i_bp_p by title initials name_last idnumber idtype f50code rbcode. "acc_num.
    loop at i_bp_p into wa_i_bp_p.
    lv_tabix = sy-tabix.
    read table i_bp_p index lv_tabix into wa_i_bp_p.
    if sy-subrc = 0.
    read table i_but0id into wa_but0id with key idnumber = wa_i_bp_p-idnumber
    idtype = wa_i_bp_p-idtype binary search.
    if sy-subrc = 0.
    read table i_but000 into wa_but000 with key title = wa_i_bp_p-title
    initials = wa_i_bp_p-initials
    name_last = wa_i_bp_p-name_last binary search.
    if sy-subrc = 0.
    read table i_but0is into wa_but0is with key f50code = wa_i_bp_p-f50code
    rbcode = wa_i_bp_p-rbcode binary search.
    if sy-subrc = 0.
    move-corresponding wa_i_bp_p to i_bp_p100.
    append i_bp_p100.
    endif.
    endif.
    endif.
    endif.
    endloop.

  • Insert a string at particular location in the internal table

    1. I have an internal table t_text of type bcsy_text , this internal table contains a few lines of HTML code
    2. I have a variable w_text of type string , this variable contains some text
    3. now the internal table t_text contains text:
    <!"<font size = "3.5" ><b>Comments:</b></font><br><br>***********<br><br><font size = "3.5" ><b>Thank You</b></font>">
    4. The text in the w_text comes from a text area on my module pool screen
    5. There is a push button SAVE on the same module pool screen
    6. now when I enter text in the text area and press the SAVE button then i want the text in the variable w_text to be inserted into the internal table at the location where i have marked *********** in my HTML code.
    How do i achieve this?
    <!-- **--> is not part of my HTML code.. i have written it because the HTML formatting appears on the screen if i dont comment it
    Edited by: DoshiAnkit on Sep 8, 2010 3:43 PM

    Ankit,
    You have to first determine which row of the internal table needs to be updated. Once you know which row, read that row into a variable using the READ statement and INDEX option.
    Once you have the row in a variable (WA_ROW) , you have to determine the position where you want to insert the w_text contents.
    Suppose that position is 123. Then, you can concatenate the first part of the row, w_text contents, and second part of the row into another variable (WA_NEW_ROW).
    CONCATENATE wa_row(123)
    w_text
    wa_row+123
    INTO wa_new_row
    SEPARATED BY SPACE.
    Finally, modify internal table contents with WA_NEW_ROW using the INDEX option.

  • Read the last record in the database table..

    Hi..
    I am new to ABAP. So i have one condition to read the address number field in the last record from database table by using the person number where clause field.
    But the person number is same for some the records.
    So can any tell me the logic for to read the addressnumber field in the last record of selected records from database where personnumber is equal to some thing.
    Please help me..
    Thanks
    venki

    Hi Venkat ,
    u mean to say
    person number  addressnumber
    aa1            0000000000001
    aa1            0000000000002
    aa1            0000000000003
    aa1            0000000000004
    aa2            0000000000021
    aa3            0000000000110
    if i have to read the addressnumber 00000000000004
    of the person number aa1
    u can go like
    data v_address number like addressnumber.
    sort itab by personnumber addressnumber
    loop at itab .
    at end of personnumber.
    move addressnumber to v_addressnumber ..
    endat.
    endloop.
    so using control break statements i can fetch the last record of my person number if at all the same person number is having more than one address number ..
    hope this helps,
    Regards,
    Vijay
    Message was edited by: Vijay

  • To split the records of the internal table and send in Packets to XI

    Hi All,
    I am executing the program in SAP. Program will send the material numbers to Oracle through XI and in turn we will get the corresponding data back to SAP. and this all data is written into the file.
    if records are more than 700 then XI will not able to get the data fully.
    So, solution for this is to send the data in packets.
    I want to write the logic like whenever the recods are more than 700, the first 700 records  will got to XI and rest of the records will go to XI after that. we are sending the material numbers to xi through proxy.
    Problem is : how to write the logic for this.
    suppose we have  executed the report for 1000 records, then it should generate 2 excel file in which first file shud contain 700 records, AND 2nd will contain rest of the 300 records.
    Regards,
    Mamta

    Hi Mamta,
    Please try this code. This is to split records as 255 length and u can change it as ur requirement by simply changing l_offset value as 700.
    DATA: l_length TYPE i,                               
          l_lines TYPE i,                                
          l_pos TYPE i VALUE 0,                          
          l_offset TYPE i VALUE 255,                     
          l_part TYPE i,                                 
          l_lastpart TYPE i.                             
    CLEAR i_etabfinal.                                   
    REFRESH i_etabfinal.                                 
    *Split etab line as multiple 255 char length of lines
    LOOP AT i_etab INTO x_etab.                          
    l_length = STRLEN( x_etab-result ).                  
    l_lines = l_length DIV l_offset.                     
    l_lines = l_lines + 1.                               
    l_part = l_offset.                                   
    DO l_lines TIMES.
    *To avoid spaces                                    
    IF l_part LT l_length.                               
    x_etabfinal-line = x_etab-result+l_pos(l_offset).    
    APPEND x_etabfinal TO i_etabfinal.                   
    l_pos = l_pos + l_offset.                            
    l_part = l_pos + l_part.                             
    ELSE.                                                
    l_lastpart = l_length - l_pos.                       
    x_etabfinal-line = x_etab-result+l_pos(l_lastpart).  
    APPEND x_etabfinal TO i_etabfinal.                   
    ENDIF.                                               
    endloop.
    Regards,
    Subbu

  • Counting the Multiple Occurence of a record in the internal Table-Urgent

    Hi,
    I have an internal table with the following values
    a
    a
    a
    b
    b
    b
    c
    c
    I need to print a-2
                         b-3
                         c-2
    How do i accomplish this? i.e.,I need to count the multiple occurence of a field.Any input on this will be of great help.
    Thanks and Regards,
    Pavithra

    Hi,
    Find the piece of code below it can help you:
    data: begin of itab occurs 0,
               field1 type c,
               field2 type i,
            end of itab.
    data: itab2 like table of itab occurs 0 with header line.
    data: count type i.
    start-of-seleciton.
    itab-field1 = a.
    append itab.
    itab-field1 = a.
    append itab.
    itab-field1 = a.
    append itab.
    itab-field1 = b.
    append itab.
    sort itab by field1.
    loop at itab.
      count = count + 1.
    at end of field1.
      clear itab2.
      itab2-field1 = itab-field1.
      itab2-field2 = count.
      append itab2.
    endat.
    endloop.
    Dispaly output table.
    loop at itab2.
      write:/ itab2-field1, itab2-field2.
    endloop.
    Reward the points if it is helpful.

  • Selecting the last record from a database table

    In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key.  In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first.  I know I can use an internal table to sort the records first and then retrieve the right value.   But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step?  Thanks!

    hi,
    tables:mara.
        data: begin of it_mara occurs 0,
                matnr like mara-matnr,
                meins like mara-meins,
                mtart like mara-mtart,
                end of it_mara.
    select-options:s_matnr for mara-matnr.
    select matnr
              meins
              mtart
    from mara
    into table it_mara
    where matnr in s_matnr.
    if not it_mara[] is initial.
    sort it_mara by matnr descending.
    read table it_mara index 1.
    endif.
    then you get the last record of the select statement.
    reward points if useful,
    venkat.

  • Inserting one table records to the another table

    Hi There
    Though i don't close the Result set , My program throws the following Exception
    java.sql.SQLException: ResultSet is ClosedBecause of this my program Inserts only one record in the another table
    My code is this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.DefaultComboBoxModel.*;
    import javax.swing.table.*;
    import java.sql.*;
    import java.util.*;
    public class SearchBook extends JDialog implements ActionListener
         private JComboBox comboCategory,comboAuthor;
         private JSplitPane splitpane;
         private JTable table;
         private JToolBar toolBar;
         private JButton btnclose, btncancel;
         private JPanel panel1,panel2,panel3,panel4;
         private JLabel lblCategory,lblAuthor;
         private Container c;
         //DefaultTableModel model;
         Statement st;
         ResultSet rs;
         Vector v = new Vector();
         public SearchBook (Connection con)
              // Property for JDialog
              setTitle("Search Books");
              setLocation(40,110);
              setModal(true);
              setSize(750,450);
              // Creating ToolBar Button
              btnclose = new JButton(new ImageIcon("Images/export.gif"));
              btnclose.addActionListener(this);
              // Creating Tool Bar
              toolBar = new JToolBar();
              toolBar.add(btnclose);
              try
                   st=con.createStatement();
                   rs =st.executeQuery("SELECT BCat from Books Group By Books.BCat");
                   while(rs.next())
                        v.add(rs.getString(1));
              catch(SQLException ex)
                   System.out.println("Error");
              panel1= new JPanel();
              panel1.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.HORIZONTAL;
              lblCategory = new JLabel("Category:");
              lblCategory.setHorizontalAlignment (JTextField.CENTER);
              c.gridx=2;
              c.gridy=2;
              panel1.add(lblCategory,c);
              comboCategory = new JComboBox(v);
              comboCategory.addActionListener(this);
              c.ipadx=20;
              c.gridx=3;
              c.gridwidth=1;
              c.gridy=2;
              panel1.add(comboCategory,c);
              lblAuthor = new JLabel("Author/Publisher:");
              c.gridwidth=2;
              c.gridx=1;
              c.gridy=4;
              panel1.add(lblAuthor,c);
              lblAuthor.setHorizontalAlignment (JTextField.LEFT);
              comboAuthor = new JComboBox();
              comboAuthor.addActionListener(this);
              c.insets= new Insets(20,0,0,0);
              c.ipadx=20;
              c.gridx=3;
              c.gridy=4;
              panel1.add(comboAuthor,c);
              comboAuthor.setBounds (125, 165, 175, 25);
              table = new JTable();
              JScrollPane scrollpane = new JScrollPane(table);
              //panel2 = new JPanel();
              //panel2.add(scrollpane);
              splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,scrollpane);
              splitpane.setDividerSize(15);
              splitpane.setDividerLocation(190);
              getContentPane().add(toolBar,BorderLayout.NORTH);
              getContentPane().add(splitpane);
         public void actionPerformed(ActionEvent ae)
              Object obj= ae.getSource();
              if(obj==comboCategory)
                   String selecteditem = (String)comboCategory.getSelectedItem();
                   displayAuthor(selecteditem);
                   System.out.println("Selected Item"+selecteditem);
              else if(obj==btnclose)
                   dispose();     
              else if(obj==comboAuthor)
                   String selecteditem1 = (String)comboAuthor.getSelectedItem();
                   displayavailablity(selecteditem1);
                   //System.out.println("Selected Item"+selecteditem1);
                   System.out.println("Selected Author"+selecteditem1);
         private void displayAuthor(String selecteditem)
              try
              {     Vector data = new Vector();
                   rs= st.executeQuery("SELECT BAuthorandPublisher FROM Books where BCat='" + selecteditem + "' Group By Books.BAuthorandPublisher");
                   System.out.println("Executing");
                   while(rs.next())
                        data.add(rs.getString(1));
                   //((DefaultComboBoxModel)comboAuthor.getModel()).setVectorData(data);
                   comboAuthor.setModel(new DefaultComboBoxModel(data));
                   //rs.close();
              catch(SQLException ex)
                   System.out.println("ERROR");
         private void displayavailablity(String selecteditem1)
                   try
                        Vector columnNames = new Vector();
                        Vector data1 = new Vector();
                        String bname,bauthor,bcategory,bref1,bavail,bid;
                        int bref,mid,num;
                        rs = st.executeQuery("SELECT * FROM Books where BAuthorandPublisher='" + selecteditem1 +"'");     
                        while(rs.next())
                             bname = rs.getString("BName");                         
                             bauthor = rs.getString("BAuthorandPublisher");
                             bcategory = rs.getString("BCat");
                             bref = rs.getInt("BRef");
                             if(bref==1)bref1="Yes";
                             else bref1 = "No";
                             mid = rs.getInt("Mid");
                             if(mid==0)bavail="Available";
                             else bavail="Issued To:"+mid;
                             bid = rs.getString("BId");
                             System.out.println("Book Name is::"+bname);
                             System.out.println("Book Availabilty::"+bavail);
                             num = st.executeUpdate("insert into BSearch Values('"+bid+"','"+bname+"','"+bcategory+"','"+bauthor+"','"+bavail+"','"+bref1+",')");
                             System.out.println("Inseted in the table");
                        /**ResultSetMetaData md= rs.getMetaData();
                        int columns =md.getColumnCount();
                        String booktblheading[]={"Book ID","Book NAME","BOOK AUTHOR/PUBLISHER","REFRENCE","CATEGORY"};
                        for(int i=1; i<= booktblheading.length;i++)
                             columnNames.addElement(booktblheading[i-1]);
                        while(rs.next())
                             Vector row = new Vector(columns);
                             for(int i=1;i<=columns;i++)
                                  row.addElement(rs.getObject(i));
                             data1.addElement(row);
                             //System.out.println("data is:"+data);
                        ((DefaultTableModel)table.getModel()).setDataVector(data1,columnNames);
                        //DefaultTableModel model = new DefaultTableModel(data1,columnNames);
                        //table.setModel(model);
                        //rs.close();
                        //st.close(); */
                   catch(SQLException ex)
                        ex.printStackTrace();
    }Please help me Friends. I am very new to java. otherwise give me some suggestion to implement this idea in effective manner.
    Thank you for your service
    Cheers

    Hi
    Here i am Posting My programs code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.DefaultComboBoxModel.*;
    import javax.swing.table.*;
    import java.sql.*;
    import java.util.*;
    public class SearchBook extends JDialog implements ActionListener
         private JComboBox comboCategory,comboAuthor;
         private JSplitPane splitpane;
         private JTable table;
         private JToolBar toolBar;
         private JButton btnclose, btncancel;
         private JPanel panel1,panel2,panel3,panel4;
         private JLabel lblCategory,lblAuthor;
         private Container c;
         //DefaultTableModel model;
         Statement st,st1;
         ResultSet rs,rs1,rs2;
         Vector v = new Vector();
         public SearchBook (Connection con)
              // Property for JDialog
              setTitle("Search Books");
              setLocation(40,110);
              setModal(true);
              setSize(750,450);
              // Creating ToolBar Button
              btnclose = new JButton(new ImageIcon("Images/export.gif"));
              btnclose.addActionListener(this);
              // Creating Tool Bar
              toolBar = new JToolBar();
              toolBar.add(btnclose);
              try
                   st=con.createStatement();
                   rs =st.executeQuery("SELECT BCat from Books Group By Books.BCat");
                   while(rs.next())
                        v.add(rs.getString(1));
              catch(SQLException ex)
                   System.out.println("Error");
              panel1= new JPanel();
              panel1.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.HORIZONTAL;
              lblCategory = new JLabel("Category:");
              lblCategory.setHorizontalAlignment (JTextField.CENTER);
              c.gridx=2;
              c.gridy=2;
              panel1.add(lblCategory,c);
              comboCategory = new JComboBox(v);
              comboCategory.addActionListener(this);
              c.ipadx=20;
              c.gridx=3;
              c.gridwidth=1;
              c.gridy=2;
              panel1.add(comboCategory,c);
              lblAuthor = new JLabel("Author/Publisher:");
              c.gridwidth=2;
              c.gridx=1;
              c.gridy=4;
              panel1.add(lblAuthor,c);
              lblAuthor.setHorizontalAlignment (JTextField.LEFT);
              comboAuthor = new JComboBox();
              comboAuthor.addActionListener(this);
              c.insets= new Insets(20,0,0,0);
              c.ipadx=20;
              c.gridx=3;
              c.gridy=4;
              panel1.add(comboAuthor,c);
              comboAuthor.setBounds (125, 165, 175, 25);
              table = new JTable();
              JScrollPane scrollpane = new JScrollPane(table);
              //panel2 = new JPanel();
              //panel2.add(scrollpane);
              splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,scrollpane);
              splitpane.setDividerSize(15);
              splitpane.setDividerLocation(190);
              getContentPane().add(toolBar,BorderLayout.NORTH);
              getContentPane().add(splitpane);
         public void actionPerformed(ActionEvent ae)
              Object obj= ae.getSource();
              if(obj==comboCategory)
                   String selecteditem = (String)comboCategory.getSelectedItem();
                   displayAuthor(selecteditem);
                   System.out.println("Selected Item"+selecteditem);
              else if(obj==btnclose)
                   dispose();     
              else if(obj==comboAuthor)
                   String selecteditem1 = (String)comboAuthor.getSelectedItem();
                   displayavailablity(selecteditem1);
                   //System.out.println("Selected Item"+selecteditem1);
                   System.out.println("Selected Author"+selecteditem1);
         private void displayAuthor(String selecteditem)
              try
              {     Vector data = new Vector();
                   rs1= st.executeQuery("SELECT BAuthorandPublisher FROM Books where BCat='" + selecteditem + "' Group By Books.BAuthorandPublisher");
                   System.out.println("Executing");
                   while(rs1.next())
                        data.add(rs1.getString(1));
                   //((DefaultComboBoxModel)comboAuthor.getModel()).setVectorData(data);
                   comboAuthor.setModel(new DefaultComboBoxModel(data));
              catch(SQLException ex)
                   System.out.println("ERROR");
         private void displayavailablity(String selecteditem1)
                   try
                        Vector columnNames = new Vector();
                        Vector data1 = new Vector();
                        String bname,bauthor,bcategory,bref1,bavail,bid;
                        int bref,mid,num;
                        //rs2.Open();
                        rs = st.executeQuery("SELECT * FROM Books where BAuthorandPublisher='" + selecteditem1 +"'");     
                        boolean tr=true;
                        while(rs.next())
                             if(true)
                                  bname = rs.getString("BName");                         
                                  bauthor = rs.getString("BAuthorandPublisher");
                                  bcategory = rs.getString("BCat");
                                  bref = rs.getInt("BRef");
                                  if(bref==1)bref1="Yes";
                                  else bref1 = "No";
                                  mid = rs.getInt("Mid");
                                  if(mid==0)bavail="Available";
                                  else bavail="Issued To:"+mid;
                                  bid = rs.getString("BId");
                                  System.out.println("Book Name is::"+bname);
                                  System.out.println("Book Availabilty::"+bavail);
                             num = st1.executeUpdate("insert into BSearch Values('"+bid+"','"+bname+"','"+bcategory+"','"+bauthor+"','"+bavail+"','"+bref1+",')");
                             System.out.println("Inseted in the table");
                   catch(SQLException ex)
                        ex.printStackTrace();
    }Thank you for your service

  • How to know the internal table's last record

    Dear friends,
    Just I want to know my internal table last records, Ex:
    I am having the records in my internal table like this:
    Itab-col1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    I want to know and print the last record, it maybe n number of records in my itab.
    If I used at last within a loop but it dosn't work its taking the all *** in header.
    How to know which is the last record in my internal table.
    Thanks,
    Sridhar.

    hi,
    sridher reddy
    1st describe ur table i.e read the number of entries in the table .....
    data : count type i.
    DESCRIBE TABLE <table name > LINES count.
    READ TABLE <table name > INDEX count.
    write : <table name>-<fieldname>.......... .
    by this way u can print the last record of your table

  • How to get the last record of an internall table ....

    Hi All..
    i want to get the last record of an internal table itab, and i want the the value of the last record.

    Hi,
         Use describe statment.
    data: lv_line type i.
        Describe table itab lines lv_line.
        read table itab into wa_itab index lv_line.
    regards,
    Santosh Thorat

  • @Inserting Records in an Internal Table

    Hi,
    How can I Insert records in an internal table..such that i can insert the records somewhere in the middle based on the entry in a field?

    INSERT wa INTO TABLE itab INDEX idx .
    Effect
    This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.
    If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.
    An exception that cannot be handled is raised when:
    idx contains a value less than or equal to 0
    A line to be inserted would cause a duplicate entry in tables with a unique table key
    A line to be inserted would disrupt the sort order of sorted tables
    Within a LOOP loop, you can omit the addition INDEX. Each line to be inserted is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.

Maybe you are looking for

  • Purchase Info record   error

    hi SAP, In purchase info record in deletion flag i tick the check delete info record. if i do this values from info record will not come when i create purchase order. What are the other ways the values are coming to my purchase order if the info reco

  • Create a PDF. with Illustrator that Adobe Reader Can Edit

    How do I export a file to .PDF with a single line of text that can be edited with Adobe Reader. I'm Creating a sign template and the their is a spot for the price that needs to be changed every week with Adobe Reader. Is this possible

  • Can anybody run Oralce(8.1.6) demo code ?

    Can anybody run Oralce(8.1.6) demo code about embedded SQL without any problem? It seems that I'm unlucky. I need to write a small embedded SQL program (Window 2000 / VC++6 compiler) that can connect to the Oracle server on the LAN. So I try to begin

  • Clickable ads in PDF

    I am making clickable ads within a PDF that I am going to post on my company's website. I have been successful with all of the ads but one. When I type the url in and then I try to click on the ad it has somehow added more words, that look like the p

  • "FOR REC IN CURSOR(PARAMETERS) LOOP" command does not work. Why?

    Hi to all. It's a pleasure to receive your help. In "FOR REC IN CURSOR(PARAMETERS) LOOP" command although the query return value does not enter the loop. Sounds simple, but I'm not seeing the flaw... Suggestions? Version: Oracle Database 10g Enterpri