How u guys build query in program

Hey guys,
i was wondering how u guys build queries in the program. i mean if you use String or StringBuffer. e.g.
SELECT * FROM MY_TABLE WHERE X=someValue and Y=someValue and Z= someValue. if i use String i have to use + operator to get the values at runtime and which causes problem with performence. and when i use StringBuffer its kind of cumbersome. whats the best way you guys find for building queries at run time.
appreciate the time you have taken to read this.
take care and have a good day.

Hi
yes i'm creating the query in a loop. query is very
big like 2 page long. basically i've to join data from
many tables and many filter criteria entered by the
clients which i put in the where clause. we r running
optimizers on our application and it shows query
building processes are making the overall performence
slow.
First you limit the query in some fashion (if you don' t then you might as well just give them a text box and let them type SQL.)
In your case that might be limiting it to a query on all of the five tables.
Second you produce a query DTO.
A standard DTO might look like this....
       class CustomerDTO
         public String customerName;
         public double accountBalance;
  A query DTO, built to match the above, would look like this....
       class CustomerQueryDTO
         public String customerName1;
         public String customerName2;
         public OperatorType customerNameOperator;
        public double accountBalance1;
        public double accountBalance2;
        public OperatorType accountBalanceOperator;
      }And OperatorType would allow equality, between (which is why there are two parameters), greater than, etc
You build the query string as follows
       CustomerQueryDTO query = ...
       StringBuffer b = new StringBuffer();
       b.append("select ");
       b.append(fieldList);
       b.append(" from ");
       b.append(tableList);
       b.append("where 1=1");
       if (query.customerNameOperator != null)
            b.append(" and ");
            String exp = createExpression(query.customerName1,
                                   query.customerName2,
                                   query.customerNameOperator );
            b.append(exp);
     String sql = b.toString(); 
You also want to make sure that a query actually is limited by something. So the query must have at least one clause.

