Passing values to Dynamic where clause as IN parameter - ADF

Hi,
I am trying to get the Dynamic where clause query output something like below,
select * from EMP where emp_id IN(200,203,204)
How to pass values from setWhereCluase(emp_id,????)
Thanks,

I'd go about this a little differently (probably not the best way):
1. Create view object lk_department (lookup). In the query add a union with something like "select null as ID, 'All' as name' from dual;". This adds a null value that they can select by leaving the combo box on "All". Add a 'order by id" so the null value is the first one. When creating the combo box you want it set to navigation mode, so select the whole viewobject from the data palette rather a specific field.
2. Create a jTextField for the "Jobs" field.
3. Create an application module method that does something like:
public void filterEmployees(String job){
ViewObject vo_departments = findViewObject("lk_departments");
ViewObject vo_employees = findViewObject("employees");
String wc = "1 = 1 ";
String wc = " and job like '%"+job+"%'"
if (vo_departments.getCurrentRow().getAttribute("Id") != null) {wc += "and department_id = "+vo_departments.getCurrentRow().getAttribute("Id");}
vo_employees.setWhereClause(wc);
vo_employees.executeQuery();
this.sync;
4. In your Jclient app, you just need to call the method of your appmodule and insert the string from the textbox, using code similar to this:
AppModule b = (AppModule)panelBinding.getApplicationModule();
b.filterEmployees(jTextField.getText());
I didn't test this code, but that's how I go about the same thing.

Similar Messages

  • Dynamic where clause for MULTIPLE values

    In the following of dynamic where clause?
    i have some somewhat different problem.
    Is a dynamic where clause for multiple values possible?
    If the inputvariable varCode1,varCode2,varCode3,varCode4 are 0 then show all id's otherwise filter the resultset on var1 and/or var2,and/or var3,and/or var4.
    Example table:
    create table t
    (d int,var int);
    insert into t values (1 ,1 );
    insert into t values (2 ,1 );
    insert into t values (3 ,2 );
    insert into t values (4 ,3 );
    insert into t values (5 ,4 );
    insert into t values (6 ,4 );
    insert into t values (7 ,4 );
    insert into t values (8 ,4 );
    insert into t values (9 ,5 );
    insert into t values (10, 6);
    insert into t values (11, 6);
    So what i want to change the where clause upon the value of the varCodes. If var1 and var are not 0 a "AND" should be used otherwise an "OR"
    select id
    from tst
    where var = DECODE( :varCode1, 0, var, :varCode1)
    or/and(?) DECODE( :varCode2, 0, var, :varCode2)
    or DECODE( :varCode3, 0, var, :varCode3)
    or DECODE( :varCode4, 0, var, :varCode4)

    Please turn off your Caps Lock
    and try this link
    Dynamic WHERE clause

  • Dynamic where clause in "delete itab where..." variant

    Hi,  I need to be able to delete the contents of an internal table based on a dynamic where clause. I don't want to loop through the entire table to test each record.  Since the delete statement doesn't seem to allow a dynamic "where" clause I am trying to use a macro.  I can't get the macro to work either. 
    I get the following error in my syntax check:
    Statement concluding with "...FINAL_STATEMENT" ended unexpectedly.          
    Is there any way to get this macro to pass the syntax text or accomplish the dynamic delete?
    MACRO TO FILTER OUT UNWANTED RECORDS (RETAIL OUTLETS)
      DEFINE DELOUT.
        DELETE MY_ITAB WHERE &1.
      END-OF-DEFINITION.
    Example FINAL_STATEMENT = (  ZRRDIVIS = '4' )
    USING MACRO DOES NOT PASS SYNTAX CHECK
      DELOUT FINAL_STATEMENT.

    Well, if you really need this kind of functionality,  here is a code sample that I just threw together that would work.  A lot of code for one little delete statement though.
    report zrich_0001 .
    data: begin of itab occurs 0,
          fielda type c,
          fieldb type c,
          fieldc type c,
          end of itab.
    data: where_clause type string.
    class lcl_source definition.
      public section.
        types: t_source(72).
        class-data: routine(32) value 'TEMP_ROUTINE',
                    program(8),
                    message(128),
                    line type i.
        class-data: isource type table of t_source,
                    xsource type t_source.
        class-methods: execute_source importing im_clause type string.
    endclass.
    start-of-selection.
    * Build the itab.
      itab-fielda = '1'.
      itab-fieldb = '2'.
      itab-fieldc = '3'.
      append itab.
      itab-fielda = '3'.
      itab-fieldb = '2'.
      itab-fieldc = '1'.
      append itab.
    * Set the where clause
      where_clause = 'FIELDA = ''1''.'.
    * call the delete statement.
      call method lcl_source=>execute_source
                exporting
                    im_clause = where_clause.
    *       CLASS lcl_source IMPLEMENTATION
    class lcl_source implementation.
      method execute_source.
        xsource = 'REPORT ZTEMP_REPORT.'.
        insert xsource  into isource index 1.
        xsource = 'FORM & tables itab.'.
        replace '&' with routine into xsource.
        insert xsource  into isource index 2.
        xsource = 'Data: begin of xitab occurs 0,'.
        append xsource to isource.
        xsource = 'fielda type c,'.
        append xsource to isource.
        xsource = 'fieldb type c,'.
        append xsource to isource.
        xsource = 'fieldc type c,'.
        append xsource to isource.
        xsource = 'end of xitab.'.
        append xsource to isource.
        xsource = 'xitab[] = itab[].'.
        append xsource to isource.
        concatenate 'DELETE xITAB WHERE' im_clause into xsource
                      separated by space.
        append xsource to isource.
        xsource = 'ENDFORM.'.
        append xsource to isource.
        generate subroutine pool isource name program
                                 message message
                                 line line.
        if sy-subrc = 0.
          perform (routine) in program (program) tables itab.
        else.
          write:/ message.
        endif.
      endmethod.
    endclass.
    Regards,
    Rich Heilman

  • How to set dynamic WHERE clause to VO from backingBean?

    Hi,
    Can any one let me know the best way to add the dynamic WHERE clause in to VO query.
    I have created AM (with AMImpl.java) & VO (with VOImpl.java & VORowImpl.java) in my model project. I suppose to set the WHERE condition at runtime while the user click the search button. I am handling the user button click at UI layer backingBean. From the backing bean I could able to get the objct of the VO and set the where clause by below code.
            ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings.UserSearchVO1Iterator}", Object.class);
            DCIteratorBinding dcIter = (DCIteratorBinding)valueExp.getValue(elContext);
            ViewObject userSearchVO = dcIter.getViewObject();
            userSearchVO.setWhereClause("lower(usr_login) LIKE ':1' and usr_udf_suid like ':2' ");
            userSearchVO.executeQuery();But as I fear this is not the right way to do it. So I am creating the cutom method inside the VOImpl.java and triggring that method by creating one more cutom method in AMImpl.java. But I dont know how to invoke this AM method from backingBean.
    AMImpl method
    public void initDetails()
            UserSearchVOImpl vo = getUserSearchVO1();
            vo.initQuery();
    VOImpl method
        public void initQuery()
            setWhereClause("lower(usr_login) LIKE 'a%' and usr_udf_suid like '%1144%'");
            executeQuery();
        }Can any one guide me which is the best way to set the where clause to VO? How to call the AM method from backingBean?
    Thanks
    kln

    i am new to oracle 11g i writing a stored procedure in which i have made use of case in where clause to pass my parameter value v_toStoreID
    i have googled a lot regarding that i found that to use case in where clause it should be like this
    where
    case  column_value
    when 0
    then value1
    else
    value2
    end
    this my query
    SELECT ITMID as ItemId,
    NVL(OrderDtl.PackageID, 0) PackageId,
    OrderDtl.OrdDtlID,
    (CASE NVL(OrderDtl.PackageID, 0)
    WHEN 0
    THEN 1
    ELSE 0
    END) as PackageFlag,
    ivitem.Code ItemCode,
    ivitem.ITMNAME AS itemName,
    IvPatientIssueMst.IssueNo Issue_No,
    to_char(Issuedate, 'DD/MM/YYYY') IssueDate,
    OrderDtl.OrdQty,
    NVL(OrderDtl.AllocationID, 0) Package,
    OrderDtl.ServiceAmount MRP
    FROM IvPatientIssueMst
    JOIN OrderMst
    ON IvPatientIssueMst.OrderId = OrderMst.OrdId
    JOIN OrderDtl
    ON OrderDtl.OrdID = OrderMst.OrdId
    JOIN ivitem
    ON ivitem.ITMID = OrderDtl.DrugId
    LEFT JOIN IVPatientIndentMst
    ON IVPatientIndentMst.IndentID = IvPatientIssueMst.IndentId
    WHERE OrderMst.OrdVisitID = 395899
    AND
    *(CASE IvPatientIssueMst.StoreId*
    when NVL(IvPatientIssueMst.StoreId, 0)=0
    THEN v_toStoreID
    ELSE  IVPatientIndentMst.ToStoreID
    END)
    ORDER BY ivitem.ITMNAME;
    it is not working please someone help

  • Less than or eual to Date issue in dynamic where clause

    Dear All,
    I have a requirement to search the leave balance information, here date as a parameter. When ever we pass the date as a parameter it should be display all the leave balance information till the parameter date.
    Steps I have followed to achieve this requirement
    • Created the VO and query as follows
    SELECT trunc(paa.creation_date) creation_date, paa.date_start, paa.date_end,
    SYSDATE duty_resumption_date, paa.absence_days leave_deducted,
    paa.absence_days leave_added, 'Leave Deucted' detail,
    paa.absence_days balance_remaining,
    fu.user_id
    FROM per_absence_attendances paa, per_all_people_f papf, fnd_user fu
    WHERE 1 = 1
    AND papf.person_id = paa.person_id
    AND papf.person_id = fu.employee_id
    AND fu.user_id=fnd_profile.value('USER_ID')
    And trunc(paa.creation_date) <= TO_DATE((to_char(trunc(to_date(:1)),'DD-MON-YYYY') ),'DD-MON-YYYY')
    •     Created the Advance Search Region
    •     In the controller of the region, I have captured the go button logic and setting the dynamic where clause as below
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    OAApplicationModuleImpl am= (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);
    OAQueryBean oaquerybean = (OAQueryBean)webBean.findIndexedChildRecursive("QueryRN");
    if (pageContext.getParameter(oaquerybean.getGoButtonName()) != null)
    OAViewObject oaviewobject = (OAViewObject)am.findViewObject("XXLeaveBalanceVO");
    String creationDate = pageContext.getParameter("CreationDate");
    oaviewobject.setWhereClauseParam(0,creationDate);
    oaviewobject.executeQuery();
    •     But this where condition is working equal condition to the parameter but it is not working less than condition.
    •     When I am running the VO query in Toad it is working the less than condition.
    Please help me out to resolve this issue.
    Thanks in Advance,
    Sai

    Dear Kumar,
    I have changed my vo query as you suggested, now the equal condition also not working and I am getting the following error message
    JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT trunc(paa.creation_date) creation_date, paa.date_start, paa.date_end,
    SYSDATE duty_resumption_date, paa.absence_days leave_deducted,
    paa.absence_days leave_added, 'Leave Deucted' detail,
    paa.absence_days balance_remaining,
    fu.user_id
    FROM per_absence_attendances paa, per_all_people_f papf, fnd_user fu
    WHERE papf.person_id = paa.person_id
    AND papf.person_id = fu.employee_id
    AND fu.user_id=fnd_profile.value('USER_ID')
    And trunc(to_char(paa.creation_date) ,'dd-MMM-yyyy')<= trunc(to_char(:1, 'dd-MMM-yyyy'))) QRSLT WHERE (( CREATION_DATE = :2 )) ORDER BY CREATION_DATE ASC
         at oracle.apps.fnd.framework.OAException.wrapperException(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at OA.jspService(_OA.java:72)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:597)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:521)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    ## Detail 0 ##
    java.sql.SQLException: ORA-01722: invalid number
    Thanks,
    Sai

  • How can I pass multiple condition in where clause with the join table?

    Hi:
    I need to collect several inputs at run time, and query the record according to the input.
    How can I pass multiple conditions in where clause with the join table?
    Thanks in advance for any help.
    Regards,
    TD

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • Dynamic Where clause in 4.6C [Literals allowed but not variables]

    Good afternoon-
    We have a dynamic select statement that works perfectly in 4.7 ext 2, but is causing a short dump in 4.6C. The error in the short dump says:
    The current ABAP/4 program attempted to execute an ABAP/4 Open SQL       
    statement containing a WHERE condition of the form WHERE (itab) or       
    WHERE ... AND (itab). The part of the WHERE condition specified at       
    runtime in the internal table itab contains an invalid                   
    value "HDR_COMP_CODE". Literals are allowed as values, but not variables.
    HDR_COMP_CODE is in incoming parameter to the function module that is calling this code. It is of type BKPF-BUKRS.
    Here is the code:
    DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,
            TEXT_LINE(60) TYPE C,
      END OF L_WHERE_CLAUSE.
      CLEAR L_WHERE_CLAUSE.
      IF NOT HDR_COMP_CODE IS INITIAL.
        SELECT SINGLE KTOPL
        INTO LV_KTOPL
        FROM T001
        WHERE BUKRS = HDR_COMP_CODE.
        L_WHERE_CLAUSE = 'B~BUKRS = HDR_COMP_CODE'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
        L_WHERE_CLAUSE = 'AND'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
        L_WHERE_CLAUSE = 'T~KTOPL = LV_KTOPL'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
        L_WHERE_CLAUSE = 'AND'.
        APPEND L_WHERE_CLAUSE.
        CLEAR  L_WHERE_CLAUSE.
      ENDIF.
      L_WHERE_CLAUSE = 'T~SPRAS = SY-LANGU'.
      APPEND L_WHERE_CLAUSE.
      CLEAR  L_WHERE_CLAUSE.
      SELECT BSAKNR TTXT50
      INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)
      FROM  SKB1 AS B INNER JOIN SKAT AS T
         ON TSAKNR = BSAKNR
      WHERE (L_WHERE_CLAUSE).
        APPEND LT_GL_ACCOUNT_DATA.
        CLEAR  LT_GL_ACCOUNT_DATA.
      ENDSELECT.
    This EXACT query works in 4.7, has anyone run into this, or can they tell me why I might be getting the error?
    Thanks,
    Andy

    Well, in this case, unless I'm missing something,  you do not requre a dynamic WHERE clause.  You can use RANGES instead.
    report zrich_0001.
    *DATA: BEGIN OF L_WHERE_CLAUSE OCCURS 0,
    *TEXT_LINE(60) TYPE C,
    *END OF L_WHERE_CLAUSE.
    ranges: r_bukrs for t001-bukrs.
    ranges: r_ktopl for t001-ktopl.
    *CLEAR L_WHERE_CLAUSE.
    IF NOT HDR_COMP_CODE IS INITIAL.
    clear r_bukrs. refresh r_bukrs.
    r_bukrs-sign = 'I'.
    r_bukrs-option = 'EQ'.
    r_bukrs-low = hdr_comp_code.
    append r_bukrs.
    SELECT SINGLE KTOPL
    INTO LV_KTOPL
    FROM T001
    WHERE BUKRS = HDR_COMP_CODE.
    clear r_ktopl. refresh r_ktopl.
    r_ktopl-sign = 'I'.
    r_ktopl-option = 'EQ'.
    r_ktopl-low = lv_ktopl.
    append r_ktopl.
    *L_WHERE_CLAUSE = 'B~BUKRS = HDR_COMP_CODE'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    *L_WHERE_CLAUSE = 'AND'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    *L_WHERE_CLAUSE = 'T~KTOPL = LV_KTOPL'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    *L_WHERE_CLAUSE = 'AND'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    ENDIF.
    *L_WHERE_CLAUSE = 'T~SPRAS = SY-LANGU'.
    *APPEND L_WHERE_CLAUSE.
    *CLEAR L_WHERE_CLAUSE.
    SELECT B~SAKNR T~TXT50
    INTO (LT_GL_ACCOUNT_DATA-GL_ACCOUNT, LT_GL_ACCOUNT_DATA-DESCRIPTION)
    FROM SKB1 AS B INNER JOIN SKAT AS T
    ON T~SAKNR = B~SAKNR
    WHERE  b~bukrs in r_bukrs
      and  t~ktopl in r_ktopl.
    APPEND LT_GL_ACCOUNT_DATA.
    CLEAR LT_GL_ACCOUNT_DATA.
    ENDSELECT.
    Regards,
    Rich Heilman

  • Dynamic WHERE Clause in a Calendar

    I would like to have a Calendar display values based on a dynamic WHERE clause created using PL/SQL anonymous block evaluating the values of items that the user uses as filters. I have done this dynamic SQL for reports and would lke to do the same for a Calendar.

    I figured out how to do this.
    I created a Hidden Item with the source value of &APP_USER.
    named P50_APP_USER.
    This is how my query looks now:
    SELECT * FROM APX_EVENT WHERE APX_EVENT.STORE_NR IN (SELECT APX_Z.STORE_NR FROM APX_Z WHERE APX_Z.USERNAME = :P50_APP_USER)
    And it works.
    I got the answer from this thread:
    CALENDAR - SQL ORDER BY CLAUSE NOT WORKING

  • Dynamic Where Clause in SQR

    How to construct dynamic WHERE clause in our sqr programming ?
    In my run control table I am having parameters fromdate, thrudate [mandatory parameters] and location as [Optional Parameter] how can I declare dynamic where clause to achieve this could any one help me with coding ? Here is my sample coding
    Begin-Procedure Main
    if $prcs_process_instance=' '
    do askvalues
    else
    do getvalues
    end-if
    End_Procedure Main
    Begin-Procedure askvalues
    input $frmdate 'Enter From Id' type=text format=number !Mandatory Parameter
    input $todate 'Enter To Id' type=text format=number !Mandatory Parameter
    input $loc 'Enter Location' value=text !Optional Parameter
    End-Procedure
    Begin-Procedure getvalues
    Begin-Select
    FROMDATE
    THRUDATE
    SQR_LOCATION
    let $frmdate=&FROMDATE
    let $todate=&THRUDATE
    let $loc=&SQR_LOCATION
    let where=-------------------------- ?
    FROM
    PS_PROCESS_TBL WHERE OPRID=$PRCS_OPRID AND RUN_CNTL_ID=$PRCS_RUN_CNTL_ID
    End-Select
    End-Procedure getvalues
    Begin-Procedure selectall
    BEGIN-SELECT
    SQR_EMPLID
    SQR_FNAME
    SQR_LNAME
    SALARY
    FROM
    PS_SQR_FIRST_TBL WHERE SQREMPID BETWEEN $frmdate AND $todate
    END-SELECT
    End-Procedure selectall

    SQR will understand Where Clause as dynamic, when you include it in Square Brackets []
    In your case, since fromdate & thrudate are mandatory values, I would code like this
    let $frmdate=&FROMDATE
    let $todate=&THRUDATE
    let $loc=&SQR_LOCATION
    let $Where_Clause = 'SQREMPID BETWEEN' || ' ' || $frmdate || ' ' || 'AND' || ' ' ||$todate
    if $loc != ''
    let $Where_Clause = $Where_Clause || ' '|| 'AND' || ' ' || 'LOCATION = ' || $loc
    end-if
    Now you can use this Dynamic Where Clause in which procedure you want. Only thing is you need to encode the where clause with brackets([$Where_Clause])
    Edited by: 935179 on Sep 6, 2012 2:11 AM

  • ADF dynamic where clause for VO query using BC

    I'm hoping someone can help me out. I have a read only view object that I want to filter results based on some user choices. For example the user may want to see all results or they may only want to see a much smaller subset. This is for an error dashboard, the smaller subset maybe by application or maybe by application and by error severity. I think I can use a dynamic where clause but I'm not sure, Can someone get me started down the right path, or post an example that I can see.

    Hi user,
    You can use a dynamic where clause for this, but maybe there is a more practical option. Maybe you can have a fixed where clause, but using a bind parameter, like:
    vo.application like :applicationParam. This makes an executeWithParams method available that you can call from your page, and use in the bindings. This parameter you can populate with the results of for example a poplist, with a default value of '%'.
    When you do want to use a dynamic where clause, you will need to add a method to the java code of your application module, and make this method available for the client. In this method, you can use findViewObject to retrieve your VO, use VO.setWhereClause to set the whereclause to what you want, and then call VO.executeQuery. This method can then again be called from the page.
    Success,
    Jeroen van Veldhuizen

  • Creating dynamic where clause with string delimiter " ; "

    hi...
    i need a solution for complex problem like, 1. start_date IN date,
    end_date IN date,
    shift_type IN varchar2
    i will get shift_type as "first_shift" or "first_shift;second_shift" or "first_shift;second_shift;third_shift" ....etc any combination. where fist & second & third shits are nothing but 1 , 2 , 3. i need to find out data between start_date and end_date in combination of shifts ( may be 1;2 or 1;3 or 1;2;3 or 2;3 ...etc) . now i need to write this code in dynamic where clause ...i tried in different ways...but not succeeded. can anybody guide me step by step...or with script.
    NOTE: there is a table called "shift" with data like
    shift_type shift_mode
    1 first_shift
    2 second_shift
    3 third_shift

    Hi,
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    If the question involves parameters, give a few different sets of parameters and the results you want for each set, given the same sample data.
    It's unclear that you need dynamic SQL at all.
    If shift_type is a variable, that can be either a single value or a ;-delimited list (such as '1;3'), you can compare that to a column called shift_column like this:
    WHERE        ';' || shift_type   || ';'     LIKE
           '%;' || shift_column || ';%'No dynamic SQL or PL/SQL required.
    If you really do want to use dynamic SQL, these two pages should gives you some ideas:
    http://www.oracle-base.com/articles/misc/DynamicInLists.php
    http://tkyte.blogspot.com/2006/06/varying-in-lists.html

  • Dynamic where clause with loop statement

    Hi all,
    is it possible to use a dynamic where clause with a loop statement?
    Can you please advise me, how the syntax needs to be?
    Thanks for your suggestions,
    kind regards, Kathrin!

    Hi Kathrin,
               If u are in ECC 6.0, please go through the code...
              REPORT  zdynamic_select.
    TYPES:
      BEGIN OF ty_sales,
        vbeln  TYPE vbak-vbeln,            " Sales document
        posnr  TYPE vbap-posnr,            " Sales document item
        matnr  TYPE vbap-matnr,            " Material number
        arktx  TYPE vbap-arktx,            " Short text for sales order item
        kwmeng TYPE vbap-kwmeng,           " Order quantity
        vkorg TYPE vbak-vkorg,             " Sales organization
        kunnr TYPE vbak-kunnr,             " Sold-to party
        netwr TYPE vbak-netwr,             " Net Value of the Sales Order
      END OF ty_sales.
    DATA :
      gt_sales TYPE STANDARD TABLE OF ty_sales,
      wa_sales TYPE ty_sales.
    DATA: ob_select TYPE REF TO cl_rs_where.
    DATA: ob_from   TYPE REF TO cl_rs_where.
    DATA: ob_where  TYPE REF TO cl_rs_where,
          gv_source TYPE abapsource.
    START-OF-SELECTION.
    *Step 1 : Prepare the select fields.
      PERFORM zf_build_select.
    *Step 2 : Build the from clause for the select
      PERFORM zf_build_from.
    *Step 3 : Build the where clause for the select
      PERFORM zf_build_where.
    *Step 4 : Execute the dynamic select
      SELECT (ob_select->n_t_where)
          FROM (ob_from->n_t_where)
            INTO CORRESPONDING FIELDS OF TABLE gt_sales
            WHERE (ob_where->n_t_where).
      LOOP AT gt_sales INTO wa_sales.
        WRITE :   /5 wa_sales-vbeln,
                  15 wa_sales-vkorg,
                  20 wa_sales-kunnr,
                  40 wa_sales-netwr,
                  50 wa_sales-posnr,
                  60 wa_sales-matnr,
                  70 wa_sales-arktx,
                  90 wa_sales-kwmeng.
      ENDLOOP.
    *&      Form  zf_build_select
    FORM zf_build_select .
      CREATE OBJECT ob_select.
    *Build the table name/field name combination
    *Add Sales order header fields
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'VBELN'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'VKORG'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'KUNNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'NETWR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
    *Add Sales order item fields
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'POSNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'MATNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'ARKTX'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'KWMENG'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
    ENDFORM.                    " zf_build_select
    *&      Form  zf_build_from
    FORM zf_build_from .
      CREATE OBJECT ob_from.
    *Add opening bracket
      CALL METHOD ob_from->add_opening_bracket
      CLEAR gv_source.
    *Add the join condition.This can be made
    *fully dynamic as per your requirement
      gv_source = 'VBAK AS VBAK INNER JOIN VBAP AS VBAP'.
    *Add the where line
      CALL METHOD ob_from->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
    *Add the join condition.This can be made
    *fully dynamic as per your requirement
      gv_source = 'ON VBAKVBELN = VBAPVBELN'.
    *Add the where line
      CALL METHOD ob_from->add_line
        EXPORTING
          i_line = gv_source.
    *Add the closing bracket
      CALL METHOD ob_from->add_closing_bracket
    ENDFORM.                    " zf_build_from
    *&      Form  zf_build_where
    FORM zf_build_where .
      DATA :
      lv_field TYPE REF TO data,
      lv_field_low TYPE REF TO data,
      lv_field_high TYPE REF TO data.
      CREATE OBJECT ob_where.
    *Add the field VBELN : Sales Document
    *Use this method if you want to assign a single value to a field
    *Set the value for VBELN : Sales Document Number
    CALL METHOD ob_where->add_field
       EXPORTING
         i_fieldnm  = 'VBAK~VBELN'
         i_operator = '='
         i_intlen   = 10
         i_datatp   = 'CHAR'
       IMPORTING
         e_r_field  = lv_field.
    CALL METHOD ob_where->set_value_for_field
       EXPORTING
         i_fieldnm = 'VBAK~VBELN'
         i_value   = '0000120020'.
    *Use this method if you want to assign a range of values
    *Set a range for the Sales Document number
      CALL METHOD ob_where->add_field_between_2values
        EXPORTING
          i_fieldnm      = 'VBAK~VBELN'
          i_intlen       = 10
          i_datatp       = 'CHAR'
        IMPORTING
          e_r_field_low  = lv_field_low
          e_r_field_high = lv_field_high.
      CALL METHOD ob_where->set_2values_for_field
        EXPORTING
          i_fieldnm    = 'VBAK~VBELN'
          i_value_low  = '0000120020'
          i_value_high = '0000120067'.
    *Set the 'AND' Clause
      CALL METHOD ob_where->add_and.
    *Add the field MATNR : Material
      CALL METHOD ob_where->add_field
        EXPORTING
          i_fieldnm  = 'MATNR'
          i_operator = '='
          i_intlen   = 18
          i_datatp   = 'CHAR'
        IMPORTING
          e_r_field  = lv_field.
    *Set the value for the Material field
      CALL METHOD ob_where->set_value_for_field
        EXPORTING
          i_fieldnm = 'MATNR'
          i_value   = '000000000050111000'.
    *Set the 'AND' Clause
      CALL METHOD ob_where->add_and
    *Add the field VKORG
      CALL METHOD ob_where->add_field
        EXPORTING
          i_fieldnm  = 'VKORG'
          i_operator = '='
          i_intlen   = 4
          i_datatp   = 'CHAR'
        IMPORTING
          e_r_field  = lv_field.
    *Set the value for VKORG : Sales Organization
      CALL METHOD ob_where->set_value_for_field
        EXPORTING
          i_fieldnm = 'VKORG'
          i_value   = 'GMUS'.
    ENDFORM.                    " zf_build_where

  • Dynamic where clause problem?

    Hi all,
    I am using 4 parameters for the attrition rate report of an employee on the selection screen.
    Level
    Grade
    Position
    Salary Range (pa0008-ansal)
    i have filled the values of level, grade, position, from database tables at the initialization event.
    And for the salary range i hardcoded them to 0-5000, 5001-10000 etc.. and so on.
    and then showed all 4 parameters are listbox on the selection screen.
    now the first 3 parameters are from infotype pa0001 and the last is from pa0008.
    Now I want to select pernr, persg ,persk ,plans, begda ,endda fields from infotype pa0001, and 'ansal' field from pa0008 , with the help of a dynamic where clause, is it possible, because here it might be needed for a join as well.
    Please help me out with some sample coding help.
    Regards
    Tarun

    DATA: lv_query TYPE string.
      lv_query = ' '.
      IF  position IS NOT INITIAL.
        IF lv_query IS NOT INITIAL.
          CONCATENATE lv_query '  and p1~plans eq   position '  '' INTO lv_query.
        ELSE.
          CONCATENATE  ' p1~plans eq  position '  '' INTO lv_query.
        ENDIF.
      ENDIF.
      IF  grade IS NOT INITIAL.
        IF lv_query IS NOT INITIAL .
          CONCATENATE lv_query '  and p1~PERSK eq  grade ' '' INTO lv_query.
        ELSE.
          CONCATENATE '  p1~PERSK eq  grade  ' '' INTO lv_query.
        ENDIF.
      ENDIF.
      IF  level IS NOT INITIAL.
        IF lv_query IS NOT INITIAL .
          CONCATENATE lv_query '  and p1~PERsg eq  level ' '' INTO lv_query.
        ELSE.
          CONCATENATE ' p1~PERsg eq  level  ' '' INTO lv_query.
        ENDIF.
      ENDIF.
      IF  sal_slab IS NOT INITIAL.
        SELECT pernr ansal begda endda FROM pa0008 INTO CORRESPONDING FIELDS OF TABLE lt_st_p8 WHERE ansal = sal_slab.
        *IF lv_query IS NOT INITIAL .*
          *CONCATENATE lv_query '  and p8~ansal le  sal_slab ' '' INTO lv_query.*
        *ELSE.*
          *CONCATENATE '  p8~ansal le  sal_slab  ' '' INTO lv_query.*
        *ENDIF.*
      ENDIF.
    SELECT p1~pernr
        p1~persg p1~persk p1~plans p1~begda p1~endda
         p8~ansal
      INTO CORRESPONDING FIELDS of TABLE lt_st_p1_p8
        FROM pa0001 AS p1 JOIN pa0008 AS p8  ON p1~pernr = p8~pernr
        WHERE (lv_query) .
    <Added code tags>
    Now in case of salary slab, i have ranges like 0-5000 , 5001-10000 and so on and I showed it as a listbox on sel. screen.
    So how can I read the figure after the '-'?????
    And also review, if for the previous 3 parameters it is correct, or it can be shortened and accurated.
    Edited by: Suhas Saha on Dec 28, 2011 1:44 PM

  • Dynamic where clause: Urgent

    Hi,
    I am facing a problem with data retrieval in a BADI with dynamic where clause.
    I have a variable defined as:
    data: lv_where_condn    TYPE string.
    I concatenate the data in the string based on the user's input and perform the following select:
       SELECT *
       FROM zd_apo_prodvar1
       INTO TABLE lt_data
       WHERE (lv_where_condn).
    The sy-subrc returns a value 4 although there is data in the system for the users data input.
    Earlier it used to give a short dump which I have now take care of with the catch statement.
    SAP has suggested the following:
    This problem happens if an attempt was made to bind or define a variable character string with a buffer length less than the two-byte minimum requirement. Please check the variable definition in your custom code and increase the buffer size or use a different type.
    Any inputs will b appreciated in declaring the dats type for lv_where_condn.
    cheers
    Aveek

    hi,
    check this sample ..
    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.
    Regards
    vijay

  • Dynamic where clause for generated reports (designer 6.0)

    Hi,
    I'd like to include dynamic where clause into my reports. It's easy with report builder by using bind parameter in a query where clause (&param where param is a parameter in which you fill a VARACHAR2 to complete default where clause).
    Problem with designer 6.0 report generator is that he failed while trying to parse the query statement he contructs if there is a bind parameter within.
    How can I manage this problem ?
    Thanks for answers
    Romain

    Hi Divya,
         SET_REPORT_OBJECT_PROPERTY(repid,REPORT_OTHER,'paramform=no P_WHERE_CLAUSE= '||Where_Clause);Instead of using SET_REPORT_OBJECT_PROPERTY built in try using ADD_PARAMETER built in which
    adds parameters to a parameter list. Each parameter consists of a key, its type, and an associated value.
    v_rep := RUN_REPORT_OBJECT(repid); and instead of using RUN_REPORT_OBJECT try using RUN_PRODUCT.
    DECLARE
         repid REPORT_OBJECT;
         v_rep  VARCHAR2(100);
         Where_Clause Varchar2(4000) := null ;
            *Pl_Id        ParamList;*
            *Pl_Name      VARCHAR2(10) := 'param_list';*
    BEGIN
         Where_Clause := 'Where '||Create_Where_Clause();
         message(Where_Clause);
         message(' ');
            pl_id := Get_Parameter_List(pl_name);
            IF not Id_Null(pl_id) THEN
               Destroy_Parameter_List(pl_id);
            END IF;
            pl_id := Create_Parameter_List(pl_name);
            Add_Parameter(pl_id,'P_WHERE_CLAUSE', TEXT_PARAMETER, WHERE_CLAUSE);
            Add_Parameter(pl_id,'PARAMFORM',TEXT_PARAMETER,'NO');
    --      Add_Parameter(pl_id,'ANY_OTHER_PARAMETER', TEXT_PARAMETER, 'VALUE FOR OTHER PARAMETER');
            RUN_PRODUCT(REPORTS,'REPORT_NAME', ASYNCHRONOUS, RUNTIME, FILESYSTEM, pl_id, NULL);
    END;Also you can add as many User created or System parameters as you want using add_parameter. Updated the code to add PARAMFORM parameter.
    Best Regards
    Arif Khadas
    Edited by: Arif Khadas on Mar 15, 2011 9:31 AM

