Variable has SELECT query how to execute it

hi all
     question may be odd one but guide me on that.
requirement is as ,  i have a BAPI which have a STRING type INPUT parameter let P1,  P1 contain a SELECT query as its value.
  now i want to execute the select query which P1 contain in my BAPI , how i can do it.
e.g.
     P1 = 'Select single * from MARA .'  
now  either i have extract the P1 OR have to do something to get this query executed .
please guide me.

Hi
We can use the FM
Earlier WS_QUERY was there but it is obsolete. we need to check for the new one.
Or try  to use the FM
GUI_EXEC to run it.
Thanks & Regards,
Chandralekha.

Similar Messages

  • How to optimize the select query that is executed in a cursor for loop?

    Hi Friends,
    I have executed the code below and clocked the times for every line of the code using DBMS_PROFILER.
    CREATE OR REPLACE PROCEDURE TEST
    AS
       p_file_id              NUMBER                                   := 151;
       v_shipper_ind          ah_item.shipper_ind%TYPE;
       v_sales_reserve_ind    ah_item.special_sales_reserve_ind%TYPE;
       v_location_indicator   ah_item.exe_location_ind%TYPE;
       CURSOR activity_c
       IS
          SELECT *
            FROM ah_activity_internal
           WHERE status_id = 30
             AND file_id = p_file_id;
    BEGIN
       DBMS_PROFILER.start_profiler ('TEST');
       FOR rec IN activity_c
       LOOP
          SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
                     INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
                     FROM ah_item --464000 rows in this table
                    WHERE item_id_edw IN (
                             SELECT item_id_edw
                               FROM ah_item_xref --700000 rows in this table
                              WHERE item_code_cust = rec.item_code_cust
                                AND facility_num IN (
                                       SELECT facility_code
                                         FROM ah_chain_div_facility --17 rows in this table
                                        WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                                          AND div_id = (SELECT div_id
                                                          FROM ah_div --8 rows in this table
                                                         WHERE division = rec.division)));
       END LOOP;
       DBMS_PROFILER.stop_profiler;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN TOO_MANY_ROWS
       THEN
          NULL;
    END TEST;The SELECT query inside the cursor FOR LOOP took 773 seconds.
    I have tried using BULK COLLECT instead of cursor for loop but it did not help.
    When I took out the select query separately and executed with a sample value then it gave the results in a flash of second.
    All the tables have primary key indexes.
    Any ideas what can be done to make this code perform better?
    Thanks,
    Raj.

    As suggested I'd try merging the queries into a single SQL. You could also rewrite your IN clauses as JOINs and see if that helps, e.g.
    SELECT DISTINCT ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
               INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
               FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
              WHERE ai.item_id_edw = aix.item_id_edw
                AND aix.item_code_cust = rec.item_code_cust
                AND aix.facility_num = acdf.facility_code
                AND acdf.chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                AND acdf.div_id = ad.div_id
                AND ad.division = rec.division;ALSO: You are calling ah_internal_data_pkg.get_chain_id (p_file_id) every time. Why not do it outside the loop and just use a variable in the inner query? That will prevent context switching and improve speed.
    Edited by: Dave Hemming on Dec 3, 2008 9:34 AM

  • How to store data in a variable in select query

    Hi,
    Below is the select query in which i want to store the data in variable but i am getting runtime error as the fields are more as compared to variable,the declaration is necessary for it due to the reteriving for data.
    Please provide me guidelines how to do it.
    DATA: BEGIN OF ITSC01 OCCURS 0,
          PRUEFLOS LIKE QALS-PRUEFLOS,
          MBLNR LIKE QAMB-MBLNR,
          LGORT LIKE MSEG-LGORT,
          END OF ITSC01.
    IF STIT-MGEIG GE 0.
    LOOP AT STIT." WHERE PRUEFLOS EQ STIT-PRUEFLOS.
        SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
               INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
               INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
               INTO SLOC WHERE A~PRUEFLOS EQ STIT-PRUEFLOS.
    *           INTO TABLE ITSC01 WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR EQ STIT-MATNR AND C~LGORT EQ 'SC03'.
        SORT ITSC01 BY PRUEFLOS.
         READ TABLE ITSC01 WITH KEY PRUEFLOS = ITSC01-PRUEFLOS.
          IF ITSC01-LGORT EQ 'SC03'.
          STIT-MGEIG = 0.
          ENDIF.
    MODIFY STIT.
    ENDLOOP.
    ENDIF.

    hmm..
    try this:
    DATA: l_PRUEFLOS LIKE QALS-PRUEFLOS,
              l_MBLNR LIKE QAMB-MBLNR,
             l_LGORT LIKE MSEG-LGORT,
    IF STIT-MGEIG GE 0.
    LOOP AT STIT." WHERE PRUEFLOS EQ STIT-PRUEFLOS.
        SELECT APRUEFLOS BMBLNR C~LGORT FROM QALS AS A
               INNER JOIN QAMB AS B ON BPRUEFLOS = APRUEFLOS
               INNER JOIN MSEG AS C ON CMBLNR = BMBLNR AND CMJAHR = BMJAHR
               INTO ( l_PRUEFLOS , l_MBLNR, l_LGORT )
          WHERE A~PRUEFLOS EQ STIT-PRUEFLOS.
              INTO TABLE ITSC01 WHERE APRUEFLOS EQ STIT-PRUEFLOS AND AMATNR EQ STIT-MATNR AND C~LGORT EQ 'SC03'.
        SORT ITSC01 BY PRUEFLOS.
         READ TABLE ITSC01 WITH KEY PRUEFLOS = ITSC01-PRUEFLOS.
          IF ITSC01-LGORT EQ 'SC03'.
          STIT-MGEIG = 0.
          ENDIF.
    MODIFY STIT.
    ENDLOOP.
    ENDIF.

  • In Select query how to fetch values through multiple parameters  where conditon

    Dear Experts,
    I have one table(T) with 4 fields: f1, f2, f3, f4. In that based on f2, f3, f4 and parameter condition( f2 values) how to fetch f1 values. I have attached screen shot. What is the where condition in select query?
    DATA: it_T type standard table of ty_T,
              wa_T type ty_T.
    parameters: p_f2_1 type T-f3,
                      p_f2_2 type T-f3,
                      p_f2_3 type T-f3,
                      p_f2_4 type T-f4,
                      p_f2_5 type T-f4,
                      p_f2_6 type T-f4.
    select f1  f2  f3  f4 from T into table it_T where ?
    What is the where condition ?.
    Regards,
    Abbas.

    Hi Syed,
    Do all the parameters p_f2_1 ... p_f2_6 contain values for the same field f2? And do you need all the entries from the table T which contain f2 = any of the entered value? If yes, Then you can try the following where condition -
    select f1  f2  f3  f4 from T into table it_T
      where f2 =  p_f2_1  OR
                 f2 =  p_f2_2  OR
                 f2 =  p_f2_3  OR
                 f2 =  p_f2_4  OR
                 f2 =  p_f2_5  OR
                 f2 =  p_f2_6.
    P.S: If any of the above parameters are optional as per your requirement it will be better to build a dynamic query and use it in the where condition.
    Regards,
    Rachna.

  • Select query is not executing

    Hi Friends,
    my code is :
    itab-vbeln = bseg-vbeln.
    if not itab-vbeln is initial.
    select single vbeln inco1 inco2 into ( itab-vbeln itab-inco1 itab-inco2)
    from vbrk where vbeln = itab-vbeln.
    appned itab.
    note : here inco1 inco2 are incoterms
    my question is  can we direct move the values of bseg-vbeln into itab-vbeln. ???
    and i am generating the report with one varient , when i debug this report the
    there is no value in bseg-vbeln. it is showing null value.thats why my select query is not working..but i want execute this select query final.
    in output i want display the inco1 inco2 data.(incoterms)
    any help please.
    urgent.
    regards,
    vijay.

    Hi Vijay,
    First you need to check it out whether <b>itab-vbeln = bseg-vbeln</b> is in with in LOOP or not (<b>if ITAB is intenal table</b>)
    if itab is internal table you should write above statement with in loop, and also check it out in debug mode why bseg-vbeln value is not coming.
    and one more thing you need to make small correction in ur code use ',' .
    select single vbeln inco1 inco2 into ( <b>itab-vbeln, itab-inco1, itab-inco2</b>)
    from vbrk where vbeln = itab-vbeln
    Note: when ever use select single u should pass values into work area, dont use internal table .
    <b>if you have more doubts just send your entire code then i will rewrite it.</b>
    <b>Reward with points if useful.</b>
    Regards,
    Vijay Krishna

  • MDO select query: how to control sort order using parameter

    Hi experts, is there a way of controling the sort order of an MDO select query using some parameter?
    I was thinking about using some statement like CASE [Param.1] WHEN 'abc' THEN [ORDER_NO]...END in sort section of the query but it is not working.
    Of course I colud go for various select queries...but I am wondering if it can be done using only one?
    Any ideas?
    Thanks for any help

    Hi Marco,
    Yes this can be achieved dynamically using SortExpr under dynamic link assignment in MDOAction block if you are using a transaction to call it.
    Please check below thread:
    Re: MDO Query Action Block In MII Transaction
    Or else, this [Param.1] thing should work as well provided it doesn't get the logic part in it, just pass the columns names separated by comma. Haven't tried it though, will check it for you.
    Best Regards,
    Swaroop

  • Variables in SELECT query

    consider the query
    SELECT v_column_name FROM v_table_name
    I have declared and defined v_column_name, v_table_name variable but still Oracle PL/SQL
    complains
    it says v_table_name not declared.
    If i put this query in a string and open
    with cursor it works fine.
    Please send me mail at [email protected]

    Does any one knows answer to this problem
    thanks
    Pramod

  • Defaulting variable in select query

    Hi Experts,
      I am having some different requirement here like, while selecting data from a table, for some column need to deafult some constant value for all lines if the actual value in the DB table has no value. There are some aggregate results like MAX( [DISTINCT] col ), MIN( [DISTINCT] col )...COUNT( * ) (or count(*)) , But there is nothing as such to fill constant value in query time it self while selecting data.
      Do help me if any one come across such a like.
    Ex:
       Normal code we write:
       SELECT carrid connid cityfrom cityto
           FROM spfli
           INTO CORRESPONDING FIELDS OF wa.
         WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
       ENDSELECT.
       Required code need to write:
    SELECT NVL(e.carrid,1000) connid cityfrom cityto
           FROM spfli
           INTO CORRESPONDING FIELDS OF wa.
      WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
    ENDSELECT.
    Thanks in advance.
    Mohan.

    Hi Mohan
    As per my knowledge, we do not have the provision of the function that you are looking in ABAP as we have only 5 aggregate functions. Below are the same for your reference.
    1. MAX
    2. MIN
    3. AVG
    4. SUM
    5. COUNT
    I can understand your concern on the performance, but i guess there is not other way to go. Since you need to modify only one field, you can try with a logic similar to the below one:
    SELECT carrid connid cityfrom cityto
           FROM spfli
           INTO TABLE itab.
    wa-carrid = '1000'.
    MODIF itab FROM wa TRANSPORTING carrid WHERE carrid IS INITIAL.
    I guess this should be even better than modifying in the SELECT itself...
    Hope this helps...
    Kind Regards
    Eswar

  • DYNAMIC VARIABLE IN SELECT QUERY

    hi all,
    i m selecting a belnr from one table and want to fire another query on different table wherein this belnr falls somewhere in middle of the whole field.
    eg: wa-belnr = 4000
    select * from cdhdr where
    objectclass = '%wa-belnr%.
    i want to select records which contains this belnr.
    but %wa-belnr% doesnt work.
    pls suggest if theres any solution.

    Hi,
    select * from cdhdr where
    objectclass = '%wa-belnr%.
    In the above query use LIKE instead of '='.
    Also instead of %wa-belnr% Use like this
    <b>DATA: str type string.
    concatenate '%' wa_belnr '%' into str.
    select * from cdhdr where
    objectclass LIKE str.</b>
    Regards,
    Sesh

  • How to execute an sql function containing a SELECT query as paramete

    Hi
    I want to execute this sql query using JDBC methods , but could not be able to find any appropriate method to execute this query.
    select dbms_xmlgen.getxml(select * from departments) from dual
    please some one help with appropriate java code to execute it.
    Thank you

    >
    I want to execute this sql query using JDBC methods , but could not be able to find any appropriate method to execute this query.
    select dbms_xmlgen.getxml(select * from departments) from dual
    please some one help with appropriate java code to execute it.
    >
    Java code? You can't execute that query at all since it is invalid. The parameter needs to be a query string NOT a query.
    select dbms_xmlgen.getxml('select * from departments') from dual See the DBMS_XMLGEN package in the docs
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_xmlgen.htm#i1013206
    >
    Converts the results from the SQL query string to XML format, and returns the XML as a temporary CLOB, which must be subsequently freed using the DBMS_LOB.FREETEMPORARY call:
    DBMS_XMLGEN.GETXML (
    sqlQuery IN VARCHAR2,
    dtdOrSchema IN number := NONE)
    RETURN CLOB;
    >
    Then you execute that query like any other query that returns a result set. The result set will consist of one row and one column of CLOB datatype.
    See the JDBC Developer's Guide - it has examples of how to execute queries that return result sets.
    And this section shows how tow read/write CLOBs
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/oralob.htm#sthref755

  • How to ignore zero in select query

    select * from EINA where  EINAMATNR = <b>yyyy</b> and EINALIFNR = <b>zzzz</b>
    In select query, how to ignore zero? for example, EINAMATNR = 0000000yyyy, EINALIFNR=000zzz
    Maybe I can use LIKE keyword in sql query. Any other way?
    Thanks.

    Use the following conversion routines to convert yyyy & zzzz  to remove the leading zeros and then pass it to your select query.
    For Matnr -> CONVERSION_EXIT_MATN1_INPUT
    For LIFNR ->CONVERSION_EXIT_alpha_input.
       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
            EXPORTING
              input  = yyyy
            IMPORTING
              output = t_lifnr.
          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
            EXPORTING
              input  = zzzz
            IMPORTING
              output = t_matnr.
    select * from EINA where EINA~MATNR = t_matnr  and EINA~LIFNR = t_lifnr .

  • How to run batch select query ?

    I have multiple "select" query .
    how do i run the query in a efficient way and absorp the values into an ArrayList ?
    addbatch() method is mainly used for "insert" kind of query .
    and also , it would be bad idea to run "select:" query one by one .
    can you tell whats the best use ?

    Are your queries related to each other, I mean, do you have something like
    select xpto from someTable where someValue = 1
    select xpto from someTable where someValue = 2
    select xpto from someTable where someValue = 3
    If it's something like this you can group
    select xpto from someTable where someValue in(1,2,3)
    If it is not I think there's no other way but running one at a time.
    mleiria

  • Select Query Problem

    Hi Experts,
    I am having a select query in which I am using a variable in the where condition but it is giving error. Please suggest how to use variable in the select query.
    The query I am using is a s below.
    select * from zexc_rec into table it_ZEXC_REC
          where
           LIFNR in S_LIFNR and
          DOCNO in S_DOCNO and
          DOCTYP in doc_typ and
          DATE1 in S_DATE1 and
          MATNR in S_MATNR.
    Here doc_typ is a variable.
    Thanks.

    Rahul,
    use RANGES type variable instead of variable . It acts as a select-options variable. Thn use this variable in SELECT query with IN.
    Eg :
    RANGES r_t510 FOR t510-lgart.
        r_t510-low = '1600'. 
        APPEND r_t510.
        r_t510-low = '3190'. 
        APPEND r_t510.
    Note  : can be use SIGN, OPTIONS properties too in RANGES type.
    More deatils go through on HELP of RANGES
    Rgds,
    Ranjith

  • Time Taking while firing a select Query

    i am unable to access the table "X" in ABC schema
    its taking toooooooooo much time while firing just a select query
    how to resolve it
    "SELECT digital_signing_cert
    FROM X"

    could be due to huge table size,crosscheck this from user_segments view.
    select bytes/1024/1024 "MB" from user_segments where segment_name='X';
    also check database alert log for any error.

  • Select query in method    endmethod

    Hi all,
          I am writing code in a method which is not accepting into table in select query, How to pass data into internal table using select query in method. As per my knowlegde we have to write code using field-symbols. can anybody please help me.
    Thanks in advance.
    Ranjith

    it is possible to do a select into table. in your case the exporting parameter may be defined normal structure. if you want to define the internal table you have to use table types to behave the parameter as Internal table.
    exporting
      e_flight    type sflight_1ab1
    select * from sflight
    into table e_flight
    up to 30 rows.

