How to specify custom query as well as a selection criteria

Hi
I'm struggling to specify a custom select query with variable no. of agruments through toplink.
The custom query looks like:
select outer.col1, outer.col2, outer.col3,
outer.effective_date, outer.capacity_rate, outer.expiry_date, outer.comments, outer.create_date,
outer.create_user_id, outer.modify_date, outer.modify_user_id, outer.vol_uom_type_code
from tbl outer,
( select max(effective_date) effective_date, col1, col2, col3 from tbl
where expiry_date is null
or (trunc(effective_date) >= to_date('01/01/'||to_char(sysdate,'yyyy'), 'dd/mm/yyyy') )
group by col1, col2, col3
) inner
where outer.col1 = inner.col1
and outer.col2 = inner.col2
and outer.col3 = inner.col3
and trunc(outer.effective_date) = trunc(inner.effective_date)
My domain class TBL.class is mapped one to one with DB Table TBL.
With this customer query, I want to add a selection criteria depending upon what is specified on the UI-screen - I can get col1, col2 or a combination of these as search criteria.
So far I have tried multiple approaches:
1. Specifying the custom query (without arguments) as a ReadAll Query in toplink descriptor and then using expression builder to add the criteria but this doesn't work as custom ReadAll query gets overridden and i get back all the results from
TBL which match the criteria specified.
expFinal = new ExpressionBuilder().get("col1").equal(srchCriteria.getCol1());
results = (List) getTopLinkTemplate().readAll(TBL.class,expFinal,false);
2. Using Named Query:
Toplink doesn't allow me to specify a custom SQL along with a selection criteria - both for the same NamedQuery.
3. Specifying the DB query in java layer and then adding arguments and argument values. When query is executed, i don't see arguments being added.
ReadAllQuery query = new ReadAllQuery(TBL.class);
query.setSQLString(READ_ALL_QUERY);
ExpressionBuilder exp = new ExpressionBuilder();
query.addArgument("col1", Long.class);
Vector vect = new Vector();
vect.add(srchCriteria.getCol1());
query.addArgumentValues(vect);
result = (List) getTopLinkTemplate().executeQuery(query, false);
Please suggest. Would be great if you could share some code bits.
Thanks
Nitin

