Dynamic query syntax for EJB

If i'm going to let the user search the database table (eg. Employee) based on 4 parameters, ie. employee id, employee name, position and address. In cmp entity bean, the stupid way is to create (2 power of 4) findByMethod ejb-ql statements to fulfill the search. Is there any dynamic way to do the querying of table for cmp bean with only one findByMethod?
Any suggestions or help would be much appreciated. Thanks.

Hi Julius,
CMP unfortunately does not support dynamic OQL methods (unless something has changed since the last time I looked at the specs). There are however tools and software (eg powertier) that can provide this type of functionality (like a generic findBySQL(String sql) method) on some J2EE servers.
One way to solve it of course is to have 4 different methods, and then in your java code have a case or if statements selecting the correct one based on what the user enters. It is not a pretty solution but it would work.
regards,
Dion

Similar Messages

  • Query Syntax for Dynamic Navigation Menu

    I'm trying to build a Navigation menu from a query using the following syntax:
    select LEVEL,
           LABEL,
           LINK,
           'NO' as IS_CURRENT,
           null as IMAGE
      from V$RC_MENUS
    where CLUB = :APP_CLUB
    start with PID is null
    connect by prior ID = PID
    order by SEQUENCE, LABEL
    The query itself works fine for all values of APP_CLUB but it only generates the menu entries for some values of APP_CLUB, but not others. The SEQUENCE value determines the order of the entries within each level. Is this the correct syntax for a query-based navigation menu? How does it determine which sub-levels belong to a parent?  Does the ordering of the resultset have any impact on how the menu is generated?

    Jritschel-Oracle wrote:
    I'm trying to build a Navigation menu from a query using the following syntax:
    select LEVEL, 
          LABEL, 
          LINK, 
          'NO' as IS_CURRENT, 
          null as IMAGE 
      from V$RC_MENUS 
    where CLUB = :APP_CLUB 
    start with PID is null 
    connect by prior ID = PID 
    order by SEQUENCE, LABEL 
    The query itself works fine for all values of APP_CLUB but it only generates the menu entries for some values of APP_CLUB, but not others. The SEQUENCE value determines the order of the entries within each level. Is this the correct syntax for a query-based navigation menu? How does it determine which sub-levels belong to a parent?  Does the ordering of the resultset have any impact on how the menu is generated?
    As stated in the documentation:
    ...do not specify either ORDER BY or GROUP BY, because they will destroy the hierarchical order of the CONNECT BY results. If you want to order rows of siblings of the same parent, then use the ORDER SIBLINGS BY clause.
    Try:
    select LEVEL,
          LABEL,
          LINK,
          'NO' as IS_CURRENT,
          null as IMAGE
      from V$RC_MENUS
    where CLUB = :APP_CLUB
    start with PID is null
    connect by prior ID = PID
    order siblings by SEQUENCE, LABEL

  • Using Dynamic Query in For Loop

    I have a doubt whether i can use the result from dynamic query in the for loop.
    for example,
    declare
    v_sql varchar2(1000);
    v_Id INTEGER;
    begin
    v_sql := 'select id from table1 where id in ('||v_Id||')';
    FOR i in vsql LOOP
    dbms_output.put_line(i.id);
    end loop;
    end;
    The above query is possible ?

    And here's a basic example of opening up a cursor for your dynamic query...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_sql varchar2(2000);
      3    v_cur sys_refcursor;
      4    i     emp.sal%type;
      5  begin
      6    v_sql := 'select sal from emp';
      7    open v_cur for v_sql;
      8    loop
      9      fetch v_cur into i;
    10      exit when v_cur%NOTFOUND;
    11      dbms_output.put_line('Salary: '||i);
    12    end loop;
    13* end;
    SQL> /
    Salary: 800
    Salary: 1600
    Salary: 1250
    Salary: 2975
    Salary: 1250
    Salary: 2850
    Salary: 2450
    Salary: 3000
    Salary: 5000
    Salary: 1500
    Salary: 1100
    Salary: 950
    Salary: 3000
    Salary: 1300
    PL/SQL procedure successfully completed.
    SQL>

  • Dynamic query table for report based on LOV selected

    Hi,
    Need some suggestion and guidance how to dynamically query table via lov for report .
    Scenario:
    Table, TABLE_LIST, has tablename (table in DB) and filter (for where clause) column. The TABLENAME_LOVE is derived from table TABLE_LIST.
    SELECT TABLENAME D, TABLENAME R FROM TABLE_LIST
    In Page 2,a page select list item,P2_TABLENAME to use TABLENAME_LOV
    All data in tables in the table_list have identical structure (columns, triggers, primary key, and so on).
    I want to have the report region query from the table based on selected LOV.
    Example,
    Tablename Filter
    TB1
    CD2 ACTIVE='Y'
    When select TB1, the report regin will query based on TB1.
    When select CD2, the report regin will query based on CD2 WHERE ACTIVE='Y'
    Question:
    How can I query based on &P2_TABLENAME. WHERE &P2_FILTER.
    Like
    select col1, col2 from &P2_TABLENAME WHERE &P2FILTER
    Greatly appreciate any suggestion and some guidance.
    Tigerwapa

    Hi,
    You should always post your Apex version, DB version and other information as suggested in the FAQ.
    And the moment you talk report you should state whether it is IR or Classic.
    As for your query, have you explored the Report type "SQL Query (PL/SQL function body returning SQL query)" ?
    That might be a good fit for what you are trying to achieve.
    Regards,

  • Geting ORA 936 -while building dynamic query in for loop.

    HI,
    I hav written a SP and its compiled and giving me the results for the data I am quering but giving ORA936 - missing expressin and giving ORA 6512 at 2 lines. Please help me me out where I am going wrong.
    CREATE OR REPLACE TYPE LIST as VARRAY(5000) of NUMBER;
    CREATE OR REPLACE PROCEDURE test( V_id IN LIST,
    v-fdate IN DATE,
    v-tdate IN DATE,
    v_flg IN CHAR)
    AS
    TYPE opfld IS RECORD (
    FID TAB.ID%TYPE,
    FCURR TAB.CURR %TYPE,
    FCNT TAB.CNT%TYPE,
    FTOT TAB.TOT%TYPE );
    TYPE OPLIST IS REF CURSOR;
    Rc oplist;
    Edtab opfld;
    Selstr VACHAR2(200);
    Whstr1 VACHAR2(200);
    Whstr2 VACHAR2(200);
    Whstr3 VACHAR2(200);
    Whstr VACHAR2(200);
    Grpstr VACHAR2(200);
    Andstr VACHAR2(200);
    Fullstr VACHAR2(200);
    BEGIN
    Selstr := ‘SELECT col1,col2,sum(col3),sum(col4) from tab1 ’;
    Whstr1 := ‘ WHERE tdate BETWEEN TO_DATE(‘||’’’’||vfdate||’’’’||’)’;
    Whstr2: = ‘ AND TO_DATE(‘||’’’’||vtdate||’’’’||’)’;
    Whstr := whstr1||whstr2;
    Grpstr := ‘GROUP BY col1,col2’;
    IF v_flg IS NOT NULL THEN
    Whstr3 := whstr||’AND FLAG = ‘||v_flg;
    else
    Whstr3 := whstr ;
    END IF;
    FOR I IN 1..id.COUNT LOOP
    BEGIN
    Andstr := ‘ AND id =’|| v_id(i);
    Whstr := whstr3 || andstr ;
    Fullstr := selstr||whstr||grpstr;
    OPEN rc for fullstr;
    LOOP
    FETCH rc into edtab
    EXIT when rc%NOTFOUND;
    END LOOP;
    Andstr := ‘’;
    Whstr :=’’;
    END; ---BEGIN of FOR loop
    END LOOP; -- for end
    CLOSE rc;
    END; -- proc end
    Created above SP and its compiled. When I try to execute the SP with below code I am getting--
    DECLARE
    V_t LIST;
    BEGIN
    V_t:= LIST();
    V_t.EXTEND(10);
    V_t(1) := 10;
    V_t(2) := 20;
    Test(v_t,’25-APR-2012’,’30-APR-2012’,’Y’);
    END;
    The SP is building correct dynamic querry and its getting executed for id = 10 and 20, giving the correct results but though I defined only 2 ids while executing and written FOR lOOP upto ID.COUNT its building query for third time and that time its not getting id, so for the third time the last part of where clause is built like
    SELECT.....
    WHERE....
    AND id = (its taking blank here)
    GROUP BY ...;
    and thus its giving me ORA 936 missing expression and ORA 06152 at line of RECORD TYPE declaration and line of OPEN rc for fullstr;
    ERROR at line 1
    ORA 00936 misssing expresiion
    ORA 006152 at line 9
    ORA 006512 at line 87
    I hav put DBMS_OUTPUT statements @ every build of dynamic wuery and its correct. here I have not copid the code I hav typed hereso not wriiten DBMS_OUTPUT.
    I tried lot of ways redefining Andstr := ‘’;
    Whstr :=’’; after for endloop but its giving the same error. is this because I am using varray? If am providing 2 ids in anonymous block then how its building query for third blank ID value.
    Please help me out here..
    Thanks a lot..

    >
    I hav written a SP and its compiled and giving me the results for the data I am quering
    >
    Then you should have posted the one that compiles and gives you results.
    The code you posted will not compile without errors. Edit your original post and provide the corrected code.
    When you do please add \ tags on the line before and after the code to preserve formatting. See the FAQ for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is there any way to create Dynamic Query??

    Hi All,
    Can we create a Dynamic Query object for Z-Table.
    Thanks in Advance.
    Regards,
    Ravi Teja

    Hi Jotsaroop,
    We have created a Simple object to create a custom table view in the Appointment page.
    Now client wants a search help pop-up for one of the attribute in the view.
    By creating a simple object we are having normal query object.
    But we required dynamic query for the same.
    Thanks in advance for your inputs.
    Regards,
    Ravi

  • Duplicate records for Dynamic Query in WLS 7

    I am getting duplicate records back when I run a dynamic query. If I run the same
    query via a finder method, I get the correct results.
    Here's the query:
    SELECT DISTINCT OBJECT(a) FROM Company AS a, b IN a.userRole WHERE b.userId = ?1
    AND a.deptId IN ('1', '2', '3')
    Company EJB maps to LU_Company (look up table for company)
    Company to UserRole is a one-to-many relationship.
    The number of duplicates is equal to the number of records I have for the same company_id
    in User_Role table.
    The ids for the object I should get back are 1, 2, 3.
    Instead I get back 1, 1, 2, 2, 2, 2, 2, 3, 3, 3
    In the database, company_id 1 occurs twice in user_role table; company_id 2 occurs
    five times.
    Any ideas of why the dynamic query has this problem whereas the same query for a
    finder method works fine?
    Thanks for your help.

    Thanks Greg, that worked!
    "Greg Nyberg" <greg.nyberg.at.objectpartners.com> wrote:
    You can supply properties on the query request, perhaps there is a
    SQL_SELECT_DISTINCT property:
    Properties p = new Properties();
    p.setProperty("GROUP_NAME", "fieldgroup");
    p.setProperty("INCLUDE_UPDATES", "true");
    p.setProperty("SQL_SELECT_DISTINCT", "true");
    Collection people = myQuery.find(
    "SELECT OBJECT(o) FROM PersonCMPEJB o WHERE o.lastName = 'Smith'", p);
    -Greg
    Check out my WebLogic 6.1 Workbook for O'Reilly EJB Third Edition
    www.amazon.com/exec/obidos/ASIN/1931822468 or www.titan-books.com
    "Mike" <[email protected]> wrote in message
    news:[email protected]...
    Matt,
    <sql-select-distinct> needs to be set in <weblogic-query> element. I amgenerating
    a dynamic query from within a local client. So I don't have a finderdefined for
    this method. (I don't want to define a finder for this method). How doyou suggest
    I can use this? Thanks again for your help.
    Matthew Shinn <[email protected]> wrote:
    Hi Mike,
    I just filed a bug report for this (CR079471). As a work around, you
    can
    use the
    setSQLSelectDistinct flag so the database will weed out the duplicates.
    The only thing to
    look out for when using this flag is that Oracle will not allow the use
    of 'SELECT DISTINCT'
    in conjunction with a 'FOR UPDATE' clause, thus,<sql-select-distinct>True
    CANNOT be used if
    any Bean in the calling chain has a method with <transaction-isolation>
    set to
    <isolation-level>TRANSACTION_READ_COMMITTED_FOR_UPDATE. Sorry for theinconvenience.
    - Matt
    Mike wrote:
    I am getting duplicate records back when I run a dynamic query. If
    I
    run
    the same
    query via a finder method, I get the correct results.
    Here's the query:
    SELECT DISTINCT OBJECT(a) FROM Company AS a, b IN a.userRole WHERE
    b.userId
    = ?1
    AND a.deptId IN ('1', '2', '3')
    Company EJB maps to LU_Company (look up table for company)
    Company to UserRole is a one-to-many relationship.
    The number of duplicates is equal to the number of records I have forthe same company_id
    in User_Role table.
    The ids for the object I should get back are 1, 2, 3.
    Instead I get back 1, 1, 2, 2, 2, 2, 2, 3, 3, 3
    In the database, company_id 1 occurs twice in user_role table;
    company_id
    2 occurs
    five times.
    Any ideas of why the dynamic query has this problem whereas the same
    query
    for a
    finder method works fine?
    Thanks for your help.

  • Re: relationship caching for dynamic query finder

    "Carlos Muchiutti" <[email protected]> wrote:
    I have the same scenario ... is there an answer for this?
    "Haoguang" <[email protected]> wrote in message
    news:3e2e64af$[email protected]..
    Is there any way to using the relationship caching defined in thedeployment descriptor
    for the dynamic query?
    I suppose it should be one of the properties passed to the query findmethod (Query.query.find(String,
    Properties)).
    I was unable to locate any documentation or examples for the question.
    What is the key set the Properties? I know the "GROUP_NAME" is one,which
    I found
    via Google. Bravo to the documentation of bea!
    ps, We are using Weblogic 7 with sp1.
    Your help or comments will be appreciated.
    Try the stuff described in:
    http://e-docs.bea.com/wls/docs70/ejb/EJB_environment.html#1151177

    There is no information related to dynamic query finder with relationship caching.

  • SQL Syntax for hour/date range in Query

    Hi
    I am trying to set up an query for sales order documents procesed in the last 30 minutes to be set as an alert to be run every 30 minutes to the sales manager.  I am having difficulty getting the syntax for the last 30 minutes
    Any suggestions?
    David

    hi,
    I'm not sure query is correct,but u can modify it futher to get correct one.
    SELECT T0.DocNum, T0.DocDate, T0.CardName, T0.DocTotal FROM ORDR T0 WHERE DateDiff(dd, T0.DocDate ,getdate()) = 0 and
    DateDiff(Minute,T0.DocTime,' ') <= 30
    Jeyakanthan

  • FAGLL03 : Submit syntax for dynamic selections

    Hi Experts,
    My z report contains following fields in selction screen.
    1 . G/ L account
    2. Comapny code
    3. posting date
    4. document type
    5. layout
    In my z report i used following syntax for passing selection screen values to standard program and getting data.
    SUBMIT FAGL_ACCOUNT_ITEMS_GL
                      WITH SD_SAKNR   IN S_SAKNR
                      WITH SD_BUKRS   IN S_BUKRS
                      WITH X_OPSEL    EQ ' '
                      WITH X_CLSEL    EQ ' '
                      WITH X_AISEL    EQ 'X'
                      WITH SO_BUDAT   IN S_BUDAT
                      WITH PA_VARI    EQ P_VAR
                      EXPORTING LIST TO MEMORY
                     AND RETURN. 
    The above syntax is not working for dynamic selection field ( document type ), entire document types data is fetching from standard program. I want to fetch document type data based on my z report selection values for document type field.
    Expect for document type field , submit syntax is working.
    kindly provide submit syntax for my above requirement .
    Any suggestions from experts....
    thanks & regards,
    Hari priya
    Edited by: Hari  Priya on Aug 24, 2009 4:33 PM

    Hi,
    Try like this.
    call function 'RS_REFRESH_FROM_SELECTOPTIONS'
      exporting
        curr_report = 'FAGL_ACCOUNT_ITEMS_GL'
      tables
        selection_table = i_sel[].
    Fill your profit center values in i_sel
    Submit FAGL_ACCOUNT_ITEMS_GL with selection-table i_sel and return
    WITH FREE SELECTIONS TEXPR AND RETURN
    Regards,
    Shamma

  • How to use dynamic query for Result table

    Hello Experts,
    I want to use dynamic query and then display the result in the assignment block.
    Using dynamic query BTQAct and BTQRAct and base on some search criteria i want tofilter and then append the result in the result table of that custom context node, and then it should display the result in the view in UI.
    SO can you please provide me the samplle code on how to use the dynamic query and append in the result table.
    Regards.

    Hi,
    Please find below sample code:
    data:  query         TYPE REF TO cl_crm_bol_dquery_service,
               result        TYPE REF TO if_bol_bo_col.
    DATA: lt_params       TYPE crmt_name_value_pair_tab,        
               lwa_params      TYPE crmt_name_value_pair.             
    query = cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ). " Get instance of dynamic query
    Set general query parameter for maximum number of hits
          lwa_params-name = 'MAX_HITS' .
          lwa_params-value = '50'.
          APPEND lwa_params TO lt_params.
          query->set_query_parameters( it_parameters = lt_params ).
          query->add_selection_param( iv_attr_name = 'OBJECT_ID'
                                                    iv_sign      = 'I'
                                                    iv_option    = 'EQ'
                                                    iv_low       = <lv_objectid>
                                                    iv_high      = '' ). " Set your search criteria. Repeat this code if you have multiple parameters
    "You can find possible search options for a query object in  GENIL_BOL_BROWSER
    result ?= query->get_query_result(  ).   " Get result from your search query
    me->typed_context-> <your result context node>->set_collection( result ). 
    Here you will have to create a context node in your view which would refer to query result object like for BTQAct its BTQRAct                      
    Hope this helps.
    e Regards,
    Bhushan

  • DYNAMIC QUERY FOR INSERT USING SELECT

    Hi All,
    I am facing an issue...I am un bale to do an dynamic query. i have explained my code and the sample create, insert statements. I shud insert values in a table using a select statement dynamically..
    create table listing (tel_no varchar2(16), list_key varchar2(30));
    create table dummy_extract ( extract_name varchar2(10),extract_query varchar2(400),extract_date date );
    create table dummy_query (tel_no varchar2(16), list_key varchar2(30));
    insert into listing (tel_no ,header_key) values ('123456','123.23');
    insert into dummy_extract (extract_name,extract_query,extract_date) values ('SP','SELECT TEL_NO, LIST_KEY FROM LISTING','10-DEC-2010');
    SET SERVEROUTPUT ON
    declare
    CURSOR CUR_QUERY IS
    SELECT * FROM DUMMY_EXTRACT ;
    V_STMT VARCHAR2(4000);
    BEGIN
    FOR I IN CUR_QUERY LOOP
    V_STMT := 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
    EXECUTE IMMEDIATE V_STMT using i.extract_query;
    DBMS_OUTPUT.PUT_LINE (V_STMT);
    END LOOP;
    END ;

    Hi Blue shadow and Saubik,
    I tried my query.It shows missing expression...Could you tell me the reason...
    SET SERVEROUTPUT ON
    declare
    CURSOR CUR_QUERY IS
    SELECT * FROM DUMMY_EXTRACT ;
    V_STMT VARCHAR2(4000);
    BEGIN
    FOR I IN CUR_QUERY LOOP
    --V_STMT := 'INSERT INTO'|| DUMMY_QUERY ||'VALUES ' ||(I.EXTRACT_QUERY ) ;
    EXECUTE IMMEDIATE 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
    DBMS_OUTPUT.PUT_LINE (V_STMT);
    END LOOP;
    END ;
    Error report:
    ORA-00936: missing expression
    ORA-06512: at line 14
    00936. 00000 - "missing expression"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Generating Dynamic Query for Ad-Hoc Reports

    Hello,
    What is the best way to create a dynamic query to generate ad-hoc reports? I have a couple of ideas but not sure which would work best and be most flexible.
    I would like our users to be able to check checkboxes for what data they would like returned in their report. The data would be pulled from a number of tables, 10+, depending on what pieces of data they checked.
    Should I write one dynamic query, with a bunch of IF statements in it?
    Should I write many individual queries and then join them together in a temp query?
    Should I create a temp table on our SQL server which contains the data from all of the tables; then query that? (I am worried about data being out-of-date with this option.)
    Which one of these solutions should I go with or is there a better solution that I am not considering?
    Thanks for the help.
    Josh

    Do you mean a Stored Procedure? Would the Stored Procedure then have one query on it with a bunch if IF statements? Maybe a bad example, but something like this?
    Yep.
    I haven't written a proc for a coupla years (I have DB people to do that for me now, bless 'em), but every DB is different, so the approach will vary depending on what DB you have.  It's perhaps time to buy a book or do a google or something.
    Adam

  • How to use dynamic query for this ??

    hi , i am new to ABAP. i got a requirement to write  dynamic query for the following code.
    kindly address. two set of queries are same.but condition is different.
    .IF p_psd EQ ' '.
    *C--End of change DF 1232137- (Transport # :CIDK980530 )
    *C--FETCH THE Deliverd Quantiity and Material Number
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng IN s_dqt
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
        IF sy-subrc = 0.
          SORT t_afpo BY aufnr matnr pwerk.
    *C--FETCH THE OBJECT NUMBER
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_aufk BY aufnr objnr.
    *C--FETCH THE Target Quantiity
            SELECT aufnr "ORDER number
                   gamng "Total order quantity target quantity
                   FROM afko
                   INTO TABLE t_afko
                   FOR ALL ENTRIES IN t_afpo
                   WHERE aufnr = t_afpo-aufnr
                   AND   gamng IN s_tqt.
            IF sy-subrc = 0.
              SORT t_afko BY aufnr .
            ENDIF.
          ENDIF.
        ELSE.
          MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
          LEAVE LIST-PROCESSING.
        ENDIF.
    *C--Begin of change DF 1232137- (Transport # :CIDK980530 )
      ENDIF.
      IF p_psd EQ c_x.
        SELECT aufnr "ORDER number
               wemng "Quantity of goods received for the order item
               matnr "MATERIAL NUMBER
               pwerk "PLANT
               dauat "Order Type
               FROM afpo
               INTO TABLE t_afpo
               WHERE aufnr IN s_order
               AND   wemng > 0
               AND   matnr IN s_matnr
               AND   pwerk IN s_plant
               AND   dauat = c_ro.
    if sy-subrc = 0.
    *C--FETCH THE OBJECT NUMBER
        IF  NOT t_afpo[] IS INITIAL.
          SORT t_afpo BY aufnr matnr pwerk.
          SELECT aufnr "ORDER number
                 objnr "Object number
                 FROM aufk
                 INTO TABLE t_aufk
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr.
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
        IF NOT t_afpo[] IS INITIAL.
    *C--FETCH THE Target Quantiity
          SELECT aufnr "ORDER number
                 gamng "Total order quantity target quantity
                 FROM afko
                 INTO TABLE t_afko
                 FOR ALL ENTRIES IN t_afpo
                 WHERE aufnr = t_afpo-aufnr
                 AND   gamng <> t_afpo-wemng .
          IF sy-subrc = 0.
            SORT t_afko BY aufnr gamng.
          ELSE.
            MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
            LEAVE LIST-PROCESSING.
          ENDIF.
        ENDIF.
      ELSE.
        MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
        LEAVE LIST-PROCESSING.
      ENDIF.
    Edited by: Thomas Zloch on Jan 5, 2011 1:30 PM please use code tags

    Hi friend,
    Try using MACRO and dynamic WHERE condition.
    Group simialr Select statements under a Macro.
    Build a dynamic where by checking conditions
    Call macro passing dynamic where condition.
    TABLES afpo.
    DATA: str TYPE string.
    *Macro definition
    DEFINE operation.
      select single *
           from afpo into afpo
           where (&1).    " Dynamic condition
    END-OF-DEFINITION.
    *Build dynamic WHERE by checking some conditions
    *If conditon 
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
    *Else
    CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
    *Endif.
    *Call Macro passing dynamic WHERE condition
    operation str.

  • How to create custom BOL object for dynamic query in CRM 7.0

    Hi,
    Could anyone please explain me with steps that how to create the custom BOL object for dynamic query in CRM 7.0, I did it in previous version but its throwing exception when i try to create the object of my dynamic query class. I just defined the entry of my in crmv_obj_btil to create the dynamic query BOL object. do i need to do any other thing also to make it work?
    Regards,
    Kamesh Bathla
    Edited by: Kamesh Bathla on Jul 6, 2009 5:12 PM

    Hi Justin,
    First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
    In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
    Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
    Thanks in Advance,
    mallikj2.

Maybe you are looking for