URGENT: To change the where condition in select query at runtime ?

Hi,
I have to develop a report, 4 which I have created a selection screen with 7 Input Parameters whose value is to be filled by the user while executing the report.
On the basis of this I do the desired selection of output.
But the problem is that how do I write my select Query(where condition) if the user enetrs only 2 Input parameters or 3 or whatever he feels like.
Pls help me out...

hi,
check this sample code.
Here i am populating where condition at runtime.
DATA: V_WHERE TYPE STRING.
SELECTION-SCREEN BEGIN OF BLOCK INPUT WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN,
                 S_ERDAT FOR VBAK-ERDAT.
SELECTION-SCREEN END OF BLOCK INPUT.
START-OF-SELECTION.
  PERFORM POPULATE_WHERE.
  PERFORM GET_VBAK_DATA.
*&      Form  POPULATE_WHERE
*       Populate Where
FORM POPULATE_WHERE .
  IF NOT S_ERDAT[] IS INITIAL.
    CONCATENATE 'VBELN IN S_VBELN'
                'AND'
                'ERDAT IN S_ERDAT'
          INTO V_WHERE
          SEPARATED BY SPACE.
  ELSE.
    V_WHERE = 'VBELN IN S_VBELN'.
  ENDIF.
ENDFORM.                    " POPULATE_WHERE
*&      Form  GET_VBAK_DATA
*       GET VBAK DATA
FORM GET_VBAK_DATA .
  SELECT VBELN
         ERDAT
         VBTYP
         NETWR
         WAERK
         VKORG
         VTWEG
         SPART
    INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
    FROM VBAK
    WHERE VBELN IN S_VBELN
    AND   ERDAT IN S_ERDAT.
   WHERE (V_WHERE).
endform.
Regards
Sailaja.

