Dynamic queries

I am trying to use "? parameter style" to execute dynamic queries at runtime on the view object. I was sucessful in using this for the rowsetInfo but i want to do this for a view object. I cant seem to call the new queries after i assign the new where clause to the VO using the whereClauseParams(). I am building an applet/application. Does anyone have any examples....( ie : oracle people)?

I looked at the help-topics under creating and changing view object queries in the code....however how do i tie this into the view objects i already created using BC4J...Here is my code for example:
ApplicationModule appmod = sessionInfo1.getApplicationModule();
ViewObject vo = appmod.findViewObject("PARAMVIEW");
vo.setWhereClause("MGR > 1000");
vo.executeQuery();
rowSetInfo1.executeQuery();
---this does not work!!!!
this does however
rowSetInfo1.setWhereClause("MGR > 1000");
rowSetInfo1.executeQuery();
i want to use the vo because i was told that the rowSetInfo.executeQuery runs on the client side (in Help- 'ABOUT Dynamic Clauses in Data Form'-->"...the addition of dynamic WHERE and ORDER BY clauses that execute on the data form *client*")while the vo.executeQuery on the server side...Does anyone know if this is true...and if this will improve performances in an applet or am i just waisting my time?
thanks

Similar Messages

  • Dynamic queries in weblogic

    In case of dynamic queries, I found out that the finder method can not be defined
    in the Home class. I defined the finder
    method in the Bean.
    In my Bean, this is the code:
    public Collection findAllActivities(String filter, Object[] arguments) throws
    FinderException
         Properties myProp = new Properties();
         for(int i = 0; i < arguments.length; i++)
              myProp.setProperty(String.valueOf(i), String.valueOf((arguments)));
         try
              InitialContext ic = new InitialContext();                
              RolesHome rh = (RolesHome)ic.lookup("RolesHome");     
              QueryHome qh = (QueryHome)rh;
              String weblogicQL = "SELECT DISTINCT OBJECT(o) FROM roles AS o" + filter;
              Query query = qh.createQuery();
              return query.find(weblogicQL, myProp);
         catch (Exception e)
              e.printStackTrace();
              return null;
    I get a naming exception if I use :      RolesHome rh = (RolesHome)ic.lookup("RolesHome");
    javax.naming.NameNotFoundException: Unable to resolve 'RolesHome' Resolved: ''
    Unresolved:'RolesHome' ; remaining name
    'RolesHome'
    I get a casting exception if I use:      RolesHome rh = (RolesHome)ic.lookup("Roles");
    In my jsp file:
    I have this code
    InitialContext jndiContext = new InitialContext();
    Object obj = jndiContext.lookup("Roles");
    RolesHome rolesHome = (RolesHome) obj;
    list = (ArrayList) rolesHome.findAllActivities(filter, filterParams);          
    but the problem is that the home interface does not contain the findAllActivities
    function. I have already defined rolesHome
    earlier in the code which I want to use for findAllActivities also. I can not
    cast the bean e.g. RolesBean rolesBean = (
    RolesBean) rolesHome. I do not want to create a new bean as I am already using
    an old rolesHome. How do I solve this
    problem??? Please do let me know. I am really confused.
    Thanks
    Ronak Parekh

    This should be posted to the ejb newsgroups
    mbg
    "ronak" <[email protected]> wrote in message
    news:3e57faa9$[email protected]..
    >
    In case of dynamic queries, I found out that the finder method can not bedefined
    in the Home class. I defined the finder
    method in the Bean.
    In my Bean, this is the code:
    public Collection findAllActivities(String filter, Object[] arguments)throws
    FinderException
    Properties myProp = new Properties();
    for(int i = 0; i < arguments.length; i++)
    myProp.setProperty(String.valueOf(i), String.valueOf((arguments)));
    try
    InitialContext ic = new InitialContext();
    RolesHome rh = (RolesHome)ic.lookup("RolesHome");
    QueryHome qh = (QueryHome)rh;
    String weblogicQL = "SELECT DISTINCT OBJECT(o) FROM roles AS o" + filter;
    Query query = qh.createQuery();
    return query.find(weblogicQL, myProp);
    catch (Exception e)
    e.printStackTrace();
    return null;
    I get a naming exception if I use : RolesHome rh =
    (RolesHome)ic.lookup("RolesHome");
    >
    javax.naming.NameNotFoundException: Unable to resolve 'RolesHome'Resolved: ''
    Unresolved:'RolesHome' ; remaining name
    'RolesHome'
    I get a casting exception if I use: RolesHome rh =(RolesHome)ic.lookup("Roles");
    >
    >
    In my jsp file:
    I have this code
    InitialContext jndiContext = new InitialContext();
    Object obj = jndiContext.lookup("Roles");
    RolesHome rolesHome = (RolesHome) obj;
    list = (ArrayList) rolesHome.findAllActivities(filter, filterParams);
    but the problem is that the home interface does not contain thefindAllActivities
    function. I have already defined rolesHome
    earlier in the code which I want to use for findAllActivities also. I cannot
    cast the bean e.g. RolesBean rolesBean = (
    RolesBean) rolesHome. I do not want to create a new bean as I am alreadyusing
    an old rolesHome. How do I solve this
    problem??? Please do let me know. I am really confused.
    Thanks
    Ronak Parekh

  • Data series / dynamic queries

    Hi,
    I've got the following problem:
    I want to create a stacked bar chart based on dynamic queries. The query I use for the first series is:
    select null link, kw label, sum (volume) value from testview
    where id = to_number(:P18_ID)
    group by kw
    order by kw
    P18_ID is an input field.
    The query works fine and the chart is also ok.
    But if I use this same query for a second series I get an empty svg canvas as result. Even worse: no matter what kind of query I use for the second series I never get a result unless I take the variable P18_ID away from the first query.
    For info: the view testview is based on a table created by a pl/sql function (using pipelined output).
    Any ideas. I really would appreciate a quick answer very much because this is part of a project and we are running out of time because of this error.
    Thanks.

    Hi Andy,
    first of all: thank you very much for your efforts.
    I've tried something like you said before and yes, it works (at least most of the times). The problem is I want to have the option 'show all'. That's why I can't use a' where' clause (because I can't work with 'like ...%' for it would sometimes give wrong results because of ids with the same prefix -> or am I wrong?)
    What I mean is:
    where id like '1'% -> results for item 1 (and 10,11,12,...)
    where id like ' '% -> results for all items
    That's why I want to use a pl/sql function. The function is tested and works fine. But if I try to call it form ApEx it works only if use constants instead of variables or if I have only one series.
    Is there something like a time limit? Like ApEx stops processing if the database isn't answering as fast as expected (because a function is slower than querying a table). I don't really think that could be the answer because it's very little data and I'm using a pipelined function... but perhaps...

  • Dynamic Queries with JSP

    I am developing a search page which should first bring the results sorted by some particular field & then the user should have the option of sorting the results by other field names which are provided in a form list.
    For generating dynamic requests, ? is used in place of parameter. But for some reason it is not working with Order by. Other dynamic queries are working fine. Please let me know the right way to handle it.
    And also if someone can advise a good reference book for dynamic SQL statements in accordance with JSP.
    Thanks for your time.

    Never mind my previous solution. Some success was not perfect, therefore not acceptable. I used a scriplet and the problem is solved!
      <!-- Dynamically build the query -->
        <%
          String sql = "select * from issue_list_view";
          String where = null;
          String param = null;
          // Status
          param = (String)pageContext.getAttribute("status");
          if(param != null && param.compareTo("")!=0)
            where = "status='"+param+"'";
          else
            where = "status not in ('Closed','Duplicate')";
          // Assigned To
          param = (String)pageContext.getAttribute("assign");
          if(param != null && param.compareTo("")!=0)
            if(where.length()>0) {where += " and ";}
            where = "category='"+param+"'";
          // Category
          param = (String)pageContext.getAttribute("category");
          if(param != null && param.compareTo("")!=0)
            if(where.length()>0) {where += " and ";}
            where = "category='"+param+"'";
          // Type
          param = (String)pageContext.getAttribute("type");
          if(param != null && param.compareTo("")!=0)
            if(where.length()>0) {where += " and ";}
            where += "issue_type='"+param+"'";
          // Id
          param = (String)pageContext.getAttribute("id");
          if(param != null && param.compareTo("")!=0)
            if(where.length()>0) {where += " and ";}
            where += "issue_id="+param;
          // Add where clause if needed
          if(where != null) { sql += " where " + where; }
        %>
        <!-- Do the query -->
        <sql:query var="issues" sql="<%=sql%>"/>

  • Dynamic queries best practice

    Hello,
    I want to create a report that the user can use radio buttons to refine. As an example, referring to the apex sample application's Products page, add radio buttons for [>] All prices [>] under $500.
    I think the technique demonstrated for building dynamic query reports (this is a 1.6 tutorial,link to it is here) is the way to do this, but I'm not sure this is the best approach.
    I'm wondering about any design disadvantage. I'd appreciate comment. Also, if there is a working example with source view in the public apex workspaces you are aware of, post a link if there's value beyond the tutorial I mentioned.
    Thank you.
    Albert

    I am using dynamic queries from time to time. Here is a working example:
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    You may have a look.
    Denes Kubicek

  • How to escape apostrophe in Oracle PL/SQL  dynamic queries

    I have an script that receives an string as a parameter, for example:
    @C:/myScript.sql "AXEL";
    @C:/myScript.sql "AXEL DAVID";
    @C:/myScript.sql "o'neal";
    my scripts basically constructs a Parameterized query an execute it. That's all. It works most of the time, except when the parameter contains apostrophes
    DEFINE myparameter = &&1
    myquery := "Select * from myTable where x = :p1";
    EXECUTE IMMEDIATE myquery into results USING myparameter;
    ...When trying the following;
    @C:/myScript.sql "o'neal";
    I get the following error:
    Bind Variable "p1" is NOT DECLARED
    Of course if I change the parameter as "o''neal" It will work, but I will end up with other issues later on, so I would like to know how can I deal with apostrophe on dynamic queries.
    I also tried to use the following:
       myquery := "Select ....  where x = " || Q'#:p1#';
    ...but not working.
    any hint will be appreciated =)
    Edited by: user13679988 on Nov 22, 2012 3:12 PM
    Edited by: user13679988 on Nov 22, 2012 3:38 PM
    Edited by: user13679988 on Nov 22, 2012 3:45 PM

    DUPLICATE THREAD! and WRONG FORUM!
    This forum is for SQL Developer questions only and your question has nothing to do with sql developer. Please mark this question ANSWERED.
    You have already posted this question in the SQL and PL/SQL forum and should continue to use that thread.
    How to replace 2 single quotes to single quote

  • Enabling dynamic queries in wl7

    How do I enable dynamic queries in WL7. The info provide here is not very clear...like how/what to change in ejb-jar.xml http://e-docs.bea.com/wls/docs70/ejb/cmp.html#1089703

    Hi Minh,
    This is the second time I've answered this question in a week. I'll make sure the documentation gets clarified.
    You enable dynamic queries in your weblogic-ejb-jar.xml file with the following:
    <enable-dynamic-queries>True</enable-dynamic-queries>
    You can optionally set a method permission in ejb-jar.xml to control access to the feature. An example follows:
    <security-role>
    <role-name>Admin</role-name>
    </security-role>
    <method-permission>
    <role-name> Admin </role-name>
    <method>
    <ejb-name> EmployeeEJB </ejb-name>
    <method-name> createQuery </method-name>
    </method>
    </method-permission>
    - Matt
    Minh Cao wrote:
    How do I enable dynamic queries in WL7. The info provide here is not very clear...like how/what to change in ejb-jar.xml http://e-docs.bea.com/wls/docs70/ejb/cmp.html#1089703

  • Dates and dynamic queries

    Hi.
    I am retrieving Entity EJBs using dynamic queries.
    I had some troubles working with dates.
    This is an example about the kind of query I am talking about:
    SELECT OBJECT(a) FROM Payment AS a WHERE a.date <= '2/3/2005'
    It worked prefectly fine in development environment.
    So far so good, but finally it did not work properly in production.
    I think the reason is that date format configuration is different (after all, all other queries without any date parameter works fine).
    How can I set date format for Weblogic Server 8.1?
    Or maybe some other idea about what is going on?
    Thanks in advance
    Oscar

    I'd use a java.sql.PreparedStatement and let it worry about properly escaping that Date. I'd also be leery of returning a ResultSet. That's a database cursor, a scarce resource. Better to load the result of your query into a data structure and close the ResultSet right away.
    String sql = "SELECT * FROM purchasedTransaction "
                      + "WHERE "
                      + "transactionDate >= ? AND transactionDate <= ?";
    PreparedStatement statement = connection.prepareStatement(sql);
    statement.setDate(1, theDateFrom);
    statement.setDate(2, theDateTo);
    ResultSet result = statement.executeQuery();
    while (result.next())
    // load your query into a data structure of some kind and return that.
    result.close();
    statement.close();Returning a CachedRowSet would be better than a ResultSet:
    http://www.javaworld.com/javaworld/jw-02-2001/jw-0202-cachedrow.html
    MOD

  • Using "enable-dynamic-queries"

    Has any one used <enable-dynamic-queries>True</enable-dynamic-queries> in weblogic-ejb-jar.xml?
    If yes, where exactly do you specify that? As per the DTD, you do it in "<entity-descriptor>"
    element. I tried that but I can't deploy the application on wls 7.
    Any ideas what might be wrong?
    Also, does anyone know if I WLS 7 supports using WL extensions to EJB-QL for writing
    dynamic queries?
    Thanks for the help.

    Here's the relevant section of my weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>ABC</ejb-name>
    <entity-descriptor>
    <entity-cache>
    <concurrency-strategy>Exclusive</concurrency-strategy>
    </entity-cache>
    <persistence>
    <persistence-type>
    <type-identifier>WebLogic_CMP_RDBMS</type-identifier>
    <type-version>6.0</type-version>
    <type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
    </persistence-type>
    <db-is-shared>false</db-is-shared>
    <persistence-use>
    <type-identifier>WebLogic_CMP_RDBMS</type-identifier>
    <type-version>6.0</type-version>
    </persistence-use>
    </persistence>
    <enable-dynamic-queries>True</enable-dynamic-queries>
    </entity-descriptor>
    <local-jndi-name>ABC</local-jndi-name>
    </weblogic-enterprise-bean>
    Here's the stack trace for the error.
    ####<Jun 6, 2002 12:11:39 PM EDT> <Info> <HTTP> <MKDW> <myserver> <main> <kernel
    identity> <> <101202> <_appsdir_exploded_dir:web preparing>
    ####<Jun 6, 2002 12:11:40 PM EDT> <Error> <Deployer> <MKDW> <myserver> <main> <kernel
    identity> <> <149205> <The Slave Deployer failed to initialize the application appsdirexploded_dir
    due to error weblogic.management.ApplicationException: Prepare failed. Task Id =
    null
    Module Name: ejb, Error: The XML parser encountered an error in your deployment descriptor.
    Please ensure that your deployment descriptor corresponds to the format in the DTD.
    The error was:
    org.xml.sax.SAXParseException: Element type "enable-dynamic-queries" must be declared.
         at weblogic.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1273)
         at weblogic.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1889)
         at weblogic.apache.xerces.validators.common.XMLValidator.validateElementAndAttributes(XMLValidator.java:3714)
         at weblogic.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:1242)
         at weblogic.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1186)
         at weblogic.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:396)
         at weblogic.apache.xerces.framework.XMLParser.parse(XMLParser.java:1119)
         at weblogic.xml.process.ProcessorDriver.process(ProcessorDriver.java:133)
         at weblogic.ejb20.dd.xml.WebLogicEjbJarLoader_WLS600.process(WebLogicEjbJarLoader_WLS600.java:469)
         at weblogic.ejb20.dd.xml.DDUtils.processXML(DDUtils.java:252)
         at weblogic.ejb20.dd.xml.DDUtils.processXML(DDUtils.java:216)
         at weblogic.ejb20.dd.xml.DDUtils.processWLEjbJarXML(DDUtils.java:202)
         at weblogic.ejb20.dd.xml.DDUtils.createDescriptorFromJarFile(DDUtils.java:100)
         at weblogic.ejb20.dd.xml.DDUtils.createDescriptorFromJarFile(DDUtils.java:85)
         at weblogic.ejb20.deployer.EJBModule.loadEJBDescriptor(EJBModule.java:491)
         at weblogic.ejb20.deployer.EJBModule.loadDescriptor(EJBModule.java:213)
         at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:628)
         at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:548)
         at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:437)
         at weblogic.management.deploy.slave.SlaveDeployer.prepareAllStagedApplications(SlaveDeployer.java:478)
         at weblogic.management.deploy.slave.SlaveDeployer.initialize(SlaveDeployer.java:252)
         at weblogic.management.deploy.DeploymentManagerServerLifeCycleImpl.initialize(DeploymentManagerServerLifeCycleImpl.java:150)
         at weblogic.t3.srvr.ServerLifeCycleList.initialize(ServerLifeCycleList.java:54)
         at weblogic.t3.srvr.T3Srvr.initialize1(T3Srvr.java:762)
         at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:588)
         at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:276)
         at weblogic.Server.main(Server.java:31)
    --------------- nested within: ------------------
    weblogic.xml.process.XMLParsingException: Element type "enable-dynamic-queries" must
    be declared. - with nested exception:
    [org.xml.sax.SAXParseException: Element type "enable-dynamic-queries" must be declared.]
    File: META-INF/weblogic-ejb-jar.xml Line: 211 Column: 37
         at weblogic.xml.process.ProcessorDriver.process(ProcessorDriver.java:137)
         at weblogic.ejb20.dd.xml.WebLogicEjbJarLoader_WLS600.process(WebLogicEjbJarLoader_WLS600.java:469)
         at weblogic.ejb20.dd.xml.DDUtils.processXML(DDUtils.java:252)
         at weblogic.ejb20.dd.xml.DDUtils.processXML(DDUtils.java:216)
         at weblogic.ejb20.dd.xml.DDUtils.processWLEjbJarXML(DDUtils.java:202)
         at weblogic.ejb20.dd.xml.DDUtils.createDescriptorFromJarFile(DDUtils.java:100)
         at weblogic.ejb20.dd.xml.DDUtils.createDescriptorFromJarFile(DDUtils.java:85)
         at weblogic.ejb20.deployer.EJBModule.loadEJBDescriptor(EJBModule.java:491)
         at weblogic.ejb20.deployer.EJBModule.loadDescriptor(EJBModule.java:213)
         at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:628)
         at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:548)
         at weblogic.j2ee.J2EEApplicationContainer.prepare(J2EEApplicationContainer.java:437)
         at weblogic.management.deploy.slave.SlaveDeployer.prepareAllStagedApplications(SlaveDeployer.java:478)
         at weblogic.management.deploy.slave.SlaveDeployer.initialize(SlaveDeployer.java:252)
         at weblogic.management.deploy.DeploymentManagerServerLifeCycleImpl.initialize(DeploymentManagerServerLifeCycleImpl.java:150)
         at weblogic.t3.srvr.ServerLifeCycleList.initialize(ServerLifeCycleList.java:54)
         at weblogic.t3.srvr.T3Srvr.initialize1(T3Srvr.java:762)
         at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:588)
         at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:276)
         at weblogic.Server.main(Server.java:31)
    }.>

  • Content Presenter | Dynamic Queries at runtime ??

    Hello All,
    We have a use case where we need to build a dynamic query as part of our content presenter task flows. We have been able to achieve this for pages created at design time (in JDeveloper) using the CMIS queries and EL. The following excerpt from a page def file will tell you how we achieved this.
    <parameter id="datasourceType" value="${'dsTypeQueryExpression'}"/>
    <parameter id="datasource"
    value="${'SELECT * FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition = \'RD_TRAINING\' and ora:p:xLanguage=\''}${langBean.selectedLang}${'\''}"/>
    This works as expected.
    Now we are trying to achieve the same behavior for content presenter task flows added to pages at run time.
    We selected "Data Source" as "Result of a query", but we are not able to evaluate an EL under the "Additional Query Filters" section. We have to give hard coded strings for these filters to work.
    Any idea how we can create a "dynamic" content presenter at run time??
    Thanks,
    Prashant

    Hi Yannick,
    I think I wasn't clear with my problem statement. Let me try again.
    When I give the EL in the pageDef, the page works as expected at run time.....no issues here. Maybe if I encounter the bug that you mention, I will use the workaround ...thanks for this.
    The problem I am facing is when I add a content presenter task flow to a page at run time and try to configure it (using the 3 step wizard ...select content ....set content source as ‘Result of a query’ ...select template...preview)
    How do I give something dynamic here in my query? EL's are not getting evaluated here.
    Regards,
    Prashant

  • Createa a  method for creating dynamic queries

    Hi,
    I am trying to create a public method in a class to generate Dynamic SQL Queries.The method has 4 parameters :
    WHERESTRING TYPE STRING
    FROMTABLE TYPE STRING
    SELECTFIELDS TYPE STRING
    INTOTABLE TYPE ANY TABLE
    the process is :
    SELECT (selectfields) FROM (fromtable) INTO <INTOTABLE> WHERE (wherestring).
    However I get error in the INTOTABLE, it does not recognize the parameter. What am I doing wrong ?

    Resolved myself!

  • Size Constraints of Lexical Reference Types/Dynamic Queries

    Can any Oracle guru's tell me what the maximum length is for a Lexical Reference.
    Our project here reads a dynamic sql statement from a table that has been parsed into four seperate columns. We load this into four User Parameters p_select1, p_select2, p_select3, and p_select_4. All are defined as varchar2(2000).
    The query in the data model looks like this.
    &p_select1
    &p_select2
    &p_select3
    &p_select4
    These queries can get quite large. Sometime if it is too large and you run the report it dies a horrible death.
    I have read somewhere that the select statement cannot exceed 64k but, I don't know how this relates to how much you can fit into each line of the query.
    Hopefully, that makes sense.
    Thanks,
    Bob

    I should add that we are on Reports6 and Oracle 8. Thanks

  • Dynamic queries in report builder 6i ( ref cursor query )

    Hi everyone,
    My requirement is that I want to create a report where the query is dynamic. The dynamic part will be known at runtime as it is being passed via a parameter. My query looks like this :
    select * from emp where sal :p1 :p2
    Possible values for :p1 are - '>', '<', '>=', '<=', '=', '!='
    Possible values for :p2 are - any value entered by the user
    I tried creating a query in report builder based on a ref cursor. But it does not allow me to create the query for the ref cursor dynamically. That means I have to hardcode the query in the program.
    I tried using place holder columns without success.
    Can someone please help me ?
    Regards,
    Al

    Hi,
    You can use lexical paramters in the sql query
    x - char - parameter
    select * from emp &x
    you need to pass the value for x in the parameter as
    'where sal < 1234'.
    Note : Lexical variable should be of char datatype.
    This is an alternative to the ref cursors.
    This works. Hope this is clear.

  • Dynamic queries in stored procedures - JDBC

    Hi,
    How do we write a query in stored procedures if the field to be selected,conditions & sort order are dynamic?
    The user selected the columns,conditions & sort order only at run time.
    Thanks in advance,
    sundar

    The syntax for a stored procedure varies by database. And support for dynamic SQL in a stored proc varies to. And it has nothing to do with java. So you are more likely to get better responses by asking the question on a board/list that is specific to your database and that address stored procedures.
    And to get a response here you need to specify the database your are using, and the version might be a good idea too.
    And from the design prespective you might keep in mind that dynamic SQL is significantly slower than other forms. And it is also harder to debug and code for. So you might want to consider why you need to do that.
    Perhaps you actually want to know how to create dynamic SQL in Java instead?

  • Dynamic Queries in ABAP?

    Hi,
    I'm currently trying to develop an RFC FM that can create a dynamic query. I want to use the FM to query different tables without having to write n number of different cases.
    For example a particular application might need to query table xyz with three fields defined in the where clause. Another app might need to query the same table with only two fields defined in the where clause. In the same way I would like to be able to use the very same FM to query another table abc with x number of parameters.
    I'd like to send the where clause in a table.
    Is that possible?

    hi Roberto,
    try with this function.
    FUNCTION ztest.
    ""Local Interface:
    *"  IMPORTING
    *"     REFERENCE(EXTRACT_TABLE) TYPE  DD02L-TABNAME
    *"     REFERENCE(WHERE_TAB) TYPE  WHERECONDS
    *"     REFERENCE(FIELD_LIST) TYPE  WHERECONDS
    *"  EXPORTING
    *"     REFERENCE(RETURN_TABLE) TYPE  TABLE
      TYPE-POOLS: abap.
      FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                     <dyn_wa> TYPE ANY.
      DATA: dy_table TYPE REF TO data,
            dy_line  TYPE REF TO data,
            xfc TYPE lvc_s_fcat,
            ifc TYPE lvc_t_fcat,
            field_line TYPE wherecond.
    data: fields(1000).
      DATA : idetails TYPE abap_compdescr_tab,
             xdetails TYPE abap_compdescr.
      DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?= cl_abap_typedescr=>describe_by_name( extract_table ).
      idetails[] = ref_table_des->components[].
      LOOP AT idetails INTO xdetails.
        READ TABLE field_list WITH KEY text = xdetails-name TRANSPORTING NO FIELDS.
        check sy-subrc = 0.
        CLEAR xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        APPEND xfc TO ifc.
      ENDLOOP.
    Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ifc
        IMPORTING
          ep_table        = dy_table.
      ASSIGN dy_table->* TO <dyn_table>.
      LOOP AT field_list INTO field_line.
        CONCATENATE fields field_line-text INTO fields SEPARATED BY space.
      ENDLOOP.
    Select Data from table.
      SELECT (fields) FROM (extract_table) INTO TABLE <dyn_table> WHERE (WHERE_TAB).
      return_table[] = <dyn_table>.
    ENDFUNCTION.
    where
    EXTRACT_TABLE -->  name of the table
    WHERE_TAB       -->  internal table contains the where conditions
    FIELD_LIST          -->  list of fields that u want
    RETURN_TABLE  -->  dynamic table returns the selected values

Maybe you are looking for