Nitin,
This style of query does require code to apply logic as it is created. If you wish to have this used as a named query you can use a query re-direct so that instead of executing a query we call a method of yours.
You can setup your named query to use re-direction into a static method as:
        QueryRedirector redirector = new MethodBaseQueryRedirector(QueryRedirectorExample.class, "redirectMethod");
        ReadAllQuery raq = new ReadAllQuery(Employee.class);
        raq.addArgument("FIRST_NAME");
        raq.setRedirector(redirector);
        descriptor.getDescriptorQueryManager().addQuery("findByFirstNameLike", raq);The static method that then gets invoked where you can dynamically create a query looks like:
    public static Object redirectMethod(DatabaseQuery query, Record record, Session session) {
        String firstName = (String)record.get("FIRST_NAME");
        ReadAllQuery raq = new ReadAllQuery(Employee.class);
        if (firstName != null) {
            raq.setSelectionCriteria(raq.getExpressionBuilder().get("firstName").likeIgnoreCase(firstName));           
        return session.executeQuery(raq);
    }Doug

Similar Messages

  • How to specify custom table name for subclasses in Kodo 3?

    I'm migrating our codes from Kodo 2.5.x to version 3.
    In Kodo 2.x, specifying the class/subclass table name uses the extension
    like this "@jdo.extension vendor-name="kodo" key="table"
    value="DyeStuffs"" when using XDoclet to generate the .jdo metadata files.
    It no longer works in Kodo 3. Following the Kodo's documentation, I have
    upgraded XDoclet to 1.2b3 and changed all doclet tags to the ones that
    XDoclet understands.
    I noticed in the documentation, to specify custom table mapping, it uses
    nested vendor extensions. E.g
    <extension vendor-name="kodo" key="jdbc-class-map" value="vertical">
    <extension vendor-name="kodo" key="table" value="TABLOID"/>
    <extension vendor-name="kodo" key="ref-column.JDOID"
    value="MAG_ID"/>
    </extension>
    So how do I specify nested extensions when using with XDoclet's tags?
    Need help as I have to complete the migration by end of the week.
    Thanks,
    Makas

    Abe White wrote:
    Makas Tzavellas wrote:
    Does it mean I have to map all classes and fields to the existing tables?As I tried to point out earlier, in 3.0 all mapping information must be
    explicit all the time. So basically everything is like mapping to an
    existing schema (only Kodo can generate those mappings for you... as
    long as you're not using XDoclet for all your mapping! :)
    It seems quite a pain to manually map all the existing tables and
    fields, especially when Kodo gave the table and field names. I don't
    mind mapping the tables, but mapping the fields will be a horror with
    105 tables. Have I missed out anything in the migration documentation
    that might help me with this process? Also does Kodo require the
    ..mapping file to work or having everything in .jdo file is sufficient
    (looking at the documentation it seems ok to have .jdo file only)?
    If I do, I prefer to regenerate all tables without the base table,
    basically having tables to include all the fields from the base table.
    And migrate all existing data to the new table structure.I'm not entirely clear on what you want. Are you saying that you want
    each subclass to have its own table and repeate the columns from its
    superclass table in its own?
    Yes, that is exactly what I want.
    If so, then this is not supported by Kodo (yet... we're working on it
    though).
    Ok, I'll settle having Kodo 3 to only map back to the original tables,
    as I believe Kodo 3 will provide some performance improvement as
    compared to 2.x.

  • How to specify custom SQL in polling db adapter with logical delete option

    Hi all,
    I am writing a SOA composite app using JDeveloper SOA Suite 11.1.1.4 connecting to a SQL Server db using a polling DB Adapter with the logical delete option to send data to a BPEL process.
    I have requirements which go beyond what is supported in the JDeveloper UI for DB Adapter polling options, namely:
    * update more than one column to mark each row read, and
    * specify different SQL for the logical delete operation based on whether bpel processing of the data polled was successful or not.
    A complicating factor is that the polling involves two tables. Here is my full use-case:
    1) Polling will select data derived from two tables: e.g. 'headers' and 'details' simplified for this example:
    table: headers
    hid - primary key
    name - data label
    status - 'unprocessed', 'processed', or 'error'
    processedDate - null when data is loaded, set to current datetime when row is processed
    table: details
    hid - foreign key pointed at header.hid
    attr - data attribute name
    value - value of data attribute
    2) There is a many:1 relationship between detail and header rows through the hid columns. The db adapter polling SELECT shall return results from an outer join consisting of one header row and the associated detail rows where header.status = 'unprocessed' and header.hid = details.hid. (This is supported by the Jdeveloper UI)
    3) The polled data will be sent to be processed by a bpel process:
    3.1) If the bpel processing succeeds, the logical delete (UPDATE) operation shall set header.status = 'processed', and header.processedDate = 'getdate()'.
    3.2) If bpel processing fails (e.g. hits a data error while processing the selected data) the logical delete (UPDATE) operation shall set header.status = 'failed', header.processedDate = 'getdate()', and header.errorMsg = '{some text returned from bpel}'.
    Several parts of #3 are not supported by the JDeveloper UI: updating multiple columns to mark the row processed, using getdate() to populate a value of one of those column updates, doing different update operations based on the results of the BPEL processing of the data (success or error), and using data obtained from BPEL processing as a value of those column updates (error message).
    I have found examples which describe specifying custom SQL using the polling delete option to create a template then modifying the toplink file(s) to specify custom select and update SQL to implement a logical delete. (e.g. http://dlimiter.wordpress.com/2009/11/05/advanced-logic-in-oracle-bpel-polling-database-adapter/ and http://myexperienceswithsoa.blogspot.com/2010/06/db-adapter-polling-tricks.html). But none of them match what I've got in my project, in the first case because maybe because I'm using a higher version of JDeveloper, and in the second I think because in my case two tables are involved.
    Any suggestions would be appreciated. Thanks, John

    Hi John,
    You've raised a good scenario.
    First of all let me say that the purpose of the DB polling transaction, is to have an option to initiate a process from a DB table/view and not to update multiple fields in a table (or have other complex manipulation on the table).
    So, when choose to update a field in a record, after reading it, you are "telling" the engine not to poll this record again. Sure, i guess you can find a solution/workaround for it, but I don't think this is the way....
    The question now is what to do?
    You can have another DB adapter where you can update the data after finishing the process. In that case, after reading the data (on polling transaction) - update the header.status = 'processed' for example, and after processing the selected data update the rest of the fields.
    Hope it make some sense to you.
    Arik

  • A/r Invoice report query based on posting date selection criteria

    Hi experts,
    I am trying to write a query to get the A/r invoice report including Docnum, Docdate, cardname, project, linetotal, taxcode, taxtotal.
    and i tried the below query
    SELECT T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName],T1.[LineTotal] FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocDate] >=[%0] AND  T0.[DocDate] <=[%1]
    In this query ,
    1) i am unable to sum up the linetotal( total before tax) 
    2) also unable to fetch the sum of taxamount.
    3) its more important , the above query will  me docnum , when i try to open that doc, it opens the 2007 docments. whereas the other details are correct like docdate, amount and all.
    example:   from date: 1/04/2011    to date: 28/07/2011
    Docnum    Docdate  cardname   linetotal.... etc
        2              1/04/11   XYZ              5000
    when i click the 2 (docnum)  it opens me the 04/04/2007  documents.
    how to limit the doc within the periods given?
    thanks in advance
    Dwarak

    Hi Rahul/Gordon,
    thanks for your query's .
    additionally,   i want this query without the A/r invoices whichever having credit memo as target doc. 
    and
    i have selection criteria as  T0.[U_Sec_Category] = '[%2]'  and this has 3 values like  1)CIM 2)BIN 3)DMP
    among these  CIM should be seen only only user1  and BIN & DMP only by user2.
    can u plz get me this
    thanks,
    Dwarak

  • SQ01 query on LDB BRF with selection criteria on BSEG

    Dear all,
    we built an inofset on LDB BRF (BKPF - BSEG) and a query with selection criteria based on both BKPF and BSEG tables.
    My proble : when the query select a posting fullfilling header data selection criteria but not line item criteria, it still displayed the header data in the layout.
    We set up a filter on the account to hide results where account is blank but we loss the filter exporting the result on access. So if anyome has a better idea, we'll be very thankfull.
    Br,

    Hi Rick,
    What Edan proposed will work as logical AND (both filters on dates will be checked simultaneously).
    Here is a solution.
    You’ll have a user entry variable on 0CALDAY.
    - Create a new variable on 0CALDAY, customer exit, mandatory, not ready for input. This variable should return the date entered in user entry variable.
    - Create a structure in columns.
    - New selection (let’s name it chg). Put there your KF and your Change date char. Restrict it by the user entry var. Hide it.
    - New selection (let’s name it crt). Put there your KF and your Created on date char. Restrict it by the customer exit var. Hide it.
    New formula (let’s name it FilteredAmount):
    ( 'chg' <> 0 ) * 'chg' + ( 'crt' <> 0 ) * 'crt'
    Create a condition:
    FilteredAmount <> 0.
    Best regards,
    Eugene

  • How to bring values with out loop as per selection criteria

    Hi Everyone,
    We are doing some re-design in IPAD in that i am facing an issue. There is one scenario where sub-action loop has been used(it is an existing functionality). We dynamically bring the question in this loop based on certain seller phase.
    Now they want to bring everything in one screen it self. The table they are looping is complex table.
    Any ideas how we can achieve this problem.
    The idea which i have:
    During fetch i need to loop and this complete table and get these values in to variables, so that i can hide remaining fields based. Is there any other way do it.
    Regards,
    Gupta

    It's difficult to really give steps without knowing your application better but here goes my best shot at it.
    In terms of underlying structures on the client, I am assuming you have a questionsCT, a question object (with the desired fields to displa and a tempQuestions collection on your Main Object to hold the displayed questions.
    1) Create an Edit Transaction on the main object with one property of the tempQuestions collection.  This property should be set to Auto-Initialize.  When this transaction is involved from an action and applied it will clear the tempQuestions collection.
    2) On the question object, create an Add transaction to populate the object fields from the corresponding questionCT current record.  For each of the transaction properties set the Initial Value to "From a different object property" and then browse to the Complex Tables selecting your questionsCT -> current record -> field name.
    3) Create your Add question Action to call the AddQuestion Transaction and Apply.  This will be the action called from your subaction loop.
    4) Create your refresh action with the following steps
        a) Transaction - (#1)
        b) Apply
        c) Sub-Action
            c1) Execution Type: Loop over collection
            c2) Collection: Browse and select your questionsCT
            c3) Execution Rule: Define a new rule to return true if the current record meets your selection criteria
            c4) Action: Seelct your Add question action (#3)
    On your detail screen, I am assuming you will have a dropdown or some similar way to set the selection criteria.  Create a button field that will call your refresh action (#4) and add a tile list control targeting the tempQuesitons collection as it's source.
    This should hopefully get you started in the right direction.
    --Bill

  • How to specify custom page size in points?

    Have done the usual searches and not hit anything.
    Has anyone worked out how to get the custom sizes in Print Setup… to be measured in Points?
    I have a job where I need to work to screen resolution.
    The two System choices are for Metric which oddly shows in mm when everything else is in cm, or US measurements which are in inches (at least they aren't cubits).
    Nothing I see will switch it to the most accurate, by pdf/PostScript standards, of showing the measure in points.
    I have a vague recollection of having done this years ago in an OS far, far away. Could have been OS9, Windows or Linux of some ilk.
    Peter

    Peter,
    I have looked at this again in Pages ’09, and via Page Setup > Paper: Manage Custom Sizes..., it will not let me override the inch measurements.
    Try this to get two decimal places. Double-click the mm value in the paper size to select all, and then just type your mm setting with two decimal places (no mm text designation) and then tab out of that entry window. The two decimal setting is retained.
    This is redundant knowledge, but here is the conversion fluff. Inches in Page Setup may need to be set to approximate closest points. In the Postscript (cough) world, the conversion is:
    1 Point = 0.01388888889 Inch
    And the calculator (with round option).

  • How to specify custom namespace in generating WSDL for BAPI

    In the creation of the Web Service Definition(WSDL) for a rfc-enabled function module, I would like to specify the custom namespace rather than the default in /sap/bc/srt/rfc/sap/. And I could not change the path in the Service Definition after it is generated(greyed out in change mode).
    I have looked all over the SAP help and could not find any documentation for the change.
    Any advise?
    regards,
    Wai-ming

    Hi John,
    You've raised a good scenario.
    First of all let me say that the purpose of the DB polling transaction, is to have an option to initiate a process from a DB table/view and not to update multiple fields in a table (or have other complex manipulation on the table).
    So, when choose to update a field in a record, after reading it, you are "telling" the engine not to poll this record again. Sure, i guess you can find a solution/workaround for it, but I don't think this is the way....
    The question now is what to do?
    You can have another DB adapter where you can update the data after finishing the process. In that case, after reading the data (on polling transaction) - update the header.status = 'processed' for example, and after processing the selected data update the rest of the fields.
    Hope it make some sense to you.
    Arik

  • How to specify a constraint that is not a selected column

    Assuming I have the following dimensions:
         person_id
         case_number
         report_date
    and 1 measure, Payment_Amount
    1. In OBIEE Answers, how do I aggregate-sum the Payment_Amount by person_id, and case_number where
    report_date <= (some user specified date)
    2. How does the user pass the parameter for the report_date?
    In SQL a prototype may look like:
    Select person_id, case_number, sum(Payment_Amount) from Payment_Table
    where report_date <= (user specified date)
    group by person_id,case_number
    Thanks in advance, szzfrank

    http://bischool.wordpress.com/2009/05/05/presentation-variable-values-in-report-titles-or-using-presentation-variable-in-dashboard-text-object-and-narrative-view-directly/
    ---> Step # 7 shows how to add the filter, you can use CTRL+Click on Criteria or else add column apply the filter as shown and delete it from criteria
    And the below are about presentation variable example my not fit 100% but you can get some info
    http://prasadmadhasi.com/2012/02/28/variable-prompt-in-obiee-11g/
    or
    http://oraclebi.blog.com/example-of-presentation-variable-in-obiee/
    http://gerardnico.com/wiki/dat/obiee/presentation_variable
    Hope this helps

  • How to find out Query Statistics for the initial selections

    Hi,
    Is there a way to find out the statistics for the initial query execution(without any navigations)
    /Santosh

    Hi,
      For knowing the statistics of the Query (Responce performence). U can find out with T-Code  RSDDSTAT. The base rule is U have to execute the Query atleast once. If you the aggrigates are there at DATA TARGET level u can get a details view with TCode  RSDDV.
    Best Regards

  • Custom query conditions in db adapter

    Hello,
    How to execute custom query in bpel db adapter?
    For example :
    1. select * from employee where status = 'N' and address is not null
    2. select * from empoyee where substatus = 'Y' and phone is null
    after where keyword - query part is dynamic, parameter combinations and count is unlimited ( depends on business logic ). It is not possible to implement each condition parameter as parameter in db adapter configuration.
    Db adatper query has to be something like  : select * from employee where #condition# , but #condtion# need to be interpretated as condition not string with quotes..
    best Regards,
    Uldis

    Say your complete query looks like this -
    select SUBJECT_NAME from RELATION
                where PID_GID_SSID IN (select PARTY_KEY from  xref WHERE row_id='123')
    1). In assign activity, write out the query part which comes after where clause and assign to variable query
    (select PARTY_KEY from  xref WHERE row_id='123') , replace the value of row_id from input value in assign.
    2. Now open DB adapter and pass the rest of query as input -
    select SUBJECT_NAME from RELATION
                where PID_GID_SSID IN #query

  • Using custom fields of Infoset as Selection Criteria in Query Reporting

    Hi Experts,
    I have created one Infoset based on LDB PNPCE and added some custom fields to it. Coding has been done for the custom fields.
    But these additional custom fields are not available as selection criteria while creating the query.
    Can you please tell me how to use the custom fields as selection criteria?
    Reply soon
    Thanks in Advance.
    Raveesh

    Hello Guys,
    I just noticed that it is possible to select custom fields as selection criteria in case of SAP Query,
    but NOT is case of Infoset(Adhoc) query.
    Can anyone tell me the whether it is possible to select the custom fields as Selection Criteria in case of Infoset Query?
    Thanks in Advance,
    Raveesh

  • How can I edit custom query in Data Insight

    1.  Whenever I click the edit sql query by right clicking on the custom query, the system hangs up and does not proceed further
    2.  Once you create a query without retrieving data results, is it possible to change to retrieve the data and how.
    Thanks -   Mahrukh

    Hi Mahrukh,
    I do not have this issue.  What version of Data Insight are you using?  What database is your metadata repository?  What database is your source data in for the Data Insight query you are writing?  Have you tried double clicking on the custom query - this should open it up for you to be able to edit it as well!
    You should be able to open the query to edit it and either click the return data box or un-check it for any type of query.
    Thanks,
    Denise

  • How to write customer exit in my BI query to get (current fiscal quarter) and (current fiscal quarter - 1 ) without user input

    Hi all,
    I need your help how to write customer exit in my BI query to get (current fiscal quarter) and (current fiscal quarter - 1 ) without user input.
    in my query info object is 0CALQUARTER and variable is ZFIS_QTR.
    in 0CALQUARTER fiscal quarter stored in 201301,201302,201303,201304 and 201401 format, for current fiscal quarter 201401 and (current fiscal quarter - 1 ) would be 201304.
    please replay ASAP to deliver the report to client.
    thanks in advance.
    -- Rakesh Nagpure

    I am Getting the same error for both the codes that i have written...
    Do i Need to write sth else in the code...
    Code:
    WHEN 'ZVLIVELEASES'.
      IF I_STEP = 2.
            L_DATE = SY-DATUM.
            SELECT * FROM "DSO_ACTIVE_TABLE"
                INTO TABLE ITAB_LL where "EXPIRY_DATE" > L_DATE.
            LOOP AT ITAB_LL INTO WA_LL.
            CLEAR l_s_range.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            l_s_range-low = WA_LL-"EXPIRY_DATE".
           APPEND L_S_RANGE TO E_T_RANGE.
            ENDLOOP.
       ENDIF.
    Error: Error for variable in customer enhancement ZLIVELEASES

  • How to find Tables behind a Custom Query in SAP

    Hi Gurus,
    Can anyone please help me find tables behind a custom query in SAP.
    Regards
    As

    Hi
    Check the name of the programm assigned to transaction, it should be like this:
    AQZZ<user group>=======<query name>======
    or
    AQIC<user group>=======<query name>======
    It depends of the query area is global or cross-client
    So run SQ01, select the quey area, select the quey group and so your query: now you can see the infoset and then you see it by SQ02 transaction
    Max

Maybe you are looking for