Where condition with optional fields in select statement

Hi,
In a function module I have to fetch data based on 7 fields out of which 6 are optional.
If we won't enter values for optional fields it will take default values as zeroes .
So this is not fetching data. But for some fields some values has zero values.
How to solve this condition?
Regards,
maha.

Hi,
For those import parameters for which its mentioned as optional, use like condition in the where clause of select statement in the function module.
try like this,
concatenate pfield2 '%' into pfield2.
concatenate pfield3 '%' into pfield3.
concatenate pfield4 '%' into pfield4.
concatenate pfield5 '%' into pfield5.
concatenate pfield6 '%' into pfield6.
concatenate pfield7 '%' into pfield7.
select *
from db table
into itab
where field1 = pfield1 and
           field2  like pfield2 and
           field3  like pfield3 and
           field7 like pfield7.
Now even if the optional fields are blank, data will be selected
Regards,
Vik

Similar Messages

  • Can i Use a time stamp vale  in where condition with date field?

    HI,
    In a where condition the table field vale is of type timestamp and select options value is of type date.
    How do i select data?

    Define a range for r_dt for timestamp field.
    Initailize the range with the below values.
    r_dt-sign = 'I'.
    r_dt-option = 'CP'.
    concatenate r_date-low '*' into r_dt-low.
    concatenate r_date-high '*' into r_dt-high.
    append r_dt.
    Use r_dt in your select query where clause.
    Note - r_date is the select-option for your date field.
    Regards
    Anurag

  • Group by function with CLOB fields in Select statement

    I have the following sql trying to query our database. Removing the Clob field (a.description) I am successful. But I need the Clob field (a.description). Here is my current sql
    select  a.id_number, a.id_owner,  MAX (n.next_action_required)
                KEEP (DENSE_RANK LAST ORDER BY n.modified_date),
             MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date)
    from table1 a, table2 n
    where a.id_number = n.id_number
    group by a.id_number, a.id_ownerI tried the following which works sometimes but not always because the Clob field (a.description)'s length varies; anywhere from 10 characters up to 12,000 characters. I get some blanks with the following and some where text is cut off. I may not be writing the dbms_lob.substr function correct.
    select  a.id_number, a.id_owner,  MAX (n.next_action_required)
                KEEP (DENSE_RANK LAST ORDER BY n.modified_date),
             MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) , DBMS_LOB.SUBSTR (a.description, 8001, 10000)
    from table1 a, table2 n
    where a.id_number = n.id_number
    group by a.id_number, a.id_owner, DBMS_LOB.SUBSTR (a.description, 8001, 10000)Please help. Thank you,

    Maybe,
    but throw it away if the combination a.id_number,a.id_owner,n.next_action_required(a.id_number = n.id_number),n.modified_date(a.id_number = n.id_number) is not unique
    select nd.id_number,
           nd.id_owner,
           nd.next_action_required,
           nd.modified_date,
           a.description
      from (select a.id_number,
                   a.id_owner,
                   MAX (n.next_action_required) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) next_action_required,
                   MAX (n.modified_date) KEEP (DENSE_RANK LAST ORDER BY n.modified_date) modified_date
              from table1 a,
                   table2 n
             where a.id_number = n.id_number
             group by a.id_number,
                      a.id_owner
           ) nd,
           table1 a
    where nd.id_number = a.id_number
       and nd.id_owner = a.id_owner
       and nd.id_number = (select id_number
                             from table2
                            where next_action_required = nd.next_action_required
                              and modified_date = nd.modified_date
                          )Regards
    Etbin

  • CASE Statement in Where Condition with Multi Valued parameter in SSRS

    Hi All,
    I am little confused while using CASE statement in Where condition in SSRS. Below is my scenario:
    SELECT
    Logic here
    WHERE
    Date IN (@Date)AND
    (CASE
    WHEN NAME LIKE 'ABC%' THEN 'GROUP1'
    WHEN ID IN ('123456', '823423','74233784') THEN 'GROUP2'
    WHEN ABC_ID IS NULL THEN 'GROUP3'
    ELSE 'GROUP4'
    END ) IN (@GROUP)
    So above query uses WHERE condition with CASE statement from @GROUP parameter. I want to pass this parameter as multi- valued parameter and hence I have used CASE statement IN (@GROUP).
    For @Date one dataset will pass the available and default values and
    for @GROUP parameters, another dataset will pass the available and default values.
    But this is not working as expected. Please suggest me where I am making mistake in the query.
    Maruthu | http://sharepoint-works.blogspot.com

    Hi Maruthu,
    According to your description, I create a sample report in my local environment. It works as I expected. In your scenario, if the selected values from the Date parameter contains some of the Date field values, the selected values from the GROUP parameter
    contains some of GROUPS (‘GROUP1’,’GROUP2’,’GROUP3’,’GROUP4’) and the corresponding when statement is executed , then the dataset returns the corresponding values.
    In order to trouble shoot this issue, could you tell us what results are you get and what’s your desired results? If possible, you can post the sample data with sample dataset, then we can make further analysis and help you out.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Using where condition with dynamic internal table

    Hi Friends.
    How to use where condition with dynamic internal table ?
    Regards,
    Amit Raut

    Hai Amit
    REPORT  ZDYNAMIC_SELECT                         .
    TABLES: VBAK.
    DATA: CONDITION TYPE STRING.
    DATA: BEGIN OF ITAB OCCURS 0,
    VBELN LIKE VBAK-VBELN,
    POSNR LIKE VBAP-POSNR,
    END OF ITAB.
    SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
    CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
    INTO CONDITION SEPARATED BY SPACE.
    SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
    WHERE (CONDITION).
    LOOP AT ITAB.
    WRITE 'hello'.
    ENDLOOP.
    Thanks & Regards
    Sreenivasulu P

  • A trouble with "LIKE" in a select statement

    Hi!
    I'm having trouble with "LIKE" in a select statement...
    With Access I can make the following and everything works well:
    SELECT name, birthday
    FROM client
    WHERE birthday LIKE '*/02/*';
    but if try to do it in my application (it uses Access), it doesn't work - I just can't understand that!!!
    In my application the "month" is always the currently month taken from the "System". Look what I'm doing...
    String query1 = "SELECT name, birthday " +
              "FROM client " +
              "WHERE birthday " +
              "LIKE '*/" +
              pMonth +
              "/*' " +
              "ORDER BY birthday ASC ";
    ResultSet rs = statement1.executeQuery(consulta1);
    boolean moreRecords = rs.next();
    The variable "moreRecords" is always "false", the query returns nothing although the table "client" has records that attend the query.
    Please, anyone can help me?! It's a little bit urgent.
    Thanks,
    Katia.

    Hi Katia,
    I'll bet the problem lies with the characters you're using to escape the LIKE clause. You're using the ones that Access likes to see, but that's not necessarily what's built into the JDBC-ODBC driver class.
    You can find out what the correct escape wildcard characters are from the java.sql.DatabaseMetaData.getSearchStringEscape() method. It'll tell you what to use in the LIKE clause.
    I'm not 100% sure about your code. It doesn't use query1 anywhere. I'd do this:
    String query = "SELECT name, birthday FROM client WHERE birthday LIKE ? ORDER BY birthday ASC";
    PreparedStatement statement = connection.createStatement(query);
    String escape = connection.getMetaData().getSearchStringEscape();
    String test = escape + '/' + pMonth + '/' + escape;
    statement.setString(1, test);
    ResultSet rs = statement.executeQuery();
    while (rs.hasNext())
    // load your data into a data structure to pass back.
    rs.close();
    statement.close();Let me know if that works. - MOD

  • Default Current year in select option field on selection Screen

    Dear Experts,
    I want to set current year as default value in fiscal year select-options field on selection screen.
    for this, i hv written following code
    DATA:VAR_DATE TYPE SY-DATUM.
    DATA VAR(4) TYPE C.
    VAR_DATE = SY-DATUM.
    VAR = VAR_DATE+0(4).
    this retrieves current year .
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
    SELECT-OPTIONS I11 FOR ANLC-GJAHR DEFAULT VAR TO VAR..                            "Fiscal Year
    SELECTION-SCREEN END OF BLOCK B1.
    Now when i am executing program pop-up is raised describing "Specify the range Limits". Please help.
    Regards,
    Apoorv Sharma

    >
    Ganga Bhavani R wrote:
    > Use below lines.
    >
    > SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
    > SELECT-OPTIONS I11 FOR ANLC-GJAHR DEFAULT SY-DATUM+0(4). "Fiscal Year
    > SELECTION-SCREEN END OF BLOCK B1.
    Hi, Ganga,
    I think it will not working properly that way, Please test the bellow Sample Code.
    TABLES: anlc.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
    SELECT-OPTIONS i11 FOR anlc-gjahr .
    SELECTION-SCREEN END OF BLOCK b1.
    INITIALIZATION.
      IF i11[] IS INITIAL.
        i11-low = sy-datum+0(4).
        APPEND i11.
      ENDIF.
    Thanks and Regards,
    Faisal

  • View with selection conditions with system fields.

    Hi Experts,
    I have a view. Now i want to control the data that is selected using 'Selection Conditions'.
    here i want to use system field SY-DATUM.
    My requirement is  i want to control the output like
    Valid_From_Date GE SY-DATUM and
    Valid_To_Date     LE  SY-DATUM
    which means that i would be showing only active users in this view.
    How can i go about this? System is not allowing system fields in comparision value.
    Any help on this is highly appreciated. Thanks.
    regards,
    Simha

    Hi,
    I am getting a warning first 'enter constant as comparision value'
    when i trying to activate the view i am getting the below error.
    A join condition on a field of the system table SY (or SYST) was defined.
    This is not permitted for database views because the system table is not known to the database
    Have tried to activate the view you created?
    How to go about this?
    Regards,
    Simha

  • SELECT OPTIONS use in select statement

    hi,
    I have defined my selection screen in the main program.
    selection-screen begin of screen 0101 as subscreen.
    selection-screen begin of block b1.
    select-options:  S_KUNNR for  KNA1-KUNNR,
    selection-screen end of block b1.
    selection-screen end of screen 0101.
    then in an include in the same module pool, i try to use this in select statement
    SELECT * INTO CORRESPONDING FIELDS OF XXX FROM ZPPP WHERE KUNNR IN S_KUNNR.
    I get  an error saying " the IN operator with S_KUNNR is neither followed by an internal table nor by a valuelist "..what does this mean ?
    thks

    Check the sample code...
    REPORT  ztest_mod.
    DATA: kunnr TYPE kunnr.
    * Custom Selection Screen 0200
    SELECTION-SCREEN BEGIN OF SCREEN 0200 AS SUBSCREEN.
    SELECT-OPTIONS: s_kunnr FOR  kunnr.
    SELECTION-SCREEN END OF SCREEN 0200.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_kunnr-low.
      BREAK-POINT.
    START-OF-SELECTION.
      "in this screen i have a button with function code 'SEARCH'
    " and a subscreen area with name sub
      CALL SCREEN 100.
    *&      Module  STATUS_0100  OUTPUT
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS'.
    ENDMODULE.                    "status_0100 OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    MODULE user_command_0100 INPUT.
      DATA: it_kunnr TYPE TABLE OF kna1.
      CASE sy-ucomm.
        WHEN 'SEARCH'.
          SELECT * FROM kna1
          INTO TABLE it_kunnr
          WHERE kunnr IN s_kunnr.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                    "user_command_0100 INPUT
    in the flow logic..
    PROCESS BEFORE OUTPUT.
      MODULE status_0100.
      CALL SUBSCREEN sub INCLUDING sy-repid '0200'.
    PROCESS AFTER INPUT.
      MODULE user_command_0100.
    Regards
    Vijay Babu Dudla

  • Dynamic fields in select statement

    Hi all,
       In selection screen we are having period as select option.The values for period are 01 to 16. Based on 
          the values entered in selection screen for period we need to select HSLXX from FAGLFLEXT.
       For example if we enter 01 to 03 in selection screen then we need to select HSL01 HSL02 HSL03  
           from FAGLFLEXT.
      Like this we need to select fields dynamically in select statement. Can any one tell me how to restrict fields dynamically.
    Regards,
    Swetha

    hi Swetha,
    the  third select statemnet will work for  you..
    try this..
    _Dynamic where clause in select query.._
    * With a variable, result: AND rbusa = '5145'
    concatenate 'AND rbusa = '  ''''  i_tab-zgsber  ''''
    append where_clause to where_tab.                                  
    * Select
    select * from zcostfreq                                           
         where (where_tab).                                              
    endselect.
    _Using a dynamic table name_
    parameters:
    p_tab type tabname.
    start-of-selection.
      select count(*) from (p_tab) into l_count.
    _Dynamic retrieval and writing of data_
    FIELD-SYMBOLS:
      <row>         TYPE ANY,
      <component>   TYPE ANY.
    PARAMETERS:
    p_tab TYPE tabname.
    CREATE DATA dataref TYPE (p_tab).
    * The variable dataref cannot be accessed directly, so a field symbol is
    * used
      ASSIGN dataref->* TO <row>.
      SELECT *
        FROM (p_tab) UP TO 10 ROWS
        INTO <row>.
        NEW-LINE.
        DO.
    *     Write all the fields in the record   
          ASSIGN COMPONENT sy-index
            OF STRUCTURE <row>
            TO <component>.
          IF sy-subrc <> 0.
            EXIT.
          ENDIF.
          WRITE <component>.
        ENDDO.
      ENDSELECT.
    Regards,
    Prabhduas

  • How to get around Ampersand in text field in Select statement

    I have an SQL statement I am trying to run in SQL*Plus. In one of my subqueries, I have a select statment in which some of the fields I am trying to pull have an "&" within the text. So, when I try and run the query it returns "Enter value for 35:". I've even tried wildcard characters and it is still not working. If anyone could help me with this, I would appreciate it. Here is a sample of my statement (the subquery is at the bottom of the statement):
    select real_case.file_dt, real_case.dscr, pty_cd, first_name, last_name, addr_line1, addr_line2, city, st_cd, zip_cd
    from real_case, pty, idnt, ptyaddr s1, addr
    where real_case.case_id = pty.case_id
    AND pty.idnt_id = idnt.idnt_id
    AND pty.case_id = s1.case_id
    and pty.seq = s1.seq
    and s1.addr_id = addr.addr_id
    and (real_case.file_dt >= '01-NOV-06'
    and real_case.file_dt <= current_date)
    and (real_case.dscr like '79D01-%'
    or real_case.dscr like '79C01-%'
    or real_case.dscr like '79D02-%')
    and (pty.pty_cd like 'DFNDT')
    and (s1.ins_dttm in
    (select max(s2.ins_dttm) from ptyaddr s2
    where s2.case_id = s1.case_id
    and s2.seq = s1.seq))
    and (real_case.case_id in
    (select case_id from ptychrg
    where ptychrg.actn_cd IN ('35-41-5-1&35-48-4-1')));Thanks,
    Shannon

    this?
    SQL> set define off
    SQL> ed
    Wrote file afiedt.buf
      1  with t as
      2    (select 'a&b' col from dual
      3      union all
      4      select 'abc' from dual)
      5   select    * from t
      6*  where col like '%\&%'
      7  /
    COL
    a&b
    or this
    SQL> ed
    Wrote file afiedt.buf
      1  with t as
      2    (select 'a&b' col from dual
      3      union all
      4      select 'abc' from dual)
      5   select    * from t
      6*  where col like '%'||chr(38)||'%'
    SQL> /
    COL
    a&bjust '%'||chr(38)||'%' will not work.
    You nedd either set scan off or set define off
    correction
    Message was edited by:
    devmiral

  • Determine Length of Field in Select Statement

    Hi Experts!
    My officemate has this little problem regarding selection of data based on a certain condition...
    Here is the situation:
    For Example...
    In table KNA1....
    KUNNR       NAME1         Length of Data in Name1
    000001        AA                2           
    000002        AB                2
    000003        ABCD           4
    000004        ABCDE         5
    She only wants to get the records that has the length of 2 in KNA1-NAME1,
    i.e., 'AA' and 'AB' without having to put it in the internal table then make a loop and update the table using the strlen() condition....
    Experts, is this possible? Knowing the length of the data in the select statement? She wants this alternative because it is faster rather than having to loop in internal tables and check if this data has the length of 2 or 3 or 4 and so on....
    Can you please help me out with this one? Thanks in advance!
    <b></b>

    Hi
    If the lenghtn is 6 characters and if you want to fetch only first 2 characters.
    you can use offset
    fetch data from internal table and take variable
    v_var1 = itab-name1+0(2).
    you get only first 2 characters....
    if you want last 2 characters itab-name1+4(2).
    Thanks

  • Dynamic field in Select Statement

    I am able to create a dynamic statement to insert into the where clause of my sql, but I am unable to dynamically create a select statement. Oracle Reports produces the following error:
    REP-0499: Column " selected by the query is incompatible with report definition.
    Here is an example of my select:
    Select
    &dynamic_field
    from
    any_table
    Any help is appreciated.

    I figured it out. Thanks

  • Problem with Hiding fields of selection screen which is called as subscreen

    Hello All,
    I have problem while hiding the selection screen which is called as subscreen.
    Flow of my logic:
    Selection-screen with one field and three buttons CREATE,DISPLAY and CHANGE in application toolbar.
    user enter some value in field and either he press change or dispaly
    When change i need to call selection screen when it is in dispaly i need to stop calling this selection screen.
    Upto my knowledge we can't stop calling selection screen in display mode so there is only one possibility is hiding the fields when it is in display mode.
    How can i hide the fields and where i need to hide fields?
    Please post some codes.
    Regards,
    Lisa

    you can refer the sample code which i mentioned in your previous post. that will solve the problem.

  • Using a varchar field to select statement

    Hi all
    I have a single row and single column table
    T(command varchar2(4000))
    and the row is
    sno,name
    And I have another table T1(sno number,name varchar)
    Now can any body tell how can i use command column in table T to query T1 to get sno,name from T1
    I am looking for a select statement like this
    select (select command from T) from T1;
    but it is printing out the data in T i mean sno, name
    This is a copy of thread Selecting output of a select statement
    but explained more clearly
    Thanks,
    ganesh.

    I don't know why your tables are designed like this but what I think you want to do is join T1 with the data in T.
    select sno, name from T1
    where sno in (select substr(command,0,instr(command,',')-1) from T)
    and name in (select substr(command,instr(command,',')+1) from T);
    substr returns a string up to a position
    instr returns the position of a string
    and the other post you refer to as about as confusing as your one.

Maybe you are looking for