Similar Messages

  • Regarding  dynamically assigning the where clause to select query

    hi,
      Please send the code regarding how to dynamically assign the where clause to select query.
    thanks in advance

    SELECT <fileds>
            INTO TABLE itab
            FROM dbase
            WHERE  condition.

  • How Can I Change the  Where Condition In the First SQL Query?

    SELECT IND_SSN, BEG_SVC_DT, END_SVC_DT,
    TRUNC(MONTHS_BETWEEN((TO_DATE('19'||END_SVC_DT,'YYYYMMDD')),BEG_SVC_DT)/12),
    mod(trunc(months_between((to_date('19'||end_svc_dt,'YYYYMMDD')),BEG_SVC_DT)),12),
    DECODE((SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1),-1,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -2,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -3,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -4,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -5,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -6,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -7,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -8,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -9,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -10,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -11,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -12,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -13,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -14,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -15,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -16,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -17,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -18,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -19,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -20,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -21,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -22,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -23,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -24,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -25,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -26,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -27,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -28,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -29,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -30,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    -31,((SUBSTR(END_SVC_DT,5,2)+ 31) - SUBSTR(BEG_SVC_DT,1,2)),
    30,0,
    (SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1))
    FROM SVC_OCCURRENCES
    WHERE end_svc_dt not in ('PRESENT')
    AND SUBSTR(END_SVC_DT,1,1) IN '9'
    AND SUBSTR(END_SVC_DT,5,2) NOT IN ('31')
    and (SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1) not in ('30')
    UNION
    SELECT IND_SSN, BEG_SVC_DT, END_SVC_DT, NULL, NULL, NULL
    FROM SVC_OCCURRENCES
    WHERE SUBSTR(END_SVC_DT,1,1) IN 'P'
    The above code works fine and I get the correct numeric values from the SQL
    query when the varchar2 end_svc_dt field is numeric however if I have encoded
    the word 'PRESENT' in the varchar2 end_svc dt field the SQL query aborts at
    the last statement in the WHERE condition. The beg_svc_dt field is a Date field.
    and (SUBSTR(END_SVC_DT,5,2) - SUBSTR(BEG_SVC_DT,1,2)+1) not in ('30')
    I get the following error message
    ERROR ORA-0722 INVALID NUMBER
    I encode the word 'PRESENT' in a varchar2 end_svc_dt field on an Oracle form. This is the only word that can be encoded.
    Is there some way that I can bypass the last statement in the where condition and
    compute the values from the SQL query without having the SQL query abort?
    Eventually I want to do this in a report. I know that this sounds strange but can it be done?

    The above code works fine and I get the correct
    numeric values from the SQL
    query when the varchar2 end_svc_dt field is numeric
    however if I have encoded
    the word 'PRESENT' in the varchar2 end_svc dt field
    the SQL query aborts at
    the last statement in the WHERE condition.Ouch!
    Storting dates in VARCHAR2 columns is bad practice, poor design and makes for horrible code.
    The beg_svc_dt field is a Date field.
    and (SUBSTR(END_SVC_DT,5,2) -
    SUBSTR(BEG_SVC_DT,1,2)+1) not in ('30')If it's a date field then why on earth are you trying to SUBSTR it. SUBSTR = sub-string i.e. take a sub section of a string not sub-date.
    I get the following error message
    ERROR ORA-0722 INVALID NUMBERAnd you're surprised by this?
    Is there some way that I can bypass the last
    statement in the where condition and
    compute the values from the SQL query without having
    the SQL query abort?Store your dates properly, use additional flag columns for non-date information and code your SQL properly.
    Eventually I want to do this in a report. I know
    that this sounds strange but can it be done?Yes, most things are possible.

  • How to formulate where clause in select query at runtime..??

    I am facing a problem..
    I have to generate a select query during runtime..For Ex: when user selects a row in an alv report, particular date field is to be read and another report is to be opened for that data..
    I know how to make drill down report but my problem is concatenating  date field...
    Plz tell a solution....

    Hi,
    Try like this....
    refresh : gt_tvarvc_temp[].                                       
      gt_tvarvc_temp[] = lt_tvarvc[].                                   
          loop at gt_tvarvc_temp into gs_tvarvc_temp
                                  where name = 'CREDIT_MEMO_DOC_TYPE'.  
            r_blart-sign = gs_tvarvc_temp-sign.                         
            r_blart-option = gs_tvarvc_temp-opti.                      
            r_blart-low = gs_tvarvc_temp-low.                           
            append r_blart.                                            
            clear r_blart.                                             
          endloop.                                                     
          concatenate 'BLART IN ' 'r_blart' into lv_condition
          separated by space.
    if not lv_customer_cond is initial.
          if lv_condition is initial.
            concatenate lv_customer_cond lv_condition
                into lv_condition separated by space.
          else.
            concatenate lv_condition 'AND' lv_customer_cond
                into lv_condition separated by space.
          endif.
        endif.
    select bukrs belnr gjahr appending corresponding fields        
                                        of table lt_potential_credits
                                        from bsid
                                        where (lv_condition).
    Hope its helps

  • Where condition in select query

    my requirement is this. I want to fetch some records
    from DB table. The field objnr has 12 characters.
    i will supply a substring of this field. the substring
    starts at the 3rd location of field.
    SELECT objnr FROM cosp INTO TABLE gt_itab
                  WHERE objnr like srch_str.
    how to do this? could u give me a possible solution?

    Then you're going to have to go at it this way
    TABLES: cosp.
    DATA:
      BEGIN OF gt_itab OCCURS 0,
        objnr      LIKE cosp-objnr,
      END OF gt_itab.
    DATA:
      wk_objnr      LIKE cosp-objnr,
      srch_str(22) VALUE '1000',
      ss_len       TYPE i.
    START-OF-SELECTION.
      ss_len = strlen( srch_str ).
      SELECT objnr FROM cosp INTO gt_itab-objnr.
        CHECK gt_itab-objnr+2(ss_len) = srch_str.
        APPEND gt_itab.
      ENDSELECT.
    Or this way.
    TABLES: cosp.
    DATA:
      BEGIN OF gt_itab OCCURS 0,
        objnr      LIKE cosp-objnr,
      END OF gt_itab.
    DATA:
      cntlarea(22)  TYPE c  VALUE '1000',
      wk_objnr      LIKE cosp-objnr,
      srch_str(50),
      ss_len       TYPE i.
    START-OF-SELECTION.
      CONCATENATE '%' cntlarea '%' INTO srch_str.
      ss_len = strlen( cntlarea ).
      SELECT objnr FROM cosp INTO gt_itab-objnr
        WHERE objnr LIKE srch_str.
        CHECK gt_itab-objnr+2(ss_len) = cntlarea.
        APPEND gt_itab.
      ENDSELECT.
    Edited by: Paul Chapman on May 29, 2008 8:33 AM

  • Variable in the where condition how?

    Hello Expert Abapers,
    how to use a variable in the where condition..
    select * from (Var_tab_name)
    into itab
    where (var1) = 'A'
    but i know this expression where (var1) is not allowed, but what is the alternative to this.
    Thanks for any suggestions.
    BWer

    Hi,
    <b>Dynamic Conditions</b>
    To specify a condition dynamically, use:
    SELECT ... WHERE (<itab>) ...
    where <itab> is an internal table with line type C and maximum length 72 characters. All of the conditions listed above except for selection tables, can be written into the lines of <itab>. However, you may only use literals, and not the names of data objects. The internal table can also be left empty.
    If you only want to specify a part of the condition dynamically, use:
    SELECT ... WHERE <cond> AND (<itab>) ...
    You cannot link a static and a dynamic condition using OR.
    You may only use dynamic conditions in the WHERE clause of the SELECT stateme
    example:
    data: begin of myselection occurs 0,
         line(72),
           end of myselection.
    data char(1) value 'A'.
    myselection-line = 'var1 = char'.
    append myselection.
    select * from (Var_tab_name)
    into itab
    where (myselection) .
    Message was edited by: Svetlin Rusev

  • Changing the where clause

    Hi all,
    Can anyone suggest an appropriate answer for this
    I want to change the where condition in Reports (Developer 2000) dynamically (in runtime)
    Thank you

    Hi,
    Try this in you pre-query trigger.
    -- if you want to add to the where clause do this
    -- first store the current where clause
    C_WHERE := get_block_property('your_block', default_where);
    IF <condition> THEN
         c_where := 'desired_condition'||' AND '||C_where;
    -- append your condition to the existing one.
    END IF;
    set_block_property('your_block', default_where,c_where);
    or if you want to totally replace it just use the set_block_property in the trigger.
    Hope this helps.
    Bob

  • How to select data from a table using a date field in the where condition?

    How to select data from a table using a date field in the where condition?
    For eg:
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
                                                      and bdatu = '31129999'.
    thanks.

    Hi Ramesh,
    Specify the date format as YYYYMMDD in where condition.
    Dates are internally stored in SAP as YYYYMMDD only.
    Change your date format in WHERE condition as follows.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and bdatu = <b>'99991231'.</b>
    I doubt check your data base table EQUK on this date for the existince of data.
    Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and <b> bdatu <= '99991231'.</b>
    Thanks,
    Vinay
    Thanks,
    Vinay

  • How to Change the Document Condition Values in PO print

    HI,
    I have a requirement to change the document condition values in PO printout. We are using the copied form of MEDRUCK.
    Please tell me how can i change the Document Condition Values at run time.
    Thanks....

    hi
    hence you have copied standard script you cant able to change the driver program for this you have to use itcsy structure.
    go to the page window and select the window which you have the amount field. open the text editor of the windoiw here write
    /:           PERFORM CONTACT IN PROGRAM ZAMOUNT_ZF110_IN_AVIS1_C
    /:           USING &REGUH-ZALDT&
    /:           CHANGING &DT&
    /:           ENDPERFORM
    now create a report program with name  ZAMOUNT_ZF110_IN_AVIS1_C.
    and follow as the example program is .
    *&      Form  CONTACT
          text
         -->IN_TAB     text
         -->OUT_TAB    text
    FORM contact TABLES in_tab STRUCTURE itcsy
                       out_tab STRUCTURE itcsy.
      DATA : v_telf1 TYPE telf1.
      DATA : v_telfx TYPE telfx.
      DATA : v_adrnr TYPE ad_addrnum.
      DATA : v_flagcomm6 TYPE ad_flgcm06.
      DATA : v_datum(10) TYPE c.
      DATA : v_sydatum TYPE sy-datum.
      DATA : v_lifnr TYPE lifnr .         " Santosh Rawat , 19th Feb
      DATA : v_email TYPE ad_smtpadr .   " Santosh Rawat , 19th Feb
      LOOP AT in_tab.
        IF in_tab-name = 'REGUH-LIFNR'.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' " Santosh Rawat , 19th Feb
            EXPORTING
              input  = in_tab-value
            IMPORTING
              output = v_lifnr.
          SELECT SINGLE telf1 telfx adrnr FROM lfa1
            INTO (v_telf1, v_telfx, v_adrnr)
            WHERE lifnr = v_lifnr.
          SELECT SINGLE smtp_addr FROM adr6    " Santosh Rawat ,19th Feb
         INTO v_email WHERE ADDRNUMBER = v_adrnr. " Santosh Rawat ,19th Feb
         SELECT SINGLE flagcomm6 FROM adrc INTO v_flagcomm6
           WHERE addrnumber = v_adrnr.
        ELSEIF
          in_tab-name = 'REGUH-ZALDT' OR in_tab-name = 'REGUP-BLDAT'   .
          MOVE in_tab-value TO v_datum.
          REPLACE ALL OCCURRENCES OF '.' IN v_datum WITH ' '.
          CONDENSE v_datum.
          MOVE v_datum TO v_sydatum.
    *CALL FUNCTION 'CONVERSION_EXIT_INVDT_INPUT'
    EXPORTING
       input         = V_DATUM
    IMPORTING
      OUTPUT        = V_DATUM
          CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
            EXPORTING
              date_internal            = v_sydatum
            IMPORTING
              date_external            = v_datum
            EXCEPTIONS
              date_internal_is_invalid = 1
              OTHERS                   = 2.
          IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ENDIF.
      ENDLOOP.
      LOOP AT out_tab.
        IF out_tab-name = 'TEL'.
          MOVE v_telf1 TO out_tab-value.
        ELSEIF out_tab-name = 'FAX'.
          MOVE v_telfx TO out_tab-value.
        ELSEIF out_tab-name = 'EMAIL'.
          MOVE v_email TO out_tab-value.        " Santosh Rawat , 19th Feb
        ELSEIF out_tab-name = 'DT'.
          MOVE v_datum TO out_tab-value.
        ENDIF.
        MODIFY out_tab FROM out_tab.
    *MODIFY TABLE OUT_TAB .
      ENDLOOP.
    ENDFORM.             }
    reply for any query.
    regards,
    venkat.

  • Dynamic where condition in Select statement

    Hi,
    I have 10 fields on selection-screeen. In which ever field the user enters single values or ranges,i should pick that field dynamically and pass that field along with value range to Where condition of Select statement.How can i achieve this? Please help.
    Regards
    K Srinivas

    see the following example:
    data : begin of itab occurs 0,
             matnr like mara-matnr,
    end of itab.
    ypes: begin of ty_s_clause.
    types:   line(72)  type c.
    types: end of ty_s_clause.
    data : begin of gt_condtab occurs 0.
            include structure hrcond.
    data : end   of gt_condtab.
    FIELD-SYMBOLS <fs_wherecond> TYPE ty_s_clause.
    data:
      gt_where_clauses  type standard table of ty_s_clause
                        with default key.
    gt_condtab-field = 'MATNR'.
    gt_condtab-opera = 'EQ'.
    gt_condtab-low = '000000000000000111'.
    append  gt_condtab.
    clear  gt_condtab.
    call function 'RH_DYNAMIC_WHERE_BUILD'
      exporting
        dbtable         = space " can be empty
      tables
        condtab         = gt_condtab
        where_clause    = gt_where_clauses
      exceptions
        empty_condtab   = 01
        no_db_field     = 02
        unknown_db      = 03
        wrong_condition = 04.
    select matnr from mara into table itab where (gt_where_clauses).

  • Help for changing the case of a selected word of a multiline text to upper

    DBVersion:10g
    Foms Version:10g
    Hi Experts,
    Actually i have a requirement where i have to change the case of a selected word by a user into upper case.
    ex: FFFFFF hhhhh GGGG
    when user selects hhhhh and click on some button or any other option it should change it to upper case.
    plss help me out.
    regards :(
    Edited by: user123 on May 11, 2011 12:46 PM

    Here is some PL/SQL code to change a particular occurence of a word in a text.
    In this case, I change the second occurence of the "two" word:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set serveroutput on
    SQL>
    SQL> declare
      2   c varchar2(100) := 'one two three four one two three four one two three four' ;
      3   c2 varchar2(100);
      4   i integer;
      5   j integer := 0 ;
      6   pos integer := 1 ;
      7   occurence integer := 2 ; -- occurence to change
      8  begin
      9   loop
    10    i := instr(c,'two', pos);
    11    exit when j = (occurence-1) or i = 0;
    12    j := j + 1;
    13    pos := pos + i ;
    14   end loop;
    15   i := instr(c,'two', pos);
    16   if i > 0 then
    17     c2 := substr( c,1,i-1) || upper(substr(c,i, length('two')))
    18        || substr(c, i+length('two'));
    19   end if ;
    20   dbms_output.put_line(c2);
    21  end;
    22  /
    one two three four one TWO three four one two three four
    PL/SQL procedure successfully completed.Francois

  • Chang the WHERE clause

    hi,
    I want to change the Where clause used in the block, to change runtime in the
    forms, need help.
    Thanks.

    You can use set_block_property that triggered from a button
    (When a button pressed):
    1. With default_where parameter:
    SET_BLOCK_PROPERTY('blockname', DEFAULT_WHERE, 'column = ''value''');
    SET_BLOCK_PROPERTY('emp', DEFAULT_WHERE, 'gender=''M''');
    2. With query_data_source_name parameter:
    PROCEDURE codevisibility IS
    qdsn varchar2(100);
    BEGIN
         go_block('myblock');
         clear_block;
         IF :urutblok.options = 'I' THEN     
              qdsn := ' (SELECT * FROM FERRY.mytab WHERE '
                   ||' CODE = '||:blk.code
                   ||' AND CODE2 = '||'''I'''||')';
         SET_BLOCK_PROPERTY('myblock',query_data_source_name, qdsn );
         ELSIF :urutblok.options = 'P' THEN                    
              qdsn := ' (SELECT * FROM FERRY.mytab WHERE '
                   ||' CODE = '||:blk.code
                   ||' AND CODE2 = '||'''P'''||')';
         SET_BLOCK_PROPERTY('myblock',query_data_source_name, qdsn );
    END IF;
         EXECUTE_QUERY;
    END;
    rgds,
    ferry.

  • Can we change the start conditions of SAP standard workflows

    Can we change the start conditions of SAP standard WF10400002
    Where i want to assign my own Gross amount in the start conditions.

    Check out the link below.
    [http://help.sap.com/saphelp_nw2004s/helpdata/en/90/83ed38f5f41a28e10000000a114084/content.htm]
    [http://help.sap.com/saphelp_nw2004s/helpdata/EN/4c/86bf43feca11d2a64f0060087a79ea/content.htm]
    Regards,
    Raj

  • How do I find and/or change the pre-set voltage selection switch in an HP TouchSmart IQ500 series

    how do I find and/or change the pre-set voltage selection switch in an HP TouchSmart IQ500 series (specifically an IQ524)
    This question was solved.
    View Solution.

    Doesn't it use an external AC Adapter? If so, all you should need to use in another country is an adpater plug to match the wall socket.
    ... an HP employee expressing his own opinion.
    Please post rather than send me a Message. It's good for the community and I might not be able to get back quickly. - Thank you.

  • To change the font of a selected row in a Jtable

    Hello,
    Is it possible to change the font of a selected row in a jtable?
    i.e. if all the table is set to a bold font, how would you change the font of the row selected to a normal (not bold) font?
    thank you.

    String will be left justified
    Integer will be right justified
    Date will be a simple date without the time.
    As it will with this renderer.Only if your custom renderer duplicates the code
    found in each of the above renderers. This is a waste
    of time to duplicate code. The idea is to reuse code
    not duplicate and debug again.
    No, no, no there will be NO duplicated code.
    A single renderer class can handle all types ofdata.
    Sure you can fit a square peg into a round hole if
    you work hard enough. Why does the JDK come with
    separate renderers for Date, Integer, Double, Icon,
    Boolean? So that, by default the rendering for common classes is done correctly.
    Because its a better design then having code
    with a bunch of "instanceof" checks and nested
    if...else code.This is only required for customization BEYOND what the default renderers provide
    >
    And you would only have to use instanceof checkswhen you required custom
    rendering for a particular classAgreed, but as soon as you do require custom
    renderering you need to customize your renderer.
    which you would also have to do with theprepareRenderer calls too
    Not true. The code is the same whether you treat
    every cell as a String or whether you use a custom
    renderer for every cell. Here is the code to make the
    text of the selected line(s) bold:
    public Component prepareRenderer(TableCellRenderer
    renderer, int row, int column)
    Component c = super.prepareRenderer(renderer, row,
    , column);
         if (isRowSelected(row))
              c.setFont( c.getFont().deriveFont(Font.BOLD) );
         return c;
    }It will work for any renderer used by the table since
    the prepareRenderer(...) method returns a Component.
    There is no need to do any kind of "instanceof"
    checking. It doesn't matter whether the cell is
    renderered with the "Object" renderer or the
    "Integer" renderer.
    If the user wants to treat all columns as Strings or
    treat individual columns as String, Integer, Data...,
    then they only need to override the getColumnClass()
    method. There is no change to the prepareRenderer()
    code.
    Have you actually tried the code to see how simple it
    is?
    I've posted my code. Why don't you post your solution
    that will allow the user to bold the text of a Date,
    Integer, and String data in separate column and then
    let the poster decide.Well, I don't see a compilable, runnable demo anywhere in this thread. So here's one
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Arrays;
    import java.util.Date;
    import java.util.Vector;
    public class TableRendererDemo extends JFrame{
        String[] headers = {"String","Integer","Float","Boolean","Date"};
        private JTable table;
        public TableRendererDemo() {
            buildGUI();
        private void buildGUI() {
            JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            Vector headerVector = new Vector(Arrays.asList(headers));
             Vector data = createDataVector();
            DefaultTableModel tableModel = new DefaultTableModel(data, headerVector){
                public Class getColumnClass(int columnIndex) {
                    return getValueAt(0,columnIndex).getClass();
            table = new JTable(tableModel);
    //        table.setDefaultRenderer(Object.class, new MyTableCellRenderer());
            table.setDefaultRenderer(String.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Integer.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Float.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Date.class, new MyTableCellRenderer());
            JScrollPane jsp = new JScrollPane(table);
            mainPanel.add(jsp, BorderLayout.CENTER);
            pack();
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        private Vector createDataVector(){
            Vector dataVector = new Vector();
            for ( int i = 0 ; i < 10; i++){
                Vector rowVector = new Vector();
                rowVector.add(new String("String "+i));
                rowVector.add(new Integer(i));
                rowVector.add(new Float(1.23));
                rowVector.add( (i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE));
                rowVector.add(new Date());
                dataVector.add(rowVector);
            return dataVector;
        public static void main(String[] args) {
            Runnable runnable = new Runnable() {
                public void run() {
                    TableRendererDemo tableRendererDemo = new TableRendererDemo();
                    tableRendererDemo.setVisible(true);
            SwingUtilities.invokeLater(runnable);
        class MyTableCellRenderer extends DefaultTableCellRenderer{
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if ( isSelected){
                    setFont(getFont().deriveFont(Font.BOLD));
                else{
                    setFont(getFont().deriveFont(Font.PLAIN));
                if ( value instanceof Date){
                    SimpleDateFormat formatter =(SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
                    setText(formatter.format((Date)value));
                if(value instanceof Number){
                   setText(((Number)value).toString());
                return this;
    }Hardly a "bunch of instanceof or nested loops. I only used the Date instanceof to allow date format to be specified/ modified. If it was left out the Date column would be "18 Apr 2005" ( DateFormat.MEDIUM, which is default).
    Cheers
    DB

Maybe you are looking for