Maybe you are looking for

  • Office Web App Server 2013: cannot edit word document with own WOPI Server

    Hi all, I tried to build our own WOPI Server to connect to Office Web App Server 2013 SP1. Viewing documents in IE was possible quite easy to achieve. Now it comes to editing. When I try to edit a document, I got a german message "Sie verfügen leider

  • Vendor Number Range Assignment

    Hi All, I have a question... when we create a vendor using XK01 it automatically takes the system generated Vendor number, can you please tell me how can I manually enter a vendor number for a particular vendor. Also is there a way if we can keep bot

  • NI 9237

    Please help us with to setup NI 9237 and NI 9411 with NI cDAQ-9174  to measure the load, torque and angle at the same time. We are using RJ 50 for the connection between load and torque sensors to NI 9237. For the Load cell, we wired positive and neg

  • I can look at one email in hotmail. But when I try to open/read another, nothing happens. If I close and open firefox I can again read only one e-mail.

    I can only look at one e-mail when I open Firefox. In order to read the next e-mail I have to close and open firefox again. This happened with the new version 4.0. I was happy with firefox before, but I am very unhappy now. The new download also said

  • Video(Graphic) Problem

    Hello there. I just bought a lenovo ideaPad n580.Everything looks great till i open youtube and play some video. Than even on the highest  resolution 1080px the video is not good i can see squears(pixels) and the video is not smooth is pixelate. Also