Similar Messages

  • How to link from query to executable program (38)

    Hi Experts,
    I develop one sq01 query and that I want link to my executable program which is created by from se38 to display the interactive report .
    The basic list is coming from the  query and secondary list is displaying from the program.
    please explain how to link the query and program to store the values TRSTI table.
    Please help me,its critical

    Kindly search on the net with the keyword "Report assignment in SAP Query", you will get lot of links.

  • Transport Query generated program using SQ01

    Dear All,
    Please let me know how to transport a query generated program using SQ01. I have created a program from SQ01 query creation and assign a tcode to this program. When the program was generated there was no request create so how to make a request to transport this generated program to PRD.
    Thanks in advance.

    Hi,
    for query transport (export/import or download/upload (which I prefer because it can be done between different SAP systems where no transport mechanism exists)) go to SQ02 and tick the button that looks like a car.
    The t-code assignment (and maybe the the T-code is added in an area menu using SE43) needs to be transported seperately (if you use downlaod/upload as this does not create a transport request.
    best regards, Christian

  • How to build query to give daily balance across bank accounts? (to then plot in a graph)

    How would one build a query to give daily balance across bank accounts? (to then plot in a graph)
    Assumptions:
    * There is a table TRANSACTIONS which includes columns TRANS_DATE, AMOUNT and BANK_ID. It does NOT include a column for balance. So current balance for a bank account is the sum of the AMOUNTs for that BANK_ID for example. Balance on date XX will be the sum
    of all AMOUNTS for that BANK_ID for all TRANS_DATE's prior and including the date XX.
    * There is not necessarily transactions on every day for each bank
    * Table BANKS which has BANK_ID and TITLE
    Would like a query that gives: Supply StartDate and EndDate for the query:
    Date Bank1Balance Bank2Balance Bank3Balance TotalBalance
    1/1/15 $100 $200 $100 $400
    1/2/15 $200 $200 $100 $500
    etc

    You'll find examples of queries for computing balances in various contexts in Balances.zip in my public databases folder at:
    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.
    The queries in this little demo file return balances per transaction, however, whereas you appear to wish to return balances at close of business per day.  This can easily be done by means of a subquery which sums all transactions to date.  To return
    balances for all dates regardless of whether or not any transactions have been undertaken on the day, an auxiliary calendar table can be introduced into the database to plug the gaps,  The Calendar.zip file in my same OneDrive folder has means of generating
    such a table.
    With the introduction of an auxiliary calendar table into the database a query can then be written to return the balance per customer at close of business per day over the period 2009 - 2012 covered by the data in the Transactions table:
    SELECT CustomerID, Firstname, LastName, calDate,
       (SELECT SUM(TransactionAmount)
         FROM Transactions
         WHERE Transactions.CustomerID = Customers.CustomerID
         AND Transactions.TransactionDate <= Calendar.calDate) AS Balance
    FROM Calendar,Customers
    WHERE calDate BETWEEN #2009-01-01# AND #2012-12-31#
    ORDER BY CustomerID, CalDate;
    Rows for each customer/date are returned by means of the Cartesian product of the Calendar and Customers tables (the latter analogous to your Banks table), and the subquery returns the balance at close of each day by correlating the Transactions table with
    the Customers and Calendar tables, returning the sum of all transactions per customer up to and including the date in question.  In this example credit and debit transactions are expressed as positive and negative values in a single column of course,
    but where separate credit and debit columns are used its merely a case of summing (Credit-Debit), as done in some of the examples in my demo.
    To return the data in a horizontal format per date I'd suggest the use of a report which returns one row per date, and within it a multi-column subreport in across-then down column layout, linking the subreport to the parent report on the date columns.
    Ken Sheridan, Stafford, England

  • How can I build Instalation Program for java applet?

    I want to build on line internet game based on java applet.
    Uset must instull the game to his computer.And this program mast Connect to the server when user enter
    to this application.Not from explorer,but from my application,like when i enter to ICQ.
    My questions:
    How can i build instalation program in java?
    How can i connect to the server when user enter into my game not from explorer but from game?
    Thanks,Maya.

    Hi Maya
    First of all an Applet does not have to be "installed" as you would with a normal application. The browser handles the install and execution of the applet.
    Check out this URL for more about applets:
    http://web2.java.sun.com/docs/books/tutorial/applet/index.html
    On the subject client/server pairs - see:
    http://web2.java.sun.com/docs/books/tutorial/networking/sockets/index.html
    If you decide to make the game an application instead check out Sun's WebStart - under the products section.
    That's about all the help I can give you.
    Programming a game is a complicated subject - I am doing one too:
    http://hjem.get2net.dk/mhjembaek/armageddon/
    Kind reg,
    Hjembaek

  • How to find out query name using Elements of the query builder.

    Hi SDNers,
    how to find out query name using Elements of the query .
    thanks,
    satyaa

    Hi,
    For having a look at the relation between BEx tables,check the link below:
    http://wiki.sdn.sap.com/wiki/display/BI/ExploretherelationbetweenBEx+Tables
    -Vikram

  • How to build a login program by using CGI for built-in webserver of fieldpoint

    hi ,
    I want to build a login program by using CGI . And implement in the built-in webserver of feildpoint.Can any one help me to give ideas ? THANKS

    Hi Barry,
    To set up configuration access to a VI panel image, you will need to set up a global access configuration file (*.cfg). There are numerous CGI shipping examples that are included with the Internet Toolkit. To access these examples, first start your G web server. Then, in a web browser, type in http://localhost (if you are not using port 80, you’ll need to type in a colon followed by the port number in the URL).
    The localhost url above should direct you to the default homepage for the G web server. Make sure the title is “G Web Server” and not “LabVIEW Web Server.” From the G web server page, you’ll see a button to “View CGI Examples” and from there, you’ll see a category titled Access Control. Just so you know, the hard-coded path to this page on your computer is: C:\Program Files\National Instruments\LabVIEW 7.1\www\examples\access.htm. There are then examples on setting up access control for panel images as well as directories. The sample configuration file is: C:\Program Files\National Instruments\LabVIEW 7.1\internet\http\conf\access.cfg
    Hope this helps. Best of luck!

  • Build Query in Transactions

    Hi All,
    Could you please let me know how queries or subqueries can be build using
    SQVI  or SQ01 or ZX02 transactions. For example :
    1)select * from zmstkcalc where werks_d <> werks_main.
    2)select * from zmstkcalc where werks_d in ( select werks from zmwerks_mu),
    Please note that i know how to sove this by writing program. But I would like build query instead of writing program.
    Thanks

    Hi
    Please find a pdf book on SQL Queries, this explains some steps on the same,
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVQUE/BCSRVQUE.pdf
    Regards
    Kathirvel

  • To build query related to SNP: Planned Order

    Hi,
    System: SCM 5.0
    Scenario: SO received at plant and planning creates PR against SO at plant and accordingly SNP:Planned Order at Vendor location. If SO is cancelled/deleted (manually), sometime only the PR gets cancelled/deleted (automatically during planning run) but corresponding SNP:Planned Orders still remains at vendor location and so the dependent requirements. PR and Planned Orders are pegged to SO so one-to-one relation is maintained.
    I could not find any reason why system is not deleting Planned Order at vendor location despite SO and PR is deleted at plant location. So I am planning to build query where SNP:Planned Orders are not pegged to any PR or SO.
    Can anyone help with list of SNP:Planned Order tables so that I can build query around it to identify ghost Planned Orders.
    Hope I was clear with my query but let me know if any further information is require.
    Thanks and regards,
    Devang

    HI Marius,
    Sorry for delay reply.
    I was working on on some other more critical issues to business.
    Finally we decided to built report to identify obsolete Planned Orders for which PR is not available in ordering plant. I have listed below logic for that report:
    Get Location ID from table /SAPAPO/LOC based on Location entered in selection screen
    Get PEGIDs from FM /SAPAPO/DM_MATLOC_GET_PEGIDS based on IV_SIMID as 000 and location id from step 1
    In FM /SAPAPO/OM_PEG_CAT_GET_ORDERS, use SIMVERSION as 000 and in Import Para IS_GEN_PARAMS insert all PEGIDs from step 2.
    From Export Para ET_PEG_INPNODE take From_OrderID and store in internal table.
    Execute T.Code /SAPAPO/RRP4 with following selection (Use Selection Variant: OBSOLETE PR and add Location as entered in Selection Screen)
    Planning Version: 000
    From: Current date – 60 days
    To: Current date +180 days
    Location: 0000201328
    Product: *
    Order Type: 1F
        6. Compare output of step 4 and step 5 and display result.
    From FM /SAPAPO/DM_MATLOC_GET_PEGIDS the output (step 4) will be Order ID (22 characters) while step 5 (T.Code /SAPAPO/RRP4) will give Planned Order number (8 character). I am not sure how to compare Internal Order ID (22 characters) for corresponding Planned Order Nos. (8 characters).
    I have not marked your post as correct answer as still need to find answer of above query.
    Thank you in advance for your guidance.
    Regards,
    Devang Shah

  • How to run command line argument programe

    Hi guys, I am doing pass command line argument programe in java but I don't know how to run this programe. Path for this programe in my my computer is C:\Users\Desktop\Mainjava\mycode\CommandProgjava*
    {code/}
    public class CommandProg
    public static void main(String[] args)
    System.out.println("d");
    for (int i = 0; i < args.length; i++)
    System.out.println(args);
    {code/}
    Where i need to go and what command i need to give so i can execute this programe(I am using window vista). I only know i have to give
    this command some where CommandProg arg1 arg2 arg3 arg4. Output should be
    Output:
    arg1
    arg2
    arg3
    arg4
    Please help me, Thanks in advance.
    Edited by: JayVirk on Dec 30, 2007 11:33 AM

    Jay,
    Your question isn't very clear, hence Joerg's well meaning but irrelevant advise.
    Do you mean:
    I've written a simple program in java which echos
    it's command-line arguments to back to the console.
    Here's my code:
    package forums;
    public class ArgsEchoer
      public static void main(String[] args) {
        for (String arg : args) {
          System.out.println(arg);
    But can't figure out how to compile and run the program.
    I'm using winblows shista, and it's cr@p.
    Please help me, Thanks in advance.So... where are you at? Have you installed the JDK (java development kit)? Which version? Is your path set? Is your classpath set?
    Start here: http://java.sun.com/developer/onlineTraining/new2java/

  • How do I build an expression for a multi-element in-list?

    How do I build an expression for a multi-element in-list? For example:
    SELECT * FROM employees
    WHERE (first_name, last_name, email) IN
    (('Guy', 'Himuro', 'GHIMURO'),('Karen', 'Colmenares', 'KCOLMENA'))
    Passing a Vector to Expression.in(Vector) where each element is a Vector of values itself will result in the appropriate expression for the values clause, but how to I get the columns to be considered together, that is, how do I get the "(first_name, last_name, email)" part?
    Steve

    Steve,
    I do not believe this is currently supported in the TopLink expression framework. Your best bet at this point will be to use custom SQL.
    Doug

  • How to Automate the Query Search Upon Return to the Calling Form?

    Greetings Ya’ll Gurus,
    Could you please share with me how to make the Query Search executed automatically each time, when database table is updated, upon return to the “Calling Form” (i.e. FormA in this posting) from the “Called Form” (i.e. FormB from here on)?
    I have FormA call_form to FormB. FormB may return to FormA. FormA allows users to enter the Query parameters and perform query Search to the database table with a list of search results afterward; whereas FormB allows users to add or delete the same database table records. Both form images are as follows:
    FormA:
    !http://dot.state.ak.us/nreg/jtomasic/FormA_DWR_SEL.GIF!
    FormA call_form to FormB by clicking PB “Daily Work Report” (see circled PB "Daily Work Report" in the above image.)
    FormB Image (FormB allows users to add and delete database records):
    !http://dot.state.ak.us/nreg/jtomasic/FormB_DWR.GIF!
    FormB EXIT_FORM and returns to FormA (see circled PB "DWR Selection" in above image).
    Currently, our users must press the PB “Search” on FormA each time to refresh the Query “Search” results after returning to FormA, and they request to have the "Search" done automatically/programmatically upon return to FormA each time when the database table is updated.
    If you have programming code on this and are willing to share or if you have any suggestion or thoughts on this, it would be most greatly appreciated.
    Thanks a lot & Happy Holidays!

    Thanks so much Andreas, and yes, your link for calling a form and passing a context is very helpful. I believe, your suggested use of the global variable for the saved database table will work for the automation of the Query Search. I am, however, not sure how to make the code and the trigger to automatically perform Query PB "Search". The code for our current "WHEN-BUTTON-PRESSED" Trigger for the PB-Search of FormA is as following:
    DECLARE
         alert_button     NUMBER;
         alert_id               ALERT;
      MY_WHERE VARCHAR2(2500);
      MY_DIST_ID         DIST.DIST_ID%TYPE     := :BLK_UPDATE.DIST_ID;
      MY_ORG_ID          DWR.ORG_ID%TYPE       := :BLK_UPDATE.ORG_ID;
      MY_ACTY_ID         DWR.ACTY_ID%TYPE      := :BLK_UPDATE.ACTY_ID;
      MY_ACTY_WORK_ID    DWR.ACTY_WORK_ID%TYPE := :BLK_UPDATE.ACTY_WORK_ID;
      MY_CNTY_ID         DWR.CNTY_ID%TYPE      := :BLK_UPDATE.CNTY_ID;
      MY_ASSET_GRP_ID    DWR.ASSET_GRP_ID%TYPE := :BLK_UPDATE.ASSET_GRP_ID;
      MY_ASSET_ID        DWR.ASSET_ID%TYPE     := :BLK_UPDATE.ASSET_ID;
      MY_RTE             DWR.RTE%TYPE          := :BLK_UPDATE.RTE;
      MY_BEG_MP          DWR.BEG_MP%TYPE       := :BLK_UPDATE.BEG_MP;
      MY_END_MP          DWR.END_MP%TYPE       := :BLK_UPDATE.END_MP;
      MY_FROM_DATE       DWR.DWR_DATE%TYPE     := :BLK_CONTROL.FROM_DATE;
      MY_TO_DATE         DWR.DWR_DATE%TYPE     := :BLK_CONTROL.TO_DATE;
      MY_FLAG_OFFSYS     VARCHAR2(11)          := :BLK_UPDATE.FLAG_OFFSYS;
      MY_FLAG_COMMENTS   VARCHAR2(11)          := :BLK_UPDATE.FLAG_COMMENTS;
      MY_SPECIAL_EVENT_SEQ_NO SPECIAL_EVENT.SPECIAL_EVENT_SEQ_NO%TYPE  := :BLK_UPDATE.SPECIAL_EVENT_DESCR;
      MY_FLAG_ACCDT      VARCHAR2(11)          := :BLK_UPDATE.FLAG_ACCDT;
    BEGIN
    :blk_control.dummy_flag := 1 ;
    :BLK_CONTROL.DUMMY_ERR_FLAG := 'N';
    VALIDATION_SELECTION;     -- Program Unit VALIDATES DWR SELECTION PARAMETERS PRIOR TO
                                                    -- PERFORMING THE SEARCH AND POPULATING THE DISPLAY BLOCK
    if :blk_control.dummy_flag = 1 then
      IF :BLK_CONTROL.DUMMY_ERR_FLAG = 'N' THEN
        MY_WHERE := BUILD_WHERE_CLAUSE(MY_DIST_ID,
                                       MY_ORG_ID,
                                       MY_ACTY_ID,
                                       MY_ACTY_WORK_ID,
                                       MY_CNTY_ID,
                                       MY_ASSET_GRP_ID,
                                       MY_ASSET_ID,
                                       MY_RTE,
                                       MY_BEG_MP,
                                       MY_END_MP,
                                       MY_FROM_DATE,
                                       MY_TO_DATE,
                                       MY_FLAG_OFFSYS,
                                       MY_SPECIAL_EVENT_SEQ_NO,
                                       MY_FLAG_ACCDT,
                                       MY_FLAG_COMMENTS);
        SET_BLOCK_PROPERTY('BLK_DISPLAY', DEFAULT_WHERE, MY_WHERE);
        GO_BLOCK('BLK_DISPLAY');
        CLEAR_BLOCK(NO_VALIDATE);
        EXECUTE_QUERY(ALL_RECORDS);
        IF :BLK_DISPLAY.DWR_SEQ_NO IS NOT NULL THEN
                   SET_ITEM_ON_OR_OFF('BLK_CONTROL.PB_PRINT', TRUE);
        ELSE
                   SET_ITEM_ON_OR_OFF('BLK_CONTROL.PB_PRINT', FALSE);
                   alert_id := FIND_ALERT('no_data_query');
                   IF ID_NULL(alert_id) THEN
                        error_msg(1000);
                   ELSE
                        set_alert_message(alert_id, 1040);
                        alert_button := SHOW_ALERT(alert_id);
                   END IF;
              END IF;
              GO_BLOCK('BLK_UPDATE');
              GO_ITEM('BLK_CONTROL.PB_SEARCH');
         END IF;
    end if;
    END;My questions are:
    After initializing, set and/or reset the global variable for the saved database table,
    do I copy the above code (i.e. the "entire" code in the "WHEN-BUTTON-PRESSED" Trigger for the PB-Search) to the WHEN-NEW-FORM-INSTANCE-trigger, or other trigger(s), of FormA to automate the Query Search whenever there is a successful database commit/save? Or
    is there a simple way to activate the code in the "WHEN-BUTTON-PRESSED" Trigger for the PB-Search of FormA? Or
    is there a simple way to activate the EXECUTE_QUERY(ALL_RECORDS) command in the WHEN-NEW-FORM-INSTANCE-trigger or other trigger(s) of FormA ?
    Thanks and always.

  • Need idea on how to do question and answer program

    I want to create a troubleshooting program where it asks the user questions until its drilled down to an appropriate answer.
    I've done this with a web server before but I can't seem to figure out how to do it in a program without involving many many forms. Any ideas on how to do the UI?
    Thanks!

    Building an expert system is not a trivial process so for a commercial app you'll need to do some research. For an internal app you should probably use a database. For a school project you can get away with storing the data in a file that is loaded into
    memory (or simply building the data in memory directly).  In any case you'll need to define a table of questions.  If you support questions with fixed answers then you'll need a separate table for the answers associated with the questions. 
    If questions can be different types (as mentioned previously) then you'll also need to track the question type with the question.  For the relationship between questions you can go different ways depending upon your requirements. If question 1 with answer
    A goes to question 2 but answer B goes to question 3 then you can create a simple reference table that indicates what the next question is given the current question and answer, basically a state machine.  If a single answer opens a whole series of questions
    then you might do better to group the questions together and manage the transition between groups of questions.  It really depends upon your requirements. You'll want to research state machines to implement this though.
    On the UI side you really don't need to dynamically create anything.  The only thing that changes between questions is the text and possibly the answer format (if you support multiple questions). As I mentioned earlier you can create a separate container
    (Panel) for each question type and then show or hide the container based upon the type of question (from your database data).  This eliminates the need to dynamically create the UI.

  • We are interested to know how/where to check query runtimes for any Query in SAP BW?

    We are interested to know how/where to check query runtimes for any Query in SAP BW?
    Is there any table or program to get the query run time details per query for a particular day.

    Hello Sravan,
    Bex statics tables would be 'RSDDSTATHEADER','RSDDSTATINFO' & 'RSDDSTATEVDATA'. all these can found in one view 'RSDDSTAT_OLAP'.
    above can give historical statistic.
    For current Query statics : T-code RSRT, and select debug mode select display statistics and then execute.
    Once you get the output press F3(one step back), there you can see statics of the query for that particular execution.
    Thanks,
    Mallikarjuna

  • How to solve this query

    hi,
    i have a product table like
    product month1 month2 month3 .................
    soap 1200 1256 1895 ............
    i want use a query where i can select column name with a parameter.
    like
    select month||:num from product;
    in num variable it cud be 1 to 10 of value that is dependent on my program.
    so how to make this query .
    thxs

    Hi,
    Here is an example that i am helpful.
    In the example , I am using a table 'table_name' which contains columns like
    assign_attribute1
    assign_attribute2
    assign_attribute15
    Now I will pass any number from 1 to 15 to the function.
    create or replace procedure pass_col_number(v_number varchar2) as
    v_sql varchar2(2000);
    v_assign_attribute1   varchar2(150);
    begin
    v_sql := 'select  assign_attribute'||v_number||'  from  table_name where person_id = 1345';
    execute immediate v_sql into v_assign_attribute1;
    dbms_output.put_line('v_assign_attribute1='||v_assign_attribute1);
    end;Edited by: Sreekanth Munagala on Dec 18, 2008 1:18 AM

Maybe you are looking for