Dynamic Select statements (Joins)

Hi friends the following is the Source code in my FUNCTION MODULE and this i have few parameters in my report
MARKET
MEMBER
EFFECTIVE DATE
STATUS
COUNTRY
ADMISSION TYPE
I need the output from Different Select options (PARAMETER OPTIONS) from the User point of view..this is Just one market's (XETRA) selections .. I have 13 markets... Kindly anyone help me with the similar output I need a dynamic selection ...
SAMPLE or EXAMPLE CODE appreciated...
CASE iv_market.
WHEN lc_xtra_market.                                  
      lv_table = 'ZTGP_MEMBER_XTRA'.
IF iv_member_id IS INITIAL AND iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT ztgp_member_xtra~xetra_id
               ztgp_member_xtra~admission
               ztgp_member_xtra~partner
               ztgp_member_xtra~status
               ztgp_member_xtra~adm_type
               ztgp_member_xtra~object_id
               ztgp_member_xtra~addrnumber
               ztgp_member_xtra~beg_dat
               adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber WHERE ztgp_member_xtrastatus EQ iv_status AND                ztgp_member_xtrabeg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ELSEIF NOT iv_member_id IS INITIAL AND iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT  ztgp_member_xtra~xetra_id
        ztgp_member_xtra~admission
        ztgp_member_xtra~partner
        ztgp_member_xtra~status
        ztgp_member_xtra~adm_type
        ztgp_member_xtra~object_id
        ztgp_member_xtra~addrnumber
        ztgp_member_xtra~beg_dat
        adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE ztgp_member_xtra~xetra_id EQ iv_member_id AND
      ztgp_member_xtra~status EQ iv_status AND
      ztgp_member_xtra~beg_dat LE iv_date_effective AND
      ztgp_member_xtra~end_dat GE iv_date_effective.
     APPEND lt_member.
     ENDSELECT.
ELSEIF NOT iv_member_id IS INITIAL AND NOT iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT  ztgp_member_xtra~xetra_id
        ztgp_member_xtra~admission
        ztgp_member_xtra~partner
        ztgp_member_xtra~status
        ztgp_member_xtra~adm_type
        ztgp_member_xtra~object_id
        ztgp_member_xtra~addrnumber
        ztgp_member_xtra~beg_dat
        adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE ztgp_member_xtra~xetra_id EQ iv_member_id AND
adrc~country EQ iv_country AND
ztgp_member_xtra~status EQ iv_status AND
ztgp_member_xtra~beg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ELSEIF iv_member_id IS INITIAL AND NOT iv_country IS INITIAL AND iv_adm_type IS INITIAL.
SELECT  ztgp_member_xtra~xetra_id
       ztgp_member_xtra~admission
       ztgp_member_xtra~partner
       ztgp_member_xtra~status
       ztgp_member_xtra~adm_type
       ztgp_member_xtra~object_id
      ztgp_member_xtra~addrnumber
      ztgp_member_xtra~beg_dat
adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE adrc~country EQ iv_country AND
ztgp_member_xtra~status EQ iv_status AND
ztgp_member_xtra~beg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ELSEIF iv_member_id IS INITIAL AND iv_country IS INITIAL AND NOT iv_adm_type IS INITIAL.
SELECT  ztgp_member_xtra~xetra_id
        ztgp_member_xtra~admission
       ztgp_member_xtra~partner
       ztgp_member_xtra~status
    ztgp_member_xtra~adm_type
                ztgp_member_xtra~object_id
                ztgp_member_xtra~addrnumber
                ztgp_member_xtra~beg_dat
                adrc~country
INTO (lt_member-member_id, lt_member-admission, lt_member-partner, lt_member-status, lt_member-adm_type,
lt_member-object_id, lt_member-addrnumber, lt_member-beg_dat,lt_member-country)
FROM ztgp_member_xtra JOIN adrc ON ztgp_member_xtraaddrnumber = adrcaddrnumber
WHERE ztgp_member_xtra~adm_type EQ iv_adm_type AND
ztgp_member_xtra~status EQ iv_status AND
ztgp_member_xtra~beg_dat LE iv_date_effective AND
ztgp_member_xtra~end_dat GE iv_date_effective.
APPEND lt_member.
ENDSELECT.
ENDIF.
WHEN lc_repo_market.
WHEN lc_eurex_market.
When lc_fwb_market.
and so on... 13 markets..
      ENDIF.