Maybe you are looking for

  • AS400 Connection : when I am trying to run jsf pages..then  java.lang.ClassCastException: getting

    Hi I did connection with AS400 database.When I am trying run JDE.jsf file then I am getting java.lang.ClassCastException: weblogic.jdbc.wrapper.PoolConnection_com_ibm_as400_access_AS400JDBCConnection cannot be cast to oracle.jdbc.OracleConnection err

  • Some minor issues with Windows 7

    I have a Thinkpad SL400 and the 64bit version of Windows 7.  For the mostpart, everything works pretty smoothly but I do have a few issues.  My volume buttons are unresponsive, and the battery bar for the power manager says that I do not have a batte

  • Some keys of e70 not working

    Hi guys, i have the problem that the keys "7, U, J" and "M" on my keypad are not working. Just nothing happens when I press them. I already removed the rubber-keypad once and pushed the real buttons beneath it. This didn't help. I also tried a hard r

  • Payroll not possible because data is missing: WPBP: 01 SV: 00 ST: 00

    Hi, I have created a new org structure with a set of employee. I have maintained all the needed infotypes ( 0000,0001,0003,0007,0008..) When i try to run payroll for those emp's, im getting the error message: <u>Payroll not possible because data is m

  • Cannot publish a report from BW to Business Objects Enterprise XI 3.1

    I have installed all of the applications required in the correct order and had this working at one point.  When I went back to use it, it would no longer connect.  I then wanted to change from one BW dev source to another and now I get: "An error occ