Delete records from internal table

hi all,
i want to delete records from intenal table which are starting with a particular starting number .
eg internal table
10000
20000
90000
91000
92000
88880
i want delete the records starting with 9 i.e. 90000 91000 92000.
Thanks in Adv
        RAJ

You can test this piece of code.
DATA:
i_tab TYPE STANDARD TABLE OF mara,
wa_tab TYPE mara.
wa_tab-matnr = '1000'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '1001'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '1002'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '1003'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '2001'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '3001'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
wa_tab-matnr = '4010'.
APPEND wa_tab TO i_tab.
CLEAR wa_tab.
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Aug 8, 2008 4:49 PM

Similar Messages

  • Deleting records from internal tabl

    Hi All,
    Here i need delete records from one internal table, from another internal table. both contains same field as name1, so here , i need to delete records from t_itab , the records which are existed in t_itab1.
    first internal table t_itab contains
    vinesh01
    vinesh02
    vinesh03
    vinesh04
    second internal table t_itab1 contains
    vinesh01
    vinesh02
    here i need to delte t_itab1 entries from t_itab.
    regards,
    vinesh.

    Hi,
    try this code.
    first internal table t_itab contains
    vinesh01
    vinesh02
    vinesh03
    vinesh04
    second internal table t_itab1 contains
    vinesh01
    vinesh02
    loop at t_itab1.
    loop at t_itab.
    if t_itab-name1 = t_itab1-name1.
    delete t_itab.
    (OR)
    delete itab where t_itab-name = t_itab1-name.
    endif.
    endloop.
    endloop.
    regards.
    sriram.

  • Delete records from internal table using another internal table

    HI,
    I have two internal tables itab1 and itab2 which have same records initially.Later some records of itab2 are deleted .Then i want to delete those records from itab1 also ie,those records not found in itab2 .Is there any method other than looping.
    So that itab1 again becomes equal to itab2.
    Thanks in advance.
    Sowmya.

    Soumya,
    Itab1 , Itab2 .
    Before deleting the records from itab2  move those records to one more internal table itab3.
    Now you have deleted records  of itab2  in itab3.
    SORT ITAB3,ITAB1 by your main key field.
    LOOP AT itab3.
      READ TABLE ITAB1 WITH KEY key field = itab3-
      keyfield.
    IF sy-subrc EQ 0.
    DELETE itab1 where keyfield eq itab3-keyfield.
    ENDIF.
    ENDLOOP.

  • Deleting records from internal table.

    Hello Friends,
    I have done F1 on delete and also went through the forum . I want to do a delete effectively as it involves huge amount of data ..
    Lets cosider I have two internal tables ITAB 1 and ITAB 2 .
    ITAB 1 has 10000 records  having two key fields
    ITAB2 has 1000 records having the same two key fields in it .
    THe other fields are different .
    Now I want to perform an operation where for corresponding  1000 records in ITAB2 I must delete the records in ITAB1 and result in ITAB 1 must be 10000 - 1000 = 9000 records.
    Which could be the most effecient way to do this.?
    Comradely,
    K.Sibi

    Are you sure that the keys are all unique? That is non trivial with internal tables.
    If yes, then you should define itab1 as a hashed table or copy into a hashed table.
    LOOP AT itab2
        READ TABLE itab1 WITH TABLE KEY ...
        IF ( sy-subrc = 0 ).
          DELETE itab1 WITH TABLE KEY ...
        ENDIF
    ENDLOOP.
    You can also use sorted tables and delete with index, will be somewhat slower. Or standard table with REAB BINARY SEARCH and DELETE with index.
    If the uniqueness is unclear, then you must change the order and LOOP itab1first and comletely, because the same key can appear several times.
    A READ without BINARY SEARCH will kill you, i.e. the above recommendation is incorrect.
    Siegfried

  • To delete duplicate records from internal table

    hi friends,
    i have to delete records from internal table based on following criterion.
    total fields are 7.
    out of which  if 4 fields are same and 5th field is different,then both records must be deleted.
    in case all five fields are same,the program should do nothing.
    for example.
    if there are 3 records as follows
    a1 b1 c1 d1 e1 f g
    a1 b1 c1 d1 e2 w r
    a1 b1 c1 d1 e1 j l
    then first two records should be deleted as four fields are same but fifth(e) field differs.
    but third record should remain as it is evenif first five fields are same for first and third record.
    values of last two fields need not to be consider for deleting the records.

    LOOP AT ITAB.
      V_FILED5 = ITAB-F5. "to compare later
      V_TABIX = SY-TABIX. "used to delete if condition not matches
      READ TABLE ITAB WITH KEY F1 = ITAB-F1
                               F2 = ITAB-F2
                               F3 = ITAB-F3
                               F4 = ITAB-F4.
      IF SY-SUBRC = 0.
        IF ITAB-F5 <> V_FIELD5.
    *--both the records to be deleted,as Field5 is different.
          DELETE ITAB INDEX SY-TABIX. "deletes that record
          DELETE ITAB INDEX V_TABIX. "deletes the current record
        ENDIF.
      ENDIF.
    ENDLOOP.
    Message was edited by: Srikanth Kidambi
    added comments
    Message was edited by: Srikanth Kidambi

  • How to choose in Delete Duplicates from internal table?

    Now I need to delete Duplicates from internal table,
    So at first I sort
    than I delete duplicate
    Sort itab1 BY Company_Code  Asset_No Capital_Date.
          DELETE ADJACENT DUPLICATES FROM itab1 COMPARING Company_Code  Asset_No  Capital_Date
    Company_Code
    Asset_No
    Capital_Date
    Remark
    BC35
    1515593
    20021225
    Helen
    BC35
    1515593
    20021225
    Common Asset
    BC35
    1515594
    20030109
    Judy
    BC35
    1515594
    20030109
    Common Asset
    But here comes my problem~If I want to delete the Common Asset in Remark Column,how I let it choose the right one to do it?

    Hi Jack
    Try the below coding..
    Report zsamp.
    types: begin of t_tab,
            comp_code(4) type c,
            ***_no(7) type n,
            cap_date type d,
            remark type string,
            end of t_tab.
    data: i_tab type TABLE OF t_tab,
           w_tab type t_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515593'.
    w_tab-cap_date = '20021225'.
    w_tab-remark = 'Helen'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515593'.
    w_tab-cap_date = '20021225'.
    w_tab-remark = 'Common Asset'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515594'.
    w_tab-cap_date = '20030109'.
    w_tab-remark = 'Judy'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515594'.
    w_tab-cap_date = '20030109'.
    w_tab-remark = 'Common Asset'.
    append w_tab to i_tab.
    sort i_tab by remark.
    delete ADJACENT DUPLICATES FROM i_tab COMPARING remark.

  • How to update Records from Internal table to u2018Zu2019 table?

    Hi Friends,
    How to update Records from Internal table to u2018Zu2019 table.
    I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
    ( my internal table & u2018 Zu2019 table structures are same.)
    Thanking you.
    Regards,
    Subash

    Hi,
    loop at internal table.
    modify <Z- table > from values < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    endloop.
    or
    UPDATE <Z- table > from table < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    Prabhudas

  • Delete records from multiple table

    Hi,
    I need to delete records from multiple tables using a single delete statement. Is it possible ? If so please let me know the procedure.
    Kindly Help.
    Thanks,
    Alexander.

    Hi Tim,
    Syntax of DELETE statement does not allow for multiple tables to be specified in this way. Infact, none of the DMLs allow you to specify table names like this.
    Technically, there are other ways of deleting from multiple tables with one statement.
    1. "Use a trigger":
    What was probably meant by this is that you have a driving-table on which you create a on-delete trigger. In this trigger, you write the logic for deleting from other tables that you want to delete from.
    This does mean a one-time effort of writing the trigger. But the actual DML operation of deleting from all the tables would be simply triggered by a delete on driving-table.
    2. Dynamic SQL:
    Write a PL/SQL code to open a cursor with table-names from which you want the data to be deleted from. In the cursor-for loop, write a dynamic SQL using the table-name to delete from that table.
    3. Using Foreign-Key constraint with Cascade-Delete:
    This I feel is a more 'cleaner' way of doing this.
    Having to delete data from multiple tables means that there is some kind of parent-child relationship between your tables. These relationships can be implemented in database using foreign-key constraints. While creating foreign-key constraint give the 'on delete cascade' clause to ensure that whenever data is deleted from parent-table, its dependent data is deleted from child-table.
    Using foreign-key constraint you can create a heirarchy of parent-child relationships and still your DELETE would be simple as you would only have to delete from parent-table.
    IMPORTANT: Implementing foreign-key constraints would also impact other DML operations that you should keep in mind.

  • Inserting records from internal table to database table

    Hi all,
    i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
    1) insert one by one record from internal table
    loop at itab.
    insert ztable from wa.
    endloop.
    2) insert total records at a time
    INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or let me know if any other statement is there with high performance.
    i internal table contains nearly 40000 records.
    thanks.

    Hi,
    Insert the entire table at atime rather than a record so as to increase the performance.
    you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or
    MODIFY ZPRODUCT FROM TABLE GI_AFPO.
    Regards,
    Raj.

  • Delete matching records from internal table

    I have two internal tables.
    say :
    1)zsd80
    2)i_vbrk
    i want to delete records from i_vbrk which are not in zsd80.
    this is my code. but it shows dump error after executing. please help.
    LOOP AT i_zsd80 INTO zsd80.
                LOOP AT i_konv INTO w_konv FROM w_index.
                  IF w_konv-kschl NE zsd80-kschl.
                    DELETE i_konv FROM w_konv.
                  ENDIF.
                ENDLOOP.
              ENDLOOP.

    Hi,
    Do like this...
    1. Loop at the where u want to delete..
    2. store the sy-index...
    3. read the other table....
    4. if nothing found  in read then delete that index...
    LOOP AT i_vbrk.
      TABIX = SY-TABIX.
      READ TABLE zsd80 WITH KEY .......
      IF SY-SUBRC NE 0.
        DELETE IT_VBRK INDEX TABIX.
      ENDIF.
    ENDLOOP.
    regards
    Sukriti.....
    Edited by: Sukriti Saha on Nov 3, 2008 1:19 PM

  • How to delete records from MTL_SYSTEM_ITEMS table

    Hello Experts,
    BANNER
    =======
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    PL/SQL Release 8.1.7.4.0 - Production
    CORE     8.1.7.0.0     Production
    TNS for IBM/AIX RISC System/6000: Version 8.1.7.4.0 - Production
    NLSRTL Version 3.4.1.0.0 - Production
    I am working on Oracle Apps - 11.5.8 version.
    I have some doubts in deleting the records from MTL_SYSTEM_ITEMS table.
    There are few records which have junk characters and currently resides in table.
    I need to delete those records.
    But as per the approach; we should not delete any data directly from MTL table as it would cause huge impact.
    I have followed the below approach; but didnt worked out well.
    Script
    =======
    1)
    I have modified the below parameter in the MTL_SYSTEM_ITEMS_INTERFACE table --> SET_PROCESS_ID =0,TRANSACTION_TYPE ='DELETE',PROCESS_FLAG=1 .
    Apart from that; everything remains the same as in MTL_SYSTEM_ITEM table.
    2) Called the "Import Items" concurrent program.
    It got successfully completed. But record still exists in MTL_SYSTEM_ITEMS_INTERFACE table
    Your help is highly appreciated.
    Insert into MTL_SYSTEM_ITEMS_INTERFACE
       (SET_PROCESS_ID ,TRANSACTION_TYPE,PROCESS_FLAG ,INVENTORY_ITEM_ID, ORGANIZATION_ID, LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE, CREATED_BY, LAST_UPDATE_LOGIN,
    SUMMARY_FLAG, ENABLED_FLAG, DESCRIPTION, BUYER_ID, SEGMENT1, ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE9, ATTRIBUTE15, PURCHASING_ITEM_FLAG, SHIPPABLE_ITEM_FLAG,
    CUSTOMER_ORDER_FLAG, INTERNAL_ORDER_FLAG, SERVICE_ITEM_FLAG, INVENTORY_ITEM_FLAG, ENG_ITEM_FLAG, INVENTORY_ASSET_FLAG, PURCHASING_ENABLED_FLAG,
    CUSTOMER_ORDER_ENABLED_FLAG, INTERNAL_ORDER_ENABLED_FLAG, SO_TRANSACTIONS_FLAG, MTL_TRANSACTIONS_ENABLED_FLAG, STOCK_ENABLED_FLAG, BOM_ENABLED_FLAG, BUILD_IN_WIP_FLAG,
    REVISION_QTY_CONTROL_CODE, CATALOG_STATUS_FLAG, RETURNABLE_FLAG, TAXABLE_FLAG, QTY_RCV_EXCEPTION_CODE, ALLOW_ITEM_DESC_UPDATE_FLAG, RECEIPT_REQUIRED_FLAG,
    RFQ_REQUIRED_FLAG, QTY_RCV_TOLERANCE, LIST_PRICE_PER_UNIT, PRICE_TOLERANCE_PERCENT, ENFORCE_SHIP_TO_LOCATION_CODE, ALLOW_SUBSTITUTE_RECEIPTS_FLAG,
    ALLOW_UNORDERED_RECEIPTS_FLAG, DAYS_EARLY_RECEIPT_ALLOWED, DAYS_LATE_RECEIPT_ALLOWED, RECEIPT_DAYS_EXCEPTION_CODE, RECEIVING_ROUTING_ID, LOT_CONTROL_CODE,
    SHELF_LIFE_CODE, SHELF_LIFE_DAYS, SERIAL_NUMBER_CONTROL_CODE, RESTRICT_SUBINVENTORIES_CODE, RESTRICT_LOCATORS_CODE, LOCATION_CONTROL_CODE, ACCEPTABLE_EARLY_DAYS,
    PLANNING_TIME_FENCE_CODE, LEAD_TIME_LOT_SIZE, ACCEPTABLE_RATE_INCREASE, ACCEPTABLE_RATE_DECREASE, PLANNING_TIME_FENCE_DAYS, END_ASSEMBLY_PEGGING_FLAG,
    REPETITIVE_PLANNING_FLAG, BOM_ITEM_TYPE, PICK_COMPONENTS_FLAG, REPLENISH_TO_ORDER_FLAG, ATP_COMPONENTS_FLAG, ATP_FLAG, WIP_SUPPLY_TYPE, PRIMARY_UOM_CODE,
    PRIMARY_UNIT_OF_MEASURE, ALLOWED_UNITS_LOOKUP_CODE, COST_OF_SALES_ACCOUNT, SALES_ACCOUNT, DEFAULT_INCLUDE_IN_ROLLUP_FLAG, INVENTORY_ITEM_STATUS_CODE,
    INVENTORY_PLANNING_CODE, PLANNING_MAKE_BUY_CODE, FIXED_LOT_MULTIPLIER, ROUNDING_CONTROL_TYPE, CARRYING_COST, POSTPROCESSING_LEAD_TIME, PREPROCESSING_LEAD_TIME,
    FULL_LEAD_TIME, MRP_SAFETY_STOCK_CODE, FIXED_DAYS_SUPPLY, RESERVABLE_TYPE, VENDOR_WARRANTY_FLAG, SERVICEABLE_COMPONENT_FLAG, SERVICEABLE_PRODUCT_FLAG,
    PREVENTIVE_MAINTENANCE_FLAG, PRORATE_SERVICE_FLAG, INVOICEABLE_ITEM_FLAG, INVOICE_ENABLED_FLAG, MUST_USE_APPROVED_VENDOR_FLAG, OUTSIDE_OPERATION_FLAG,
    COSTING_ENABLED_FLAG, AUTO_CREATED_CONFIG_FLAG, CYCLE_COUNT_ENABLED_FLAG, ITEM_TYPE, SHIP_MODEL_COMPLETE_FLAG, MRP_PLANNING_CODE, RETURN_INSPECTION_REQUIREMENT,
    EFFECTIVITY_CONTROL, CHECK_SHORTAGES_FLAG, EQUIPMENT_TYPE, WEB_STATUS, BULK_PICKED_FLAG, LOT_STATUS_ENABLED, SERIAL_STATUS_ENABLED, LOT_SPLIT_ENABLED,
    LOT_MERGE_ENABLED, DUAL_UOM_CONTROL, SERV_BILLING_ENABLED_FLAG, LOT_TRANSLATE_ENABLED, DEFAULT_SO_SOURCE_TYPE, CREATE_SUPPLY_FLAG)
    Values
       (0,'DELETE',1,464852, 102, TO_DATE('01/11/2007 16:15:11', 'MM/DD/YYYY HH24:MI:SS'), 3443, TO_DATE('08/24/2006 14:13:03', 'MM/DD/YYYY HH24:MI:SS'), 3443, 21069398,
    'N', 'Y', 'pentaseal 6 X 320 SL-807202 Klockner', 4223, '0006320161', 'No', 'No', 'MRPM', 'N', 'Y', 'N', 'N', 'N', 'N', 'Y', 'N', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y',
    'Y', 'Y', 1, 'N', 'Y', 'N', 'WARNING', 'Y', 'Y', 'N', 3, 0, 20, 'WARNING', 'Y', 'Y', 5, 5, 'WARNING', 3, 1, 2, 1825, 1, 2, 2, 2, 10, 4, 1, 0, 0, 1, 'B', 'N', 4, 'N',
    'N', 'N', 'N', 2, 'EA', 'EACH', 3, 12916, 14296, 'Y', 'Uncosted', 6, 1, 100, 1, 2, 0, 5, 50, 1, 20, 1, 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', 'N', 'Y',
    'CMPC', 'N', 3, 2, 1, 'N', 2, 'UNPUBLISHED', 'N', 'N', 'N', 'N', 'N', 1, 'N', 'N', 'INTERNAL', 'Y');---------

    Hi,
    You have to use the delete item utility of Oracle Inventory.
    Responsibility: Inventory Superuser or similar
    Navigation: Items -> Delete Items
    Enter a meaningful name in the Group field.
    Type - Item
    Select the organization you want to delete the item from.
    In the details section, enter the items you want to delete.
    Once all the items entered, click on the "Chcek Group" button. This will validate whether the items you have entered are eligible to delete (i.e. whether any child record such as transactions exist).
    It will submit a concurrent program and once the program finishes you will be able to see the result in the Results tab.
    Finally click on the "Delete Group" button to delete the eligible items.
    Thanks,
    PS.

  • Delete records in internal table

    Hi,
    I have two internal tables  itab1 and itab2.
    I need to delete records from itab1 comparing the data from itab2. I tried to use the read statement within the main table.
    My problem is itab2  and itab1 has multiple records and all the records need to be checked from itab2 with itab1 before deleting the records from itab1.
    itab1 and itab2 have a common field 'runid' between them.
    How can this be accomplished?
    Thanks,
    VG

    >
    Venkat.O wrote:
    > Hi VG,
    > Try this way.
    >
    > data: tabix type sy-tabix.
    > loop at itab1.
    >   tabix = sy-tabix.
    >  _LOOP at itab2 where runid = itab1-runid._
    _>  if sy-subrc NE 0._
    >   delete itab1 index tabix.
    >  endif.
    > endloop.
    >
    > Thanks
    > Venkat.O
    Venkat, inside a loop a IF SY-SUBRC NE 0 doesn't make sense because you are in the loop only after the condition in WHERE clause is satisfied (which means SY-SUBRC is always 0). Also you are missing another ENDLOOP.

  • To get recent timestamp records from internal table

    hi all,
      i have one requirment
      i'm storing error messages in one table  while creating a sales order basing on timestamp
      which is of this format yyyy-mm-dd hh:mm:ss (random Number) 
      if i want to see the error messages left i'm getting all the error messages displayed
      for example i have created a sales order
    i got 10 errors displayed
    i have rectified 5 errors ... if i again display error messages the 10 errors + the 5 errors is getting displayed
    i want to display the 5 error messages only not the previous messages from internal table
    basing on timestamp current one has to displayed remaining has to deleted from internal table.

    I thought we used Sales Order Incompletion process for this....  but, if you're recreating the errors list every time you save with a create or change transaction then, at save, delete all rows in your error table for this document.   Then get your errors and update your db table from your current errors table.   From this viewpoint, the timestamp is not relevant.

  • Deleting entry from internal table

    Hi Experts,
    i have the following internal table:
    data :    it_result1            TYPE   crmt_object_guid_tab
    and work area
    data : wa_result1 type crmt_object_guid.
    i have to delete a guid from internal table based on some condition.
    loop at it_resul1 into wa_result1
    if lv_priority eq priority.
    delete     this entry from internal table.
    endif.
    endloop..
    i tried using  delete table it_result with table key CRMT_OBJECT_GUID = wa_result. but this is giving syntax error.
    what should be done to delete the entry?
    Thanks and regards
    Shilpi

    Hi
    Check Syntax for DELETE operator on pressing F1
    1. DELETE itab.
    2. DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
    3. DELETE TABLE itab [FROM wa].
    4. DELETE itab INDEX idx.
    5. DELETE itab FROM idx1 TO idx2.
    6. DELETE itab WHERE logexp.
    7. DELETE ADJACENT DUPLICATES FROM itab.
    delete table it_result with table key CRMT_OBJECT_GUID = wa_result
    this is wrong
    delete  it_result where CRMT_OBJECT_GUID = wa_result
    Edited by: Lavanya K on Apr 22, 2009 10:20 AM

  • Delete records from a Table. Please help

    Hello Folks,
    I have a table that contains 7 records with a Button to delete each record.
    I am unable to delete any records from the table.
    Please can some one just have a look into my class and tell me how
    to delete a record from the table when the button is clicked.
    You can also run this class from the your command Prompt
    Just cut this and create a new java file.
    Please assist.
    Code Attached :
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    public class ButtonTableFactory {
    public static JTable createTable(Vector data, String buttonLabel, ActionListener action) {
    return createTable(data.iterator(), buttonLabel, action);
    public static JTable createTable(
    Iterator dataIterator,
    String buttonLabel,
    ActionListener action) {
    DefaultTableModel model = new DefaultTableModel() {
    public boolean isCellEditable(int row, int col) {
    return col == 1;
    model.setColumnCount(2);
    while (dataIterator.hasNext()) {
    Object[] row = { dataIterator.next().toString(), null };
    model.addRow(row);
    DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
    columnModel.addColumn(new TableColumn(0, 100));
    columnModel.addColumn(new TableColumn(1, 80,
    new TableButtonCellRenderer(buttonLabel),
    new TableButtonCellEditor(buttonLabel, action)
    JTable table = new JTable(model, columnModel) {
    public void valueChanged(ListSelectionEvent e) {
    super.valueChanged(e);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    return table;
    private static class TableButtonCellRenderer implements TableCellRenderer {
    final JButton button;
    TableButtonCellRenderer(String buttonLabel) {
    button = new JButton(buttonLabel);
    public Component getTableCellRendererComponent(
    JTable table,
    Object value,
    boolean isSelected,
    boolean hasFocus, int row, int column) {
    return button;
    private static class TableButtonCellEditor
    extends AbstractCellEditor
    implements TableCellEditor, ActionListener {
    final JButton button;
    final ActionListener callback;
    TableButtonCellEditor(String buttonLabel, ActionListener callback) {
    button = new JButton(buttonLabel);
    this.callback = callback;
    button.addActionListener(this);
    public Component getTableCellEditorComponent(
    JTable table,
    Object value,
    boolean isSelected,
    int row, int column) {
    return button;
    public Object getCellEditorValue() {
    return null;
    public void actionPerformed(ActionEvent e) {
    button.getParent().requestFocus();
    callback.actionPerformed(e);
    static JTable table;
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector items = new Vector();
    for (int i = 0; i < 7; i++) {
    items.add(Integer.toString(i));
    ActionListener al = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.out.println("You clicked row: " + table.getSelectedRow());
    table = ButtonTableFactory.createTable(items, "More:", al);
    frame.getContentPane().add(new JScrollPane(table));
    frame.pack();
    frame.show();

    This will get you closer:
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    public class ButtonTableFactory {
        private JTable table;
        private Vector items = new Vector();
        private JScrollPane scroll;
        private JPanel main;
        private ActionListener al;
        public static JTable createTable(Vector data, String buttonLabel, ActionListener action) {
            return createTable(data.iterator(), buttonLabel, action);
        public static JTable createTable(
                Iterator dataIterator,
                String buttonLabel,
                ActionListener action) {
            DefaultTableModel model = new DefaultTableModel() {
                public boolean isCellEditable(int row, int col) {
                    return col == 1;
            model.setColumnCount(2);
            while (dataIterator.hasNext()) {
                Object[] row = { dataIterator.next().toString(), null };
                model.addRow(row);
            DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
            columnModel.addColumn(new TableColumn(0, 100));
            columnModel.addColumn(new TableColumn(1, 80,
                    new TableButtonCellRenderer(buttonLabel),
                    new TableButtonCellEditor(buttonLabel, action)
            JTable table = new JTable(model, columnModel) {
                public void valueChanged(ListSelectionEvent e) {
                    super.valueChanged(e);
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            return table;
        private static class TableButtonCellRenderer implements TableCellRenderer {
            final JButton button;
            TableButtonCellRenderer(String buttonLabel) {
                button = new JButton(buttonLabel);
            public Component getTableCellRendererComponent(
                    JTable table,
                    Object value,
                    boolean isSelected,
                    boolean hasFocus, int row, int column) {
                return button;
        private static class TableButtonCellEditor
                extends AbstractCellEditor
                implements TableCellEditor, ActionListener {
            final JButton button;
            final ActionListener callback;
            TableButtonCellEditor(String buttonLabel, ActionListener callback) {
                button = new JButton(buttonLabel);
                this.callback = callback;
                button.addActionListener(this);
            public Component getTableCellEditorComponent(
                    JTable table,
                    Object value,
                    boolean isSelected,
                    int row, int column) {
                return button;
            public Object getCellEditorValue() {
                return null;
            public void actionPerformed(ActionEvent e) {
                button.getParent().requestFocus();
                callback.actionPerformed(e);
        public void init() {
            main = new JPanel();
            main.setLayout(new BorderLayout());
            for (int i = 0; i < 7; i++) {
                items.add(Integer.toString(i));
            al = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("You clicked row: " + table.getSelectedRow());
                    items.remove(table.getSelectedRow());
                    buildTable(items);
            buildTable(items);
        public void buildTable(Vector items) {
            table = ButtonTableFactory.createTable(items, "More:", al);
            scroll = new JScrollPane(table);
            main.removeAll();
            main.add(scroll);
            main.revalidate();
            main.repaint();
        public JPanel getContent() {
            return main;
        public static void main(String[] args) {
            ButtonTableFactory factory = new ButtonTableFactory();
            factory.init();
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(factory.getContent());
            frame.setSize(300, 300);
            frame.setVisible(true);
    //        frame.pack();
    //        frame.show();
    }

Maybe you are looking for

  • Bridge vs Lightroom - Which do you use?

    I just subscribed to Creative Cloud am am learning how to use both Bridge and Lightroom. I've been using Apple's Aperture program to organize images, but I want to see how Lightroom stacks up and perhaps switch. I have so many things to figure out, i

  • Oracle OCI: Problem in Query with Date field

    Client compiled with OCI: 10.2.0.4.0 Server: Oracle9i Enterprise Edition Release 9.2.0.4.0 The problematic query is: SELECT CODIGO FROM LOG WHERE TEL = :telnumber AND DATE_PROC = '05-JUL-08'Table description: SQL>describe LOG; TEL NOT NULL VARCHAR2(1

  • Administration of many workspaces/developers/users

    Hello, I'm teaching basics of DB-application-development in a class scenario and would like to use APEX for that. Can someone give me a hint on how to set up an environment, so that I can perform specific administrative tasks in an efficient way? Stu

  • System crashes after thunderbird upgrade.

    Thunderbird made an auto-update. After that, whenever I try to run it, the system reboots.

  • Cross Join in SAP MDX using Web I

    Hi there,   I am facing an issue. I am currently using BO universe on the top of BW infocube. Now whenever i am dragging two dimensions from the universe in my web i report it is creating cross join , however whenever i add any key figures , it chang