IF sy-subrc NE 0.
      ENDIF.
    WHEN OTHERS.
      EXIT.
  ENDCASE.

In your case your internal tables seems to have constant and same structure so it can be defined statically.
lv_table &  lv_where_cond are variables.
SELECT F1 F2 FROM (lv_table)
             INTO CORRESPONDING FIELDS OF TABLE  itab
            WHERE (lv_where_cond).

Similar Messages

  • Dynamic SELECT statement causing CX_SY_DYNAMIC_OSQL_SEMANTICS error.

    Hello Gurus,
    We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
              SELECT (lt_select_flds)
                FROM (lf_tab_name)
                INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
                FOR ALL ENTRIES IN <lt_source_data>
                WHERE (lf_where).
    In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
    WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
    This code was working fine till yesterday when we encountered serious performance problems and the Basis team had to do some changes at the DB level [Oracle]. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS.
    Is setting changes at the Oracle level cause issues with how the data is being read at the DB. If yes, can you suggest what can we do to this code to get is working correctly [in case Basis can't revert back their changes]?
    Would appreciate any help we can get here.

    You don't understand - this error comes up when we run specific BEx queries.  It was working yesterday, but today it is not.  Our support package did not change from yesterday.  We did not apply any OSSnotes.
    We are however doing pre-prepare on our Prod system.
    The temporary table is used to store SIDs for use in the join.  the table exists in the dictionary, but not at an Oracle level.

  • DYnamic select statement in JDBC adapter?

    Hi guys,
                 Is it possible so send dynamic select statement in jdbc adapter?
    XIer

    Aamir,
    The poster did not specify whether this was sender or receiver channel, but it would only make sense that a "dynamic query" must be on the receiver communication channel since if it was on the sender channel, the channel would have to intelligently determine how to do dynamic queries.
    Also, the poster asked if there was a way to "send a dynamic query" to the channel.  This seems to imply that the channel is receiving information from somewhere to determine the query, which could only mean it is a receiver channel.
    If you would like more information on the JDBC sender communication channel, please open a new thread.

  • CX_SY_DYNAMIC_OSQL_SEMANTICS error with dynamic SELECT statement

    Hello Gurus,
    We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
              SELECT (lt_select_flds)
                FROM (lf_tab_name)
                INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
                FOR ALL ENTRIES IN <lt_source_data>
                WHERE (lf_where).
    In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
    WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
    This code was working fine till we were in BW 3.5 and is causing issues after we moved to BW 7.31 recently. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS. THE ERROR TEXT SAYS 'Unable to interpret '<LT_SOURCE_data>-DOC_NUMBER'.
    Can you pleasesuggest what can we do to this code to get is working correctly ? What has changed in ABAP Objects that has been introduced from BI 7.0 that could be causing this issue?
    Would appreciate any help we can get here.
    Thanks
    Arvind

    Hi,
    Please try this.
    data: lv_where type string.
    concatenate 'vbeln' 'in' 'r_vbeln' into lv_where separated by space.
    select *from table into itab where (lv_where).
    Also please check this sample code.
    REPORT ZDYNAMIC_WHERE .
    TABLES: VBAK.
    DATA: CONDITION TYPE STRING.
    DATA: BEGIN OF ITAB OCCURS 0,
    VBELN LIKE VBAK-VBELN,
    POSNR LIKE VBAP-POSNR,
    END OF ITAB.
    SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
    CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
    INTO CONDITION SEPARATED BY SPACE.
    SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
    WHERE (CONDITION).
    LOOP AT ITAB.
    WRITE 'hello'.
    ENDLOOP.
    Regards,
    Ferry Lianto

  • Need to wite pl sql procedure for dynamic select statement

    Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
    select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;

    I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
    TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM'))

  • Autonumbers through dynamic SELECT statement

    Trying to get an autonumber from an order table. The order_id I need from the table is only uniquely identified by the customer_id and the date/time. I've been advised that you cannot get an autonumber back from access without going via a select statement.
    I've tried to do a dynamic select statement by getting the date (short i.e.DD/MM/YY) from the server using a JSP custom tag and then putting this value into a hidden form field on the previous web page.
    However, when I load the next page the data gets input into the order table okay but the web page displayed is blank i.e. it doesn't display the order_id or the form to input credit card details. There are no error messages
    Code below, any ideas?
    <%@ page language="java" contentType="text/html"
    import="ShoppingBasket,Product,java.util.*"
    errorPage="errorpage.jsp"%>
    <jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
    <html>
    <head>
    <title>Your Order Has Been Received</title>
    </head>
    <body>
    <%
    String customer_id = request.getParameter("customer_id");
    String total_value = request.getParameter("total_value");
    String order_date = request.getParameter("order_date");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Novbase","","");
    java.sql.Statement Stmt = connection.createStatement();
    String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
    Stmt.executeUpdate(query);
    java.sql.Statement Stmt2 = connection.createStatement();
    java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );
    while(RS.next())
    String order_id = RS.getString("order_id");
    %>
    your order id is <%=order_id %>. Please input your credit card details in the form below:
    <form name="form1" method="post" action="shop-postorder4.jsp">
    <table width="90%" border="0" cellspacing="1" cellpadding="5">
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
    Card Type</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <select name="card_type">
    <option value="AMERICAN EXPRESS">American Express</option>
    <option value="MASTER CARD">Master Card</option>
    <option value="SWITCH">Switch</option>
    <option value="VISA">Visa</option>
    </select>
    *</font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
    Card No.</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="card_number" size=18 maxlength="18">
    *</font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Issue
    No. <font size="1"><br>
    (Switch card holders<br>
    only)</font></font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="issue_no" size="2" maxlength="2">
    </font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Valid
    From</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="valid_from" size="4" maxlength="4">
    e.g. 0502</font></td>
    </tr>
    <tr>
    <td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
    <td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Validy
    To</font></td>
    <td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="valid_to" size="4" maxlength="4">
    * e.g. 0105</font></td>
    </tr>
    </table>
    <input type="submit" name="Submit" value="Submit">
    <input type="hidden" name="order_id" value="<%=order_id %>">
    </form>
    <a href=" <%= response.encodeURL(shop-products.jsp") %">">
    <img src="images\toshop.gif" border="0" alt="Return to the Shop"></a>
    <%
    RS.close();
    Stmt.close();
    Stmt2.close();
    connection.close();
    %>
    </body>
    </html>
    </a>

    String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
    the data gets input into the order table okay
    java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );It is a field name as <B>time_date </B>in Orders table? And should you insert some value ?
    It seems your select return nothing.
    When your RS.next() is false, so you get blank. Add some HTNL code or just <HR> after while {} block so your would see it.

  • Inner Join for Dynamic Select statement

    Hi All,
      Can some one please help me in rewriting the below select statement where i have to remove the existing table1 by putting a dynamic table name which has the same table structure.
      select a~zfield1
               a~zfield2
          from ztab1 as a
           inner join ztab2 as b
               on b~ztab1-zfield3 = a~ztab2-zfield3
         where a~zfield4 = 'A'.
    I am looking something as below. But encountering an error when using the below statement
      select a~zfield1
               a~zfield2
          from (v_ztab1) as a
           inner join ztab2 as b
               on b~ztab1-zfield3 = a~ztab2-zfield3
         where a~zfield4 = 'A'.
      No Separate selects please. Please help me in rewriting the same select statement itself.
    Regards,
    PSK

    hi,
    What error you are getting ?
    Also INTO is missing from the statement.
    SELECT  pcarrid pconnid ffldate bbookid
      INTO  TABLE itab
      FROM  ( spfli AS p
                INNER JOIN sflight AS f ON pcarrid = fcarrid AND
                                           pconnid = fconnid    )
      WHERE p~cityfrom = 'FRANKFURT' AND
            p~cityto   = 'NEW YORK' .
    thanks

  • Adding one more table to the select statement joining 4 tables gives dump

    Hi All,
    There is a select statement using which four tables namely VBAK,VBAP,LIPS and LIKPUK(view) are joined(inner join).Here, date and time fields are selected from LIPS and used.
    My requirement is to consider the Date (LIKP - WADAT_IST) instead of LIPS-ERDAT  and time(LIKP-SPE_WAUHR_IST) is to be used instead of LIPS-erzet.
    Neither LIPS nor LIKPUK contains time(SPE_WAUHR_IST) field. And, I cannot remove LIPS table or LIKPUK view as each contains a unique field which is used in the report.
    When I tried to join LIPS in the select query, it is going to dump.
    Can someone suggest a good approach ?
    Thanks,
    Pavan

    Thank you for the detailed explanation of the dump.
    The dump details together with your code lead to the answer: 42.
    Regards,
    Clemens

  • JDBC: Dynamic select statement

    Hi,
    I am working on a JDBC to SAP integration. I am trying to SELECT data from table for a specific time interval.
    In the JDBC configuration i am using the Query SQL Statement
    For example: select * from X where time='20080808'
    Now is it possible to use for example the system date and time of the server where pi is installed or any other dynamic data?
    Maybe like this: select * from X where time =@sysdate
    If it is possible how? If not why?
    I appreciate your help.
    Thanks in advance...

    Hi,
    In case of receiver JDBC you can map todays date to the select statement and make the select statement dynamic, however in the sender it can't be done. The work around may be to call the stored procedure from the sender adapter and using the stored procedure construct the select query dynamically.
    Thanks
    SaNv...

  • Getting result of dynamic select statement into variable

    I have a function that builds a dynamic sql statement. I then want to take the result of that statement and insert it into a variable. I have tried this
    execute immediate strSQL USING OUT intCounter;but that is giving me an error on that line of code. The SQL is a select count(*) and works fine. It is just how to get it into the variable that is tripping me up.
    Thanks,
    Eva

    Sure. Version 11g. The complete procedure reads as follows:
    CREATE OR REPLACE FUNCTION VALIDATIONQUESTIONRESULT
        p_ShortName VARCHAR2,
        p_SiteID    VARCHAR2
    RETURN NUMBER IS
        strSQL VARCHAR2(5000);
        strTableName VARCHAR2(200);
        strPatIDFieldName VARCHAR2(200);
        intCounter NUMBER;
    BEGIN
        select VALIDATIONSQL into strSQL from vwvalidationquestions where upper(shortname) = upper(p_ShortName);
        select
                case UPPER(DBTABLENAME)
                    when 'CPTICODES' then 'CPTIPATID'
                    when 'CPTIICODES' then 'CPTIIPATID'
                    when 'DEMOGRAPHICS' then 'PATID'
                    when 'FAMILYHISTORY' then 'FHPATID'
                    when 'GCODES' then 'GCODEPATID'
                    when 'HOSPITALIZATION' then 'HPATID'
                    when 'MEDICALHISTORY' then 'MHPATID'
                    when 'MEDICATIONS' then 'MPATID'
                    when 'PROCEDURES' then 'PPATID'
                    when 'VISITS' then 'VPATID' end into strPatIDFieldName
        from DATASPECIFICATIONS where UPPER(SHORTNAME) = UPPER(p_ShortName);
        strSQL := strSQL||' and '||strPatIDFieldName||' in (select PATID from DEMOGRAPHICS where PARTICID = '||p_SiteID||');';
        execute immediate strSQL into intCounter;
        return intCounter;
    END VALIDATIONQUESTIONRESULT; strSQL when checked builds perfectly. I get 100% what I expect from it. An example of what I am getting from strSQL is:
    select count(*) from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);I am getting the number I would expect from this. I just need to put that number into intCounter. I tried altering strSQL so it looked like this:
    select count(*) into intCounter from Procedures where TO_CHAR(ProcdDt, 'MM') = TO_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM') and TO_CHAR(ProcdDt, 'YYYY') = TO_CHAR(ADD_MONTHS(SYSDATE, -12), 'YYYY') and PPATID in (select PATID from DEMOGRAPHICS where PARTICID = 12);but that gave me an error on the execute immediate line as well.
    Sorry, I thought it would be simple so that was why I only put that bit of info. I guess it is more complicated than it at first appeared!
    Eva

  • Cursor - dynamic select statement?

    Hello!
    I am passing a string into a function, and my string is a sql select statement. Is it possible to create a cursor using the string that is passed to the function?
    Ex:
    create or replace function "GETCOUNT"
    (sqlstring in VARCHAR2)
    return NUMBER
    is
    rec_count NUMBER; --I eventually want to return a count of the rows returned from my sqlstring
    cursor c1 is sqlstring <--this is what I'd like to do...but how?
    begin
    ... -- I haven't gotten to this point yet
    end;
    The error I get says 'Encountered the symbol "sqlstring" when expecting on of the following: ( select '
    Thanks in advance!!

    Something like this ->
    create or replace procedure gen_cur(str in varchar2,rc in out sys_refcursor)
    is
    str1 varchar2(500);
    begin
    str1 := 'select empno,ename,hiredate,sal
    from emp
    where '||str;
    open rc for str1;
    exception
    when others then
    dbms_output.put_line(sqlerrm);
    end;
    variable b refcursor
    declare
    src varchar2(300);
    begin
    src:= 'sal between 2000 and 7000';
    gen_cur(src,:b);
    exception
    when others then
    dbms_output.put_line(sqlerrm);
    end;
    print bRegards.
    Satyaki De.

  • Workarea in dynamic select-statement

    Hello !
    i hope i can get some help...
    it should be possible to do a dynamic select like this:
        SELECT * FROM (S_TABLE) INTO WA_TABLE.
    but my Problem is:
    how can i define (dynamic) the wa_table?
    it should be the same structure like the table i selected before (the value is in s_table).
    thanks very much...
    Helmut

    Hi helmut,
    1. we need to construct dynamic internal table
       for this purpose.
    2. this program
       gives a selection screen for entering
       the TABLE NAME eg. T001.
    3. then it SELECTS * from that table,
       dynamically,
       and gives the data in
    <b>   <dyntable></b>
    4. Just copy paste in new program.
    5.
    rEPORT abc.
    COMPULSORY
    FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
    FIELD-SYMBOLS: <dynline> TYPE ANY.
    DATA: lt TYPE lvc_t_fcat.
    DATA: ls TYPE lvc_s_fcat.
    FIELD-SYMBOLS: <fld> TYPE ANY.
    DATA : fldname(50) TYPE c.
    PARAMETERS : iname LIKE dd02l-tabname obligatory.
    START-OF-SELECTION.
    GET INFO
    DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
    EXPORTING
    tabname = iname
    TABLES
    ddfields = ddfields.
    CONSTRUCT FIELD LIST
    LOOP AT ddfields.
    ls-fieldname = ddfields-fieldname.
    APPEND ls TO lt.
    ENDLOOP.
    PERFORM
    PERFORM mydyntable USING lt.
    select * from (iname)
    into table <dyntable>.
    BREAK-POINT.
    INDEPENDENT FORM
    FORM mydyntable USING lt TYPE lvc_t_fcat .
    Create Dyn Table From FC
    FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
    FIELD-SYMBOLS: <fs_1>.
    FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
    DATA: lt_data TYPE REF TO data.
    ASSIGN lt_data TO <fs_data>.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = lt
    IMPORTING
    ep_table = <fs_data>
    EXCEPTIONS
    generate_subpool_dir_full = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    ENDIF.
    Assign Dyn Table To Field Sumbol
    ASSIGN <fs_data>->* TO <fs_1>.
    ASSIGN <fs_1> TO <fs_2>.
    ASSIGN <fs_1> TO <dyntable>.
    ENDFORM. "MYDYNTABLE
    regards,
    amit m.

  • Cursor - Suggestions for Dynamic select statements

    Hey,
    Am trying to define a cursor like this -
    cursor c1 is
    select table_name from dba_tables INTERSECT select table_name from dba_tables@SOME_DBLINKMy need is to pass this dblink as IN parameter to the procedure and use it in the select statement for cursor. How can I do this?
    Any suggestion is highly appreciated. Thanks!

    Well that was meant to be my point. If you had two, you wouldn't (I hope) call the second one "c2" - you would be forced to think about what it represented, and name it "c_order_history" or something. Sticking "1" on the end does not make an extensible naming convention for cursors any more than it does for variables, procedures, tables or anything else, and so the "1" in "c1" is redundant because there will never be a c2.

  • Using functions in select statement(joining 5 tables) taking long time in Oracle

    Hi,
    I have created a query in oracle which joins 5 tables and uses two functions(function names are 'ca_concat' and 'ca_concat_noseq').
    Query takes approximately 40 secs to execute around 12000 records. If I remove the functions from query it excutes within a second..
    Note : I have used the oracle SQL Developer for testing the query.
    It would be appriciated if anybody helps me to improve the perfomance of the query.
    Below are the querie with and without functions:
    1. Query with functions:
    select
    imsAuditEvent12.id as ID,
    imsAuditEvent12.audit_time as AUDIT_TIME,
    imsAuditEvent12.admin_dn as ADMIN_DN,
    imsAuditEvent12.admin_name as ADMIN_NAME,
    imsAuditEvent12.event_name as EVENT_NAME,
    imsAuditEvent12.event_description as EVENT_DESCRIPTION,
    imsAuditEvent12.event_state as EVENT_STATE,
    imsAuditEvent12.envname as ENVNAME,
    imsAuditTaskSession12.task_name as TASK_NAME,
    imsAuditTaskSession12.id as TASK_ID,
    imsAuditTaskSession12.task_description as TASK_DESCRIPTION,
    imsAuditTaskSession12.task_priority as TASK_PRIORITY,
    S1.OBJECT_ID,
    S1.OBJECT_NAME as OBJECT_NAME,
    S1.OBJECT_TYPE as OBJECT_TYPE,
    S2.ATTRIBUTE_NAME as ATTRIBUTE_NAME,
    S2.ATTRIBUTE_OLDVALUES as ATTRIBUTE_OLDVALUES,
    S2.ATTRIBUTE_NEWVALUES as ATTRIBUTE_NEWVALUES,
    S3.OBJECT_DN as OBJECT_DN,
    S3.OBJECT_TYPE as IMSOBJECT_TYPE,
    S3.CONTAINER_NAME as CONTAINER_NAME,
    S3.CONTAINER_DN as CONTAINER_DN,
    S3.CONTAINER_TYPE as CONTAINER_TYPE
    from
    imsAuditEvent12 LEFT JOIN imsAuditTaskSession12 ON imsAuditTaskSession12.id=imsAuditEvent12.tasksession_id LEFT JOIN
    (select parent_event_id,
    ca_concat('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.object_name','imsAuditEventObject12') as OBJECT_NAME,
    ca_concat('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.object_type','imsAuditEventObject12') as OBJECT_TYPE,
    ca_concat_noseq('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.ID','imsAuditEventObject12') as OBJECT_ID
    from
    imsAuditEventObject12 group by parent_event_id) S1
    ON imsAuditEvent12.id = S1.parent_event_id LEFT JOIN
    (select
    parent_object_id,
    ca_concat('parent_object_id',parent_object_id,'attribute_name','imsauditobjectattributes12') as ATTRIBUTE_NAME,
    ca_concat('parent_object_id',parent_object_id,'attribute_oldvalue','imsauditobjectattributes12') as ATTRIBUTE_OLDVALUES ,
    ca_concat('parent_object_id',parent_object_id,'attribute_newvalue','imsauditobjectattributes12') as ATTRIBUTE_NEWVALUES
    from
    imsauditobjectattributes12 group by parent_object_id) S2
    ON S1.OBJECT_ID = S2.parent_object_id LEFT JOIN
    (select
    parent_event_id,
    ca_concat('parent_event_id',parent_event_id,'OBJECT_DN','imsauditobjectrelationship12') as OBJECT_DN,
    ca_concat('parent_event_id',parent_event_id,'OBJECT_TYPE','imsauditobjectrelationship12') as OBJECT_TYPE ,
    ca_concat('parent_event_id',parent_event_id,'CONTAINER_NAME','imsauditobjectrelationship12') as CONTAINER_NAME,
    ca_concat('parent_event_id',parent_event_id,'CONTAINER_DN','imsauditobjectrelationship12') as CONTAINER_DN,
    ca_concat('parent_event_id',parent_event_id,'CONTAINER_TYPE','imsauditobjectrelationship12') as CONTAINER_TYPE
    from
    imsauditobjectrelationship12 group by parent_event_id) S3
    ON imsAuditEvent12.id =S3.parent_event_id where imsauditevent12.id > 0 and imsauditevent12.id <12000 order by imsauditevent12.id ASC;
    2. Query without using functions:
    select * from imsauditeventobject12 left join imsauditevent12 on imsauditeventobject12.id=imsauditevent12.id left join imsauditobjectattributes12 on imsauditeventobject12.id=imsauditobjectattributes12.parent_object_id left join imsaudittasksession12 on imsauditevent12.tasksession_id=imsaudittasksession12.id left join imsAuditObjectRelationship12 on imsAuditEvent12.id =imsAuditObjectRelationship12.parent_event_id where imsauditevent12.id >0 and imsauditevent12.id < 12000 order by imsauditevent12.id asc;
    Thanks,
    Badri

    Hi,
    Please find the below more information about the query.
    DB version: Oracle 11g Enterprise Edition Release 11.2.0.1.0
    Below are source of the functions:
    create or replace function ca_concat( ca_key_name in varchar2,
                           ca_key_val  in varchar2,
                           ca_other_col_name in varchar2,
                           ca_tname     in varchar2 )
       return varchar2
          as
           type rc is ref cursor;
           l_str    varchar2(32000);
           l_sep    varchar2(1);
           l_val    varchar2(32000);
           l_count   number(6);
           l_cur    rc;
       begin
       l_count :=1;
       l_str := '';
           open l_cur for 'select '|| ca_other_col_name ||'
                             from '|| ca_tname || '
                            where ' || ca_key_name || ' = '
                       using ca_key_val;
           loop
               fetch l_cur into l_val;
               l_val := SUBSTR(l_val,0,102);
               exit when (l_cur%notfound or l_count > 38);
               l_str := l_str || l_sep || l_count || '.' || l_val;
               l_sep := ',';
           l_count := l_count + 1;
           end loop;
           close l_cur;
           return l_str;
       end;
      create or replace function ca_concat_noseq( ca_key_name in varchar2,
                           ca_key_val  in varchar2,
                           ca_other_col_name in varchar2,
                           ca_tname     in varchar2 )
       return varchar2
          as
           type rc is ref cursor;
           l_str    nvarchar2(32000);
           l_sep    varchar2(1);
           l_val    varchar2(32000);
           l_count   number(6);
           l_cur    rc;
       begin
       l_count :=1;
           open l_cur for 'select '||ca_other_col_name||'
                             from '|| ca_tname || '
                            where ' || ca_key_name || ' = '
                       using ca_key_val;
           loop
               fetch l_cur into l_val;
               exit when (l_cur%notfound or length(l_val)>3000 or l_count>1);
               l_str := l_str || l_sep || l_val ;
               l_sep := ',';
           l_count := l_count + 1;
           end loop;
           close l_cur;
           return l_str;
    end;
    Below are the tables structures:
    DESC imsauditevent12;
    Name                           Null     Type                                                                                                                                                                                      
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    TASKSESSION_ID                 NOT NULL NUMBER                                                                                                                                                                                       
    TASKSESSION_OID                         VARCHAR2(100)                                                                                                                                                                                
    PARENT_EVENT_OID                        VARCHAR2(100)                                                                                                                                                                                
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    EVENT_OID                      NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ADMIN_DN                       NOT NULL VARCHAR2(512)                                                                                                                                                                                
    ADMIN_NAME                              VARCHAR2(255)                                                                                                                                                                                
    EVENT_NAME                     NOT NULL VARCHAR2(255)                                                                                                                                                                                
    EVENT_DESCRIPTION                       VARCHAR2(4000)                                                                                                                                                                               
    EVENT_STATE                             VARCHAR2(100)                                                                                                                                                                                
    ENVNAME                        NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ENV_OID                        NOT NULL VARCHAR2(100)                                                                                                                                                                                
    DESC imsauditeventobject12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_EVENT_ID                NOT NULL NUMBER                                                                                                                                                                                       
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    OBJECT_TYPE                    NOT NULL VARCHAR2(100)                                                                                                                                                                                
    OBJECT_NAME                             VARCHAR2(255)                                                                                                                                                                                
    DESC imsauditobjectattributes12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_OBJECT_ID               NOT NULL NUMBER                                                                                                                                                                                       
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    DISPLAY_NAME                            VARCHAR2(255)                                                                                                                                                                                
    ATTRIBUTE_NAME                 NOT NULL VARCHAR2(255)                                                                                                                                                                                
    ATTRIBUTE_OLDVALUE                      VARCHAR2(4000)                                                                                                                                                                               
    ATTRIBUTE_NEWVALUE                      VARCHAR2(4000)                                                                                                                                                                               
    DESC imsaudittasksession12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_TS_OID                           VARCHAR2(100)                                                                                                                                                                                
    PARENT_EVENT_OID                        VARCHAR2(100)                                                                                                                                                                                
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    TASKSESSION_OID                NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ADMIN_DN                       NOT NULL VARCHAR2(512)                                                                                                                                                                                
    ADMIN_NAME                              VARCHAR2(255)                                                                                                                                                                                
    TASK_NAME                               VARCHAR2(255)                                                                                                                                                                                
    TASK_TAG                       NOT NULL VARCHAR2(255)                                                                                                                                                                                
    TASK_DESCRIPTION                        VARCHAR2(4000)                                                                                                                                                                               
    TASK_PRIORITY                           NUMBER                                                                                                                                                                                       
    STATE                          NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ENVNAME                        NOT NULL VARCHAR2(100)                                                                                                                                                                                
    ENV_OID                        NOT NULL VARCHAR2(100)                                                                                                                                                                
    DESC imsAuditObjectRelationship12;
    Name                           Null     Type                                                                                                                                                                                         
    ID                             NOT NULL NUMBER                                                                                                                                                                                       
    PARENT_EVENT_ID                NOT NULL NUMBER                                                                                                                                                                                       
    AUDIT_TIME                     NOT NULL TIMESTAMP(6)                                                                                                                                                                                 
    OBJECT_TYPE                    NOT NULL VARCHAR2(100)                                                                                                                                                                                
    OBJECT_DN                      NOT NULL VARCHAR2(512)                                                                                                                                                                                
    CONTAINER_TYPE                 NOT NULL VARCHAR2(100)                                                                                                                                                                                
    OBJECT_NAME                    NOT NULL VARCHAR2(255)                                                                                                                                                                                
    CONTAINER_NAME                 NOT NULL VARCHAR2(255)                                                                                                                                                                                
    CONTAINER_DN                   NOT NULL VARCHAR2(512)                                                                                                                                                                          
    OPERATION                      NOT NULL VARCHAR2(50)                                                                                                                                                                                 
    Thanks,
    Badri

  • Dynamic select statements

    PARAMETERS: p_table LIKE dd02t-tabname OBLIGATORY.
    SELECT *
      FROM (p_table) CLIENT SPECIFIED
      INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
      WHERE mandt = '800'.
    mandt is the system client number as 800.
    dyn_table: dynamic internal table
    p_table = mara.
    runtime error occurs at this statement.
    SQL error in the database when accessing a table.
    Kindly guide.

    Try
    CASE xdetails-type_kind.
          WHEN 'C'.
            xfc-datatype = 'CHAR'.
          WHEN 'N'.
            xfc-datatype = 'NUMC'.
          WHEN 'D'.
            xfc-datatype = 'DATE'.
          WHEN 'P'.
            xfc-datatype = 'PACK'.
          WHEN OTHERS.
            xfc-datatype = xdetails-type_kind.
        ENDCASE.
    instead of
    xfc-datatype = xdetails-type_kind.
    You can also check this link:
    http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable
    Or try to do it like this:
    http://wiki.sdn.sap.com/wiki/display/Snippets/Howtocreateadinamicinternaltable
    It means to use FM REUSE_ALV_FIELDCATALOG_MERGE instead of using cl_abap_typedescr.
    Adrian

Maybe you are looking for

  • "Error while trying to sync Audio and Midi"

    "Error while trying to sync Audio and Midi" I have been having this problem now and then for some time. Now, I can't run any audio files without a lot of popping. I tried all the suggestions on the support document for this issue. I even downloaded n

  • Humming noise when I connect my sound card to my band mixer H

    Hello, This is driving me nuts. What I'm trying to do is connect my pc through my Audigy 2 pci card to my band mixer so I can play tracks through my main system. I know the cords aren't the problem because they are high quality and they work fine in

  • How do i get the music back that i purchased, on my iphone, it dissapeared when i put a cd on the phone

    I had brought music from itunes and it was on my iphone, I puta cd on my computer and on my phone from itunes and my music i purchased dissapeared. It shows up on my purchases but not in itunes

  • Balance Display not updating

    Can anyone tell me why the balance display on my phone is not updating anymore?  I have a Samsung Gusto that I bought on 1/5.  It updated the first few times I used it and then it just quit.  I can still get the balance online, but it would be nice t

  • Form with variable length pages

    Hi, I have a form which has categories of data - some categories require many fields and some require only a handful of fields. I want to put each category on a single page. My Master Page has a graphic which serves as a background for all of the pag