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

Similar Messages

  • 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.

  • Dynamic field in select query

    Hi Team,
    I have to select dynamic fields from database table GLT0.
    This depends on period value given on screen.
    If period is 01 then fields will be hsl01.
    If period is 02 then fields will be hsl01 and hsl02.
    If period is 03 then fields will be hsl01,hsl02 and hsl03 .
    so on...till 12..
    My code is throwing exception at select query.
    "Error in module RSQL of the database interface."
    My code :
    *"      Type declaration to store field name as per given period
    TYPES : BEGIN OF y_fieldname        ,
               fieldname(10)  TYPE c    ,
             END OF y_fieldname         .
    data  t_fieldname  TYPE  STANDARD TABLE OF y_fieldname   .
      DO p_monat TIMES.
         clear w_count .
          MOVE sy-index TO w_count
          IF sy-index LE c_9.
            CONCATENATE c_hsl
                        c_0
                        w_count
            INTO      e_fieldname-fieldname.
            APPEND e_fieldname TO t_fieldname.
          ELSE.
            CONCATENATE c_hsl
                        w_count
            INTO     e_fieldname-fieldname.
            APPEND e_fieldname TO t_fieldname.
          ENDIF.
        ENDDO.
      Get Local Currency Amounts
      from table glt0 depending on period
        SELECT (t_fieldname)
          FROM glt0
          INTO TABLE t_glto_with_saknr
          FOR ALL ENTRIES IN t_bukrs
         WHERE rldnr EQ c_00
           AND rrcty EQ c_0
           AND rvers EQ c_001
           AND bukrs EQ t_bukrs-bukrs
           AND ryear EQ p_gjahr
           AND racct IN r_saknr.
    Please guide me.
    Thanking u in advance.
    Sangeeta Verma

    Hi Asik,
    I m selecting all fields now as suggestd by u so in one record i have hsl01 to hsl12.
    I have to calculate balance into e_glt0_bal-bal .This balance is summation of e_glt0_bal-hsl01 till  e_glt0_bal-hsl12 (depending on monat).
    I m using logic in process then
    my code now :
    data:    w_monat_bal type string  .
              DO p_monat TIMES.
                MOVE c_01 TO w_count .
                CONCATENATE 'e_glt0_bal-hsl'
                             w_count
                       INTO w_monat_bal.
                ASSIGN w_monat_bal TO <fs_monat_bal>.
                e_glt0_bal-bal = e_glt0_bal-bal + <fs_monat_bal>.
                w_count = w_count + c_01.
              ENDDO.
    But <fs_monat_bal> can not be added.
    Giving exception :
    Unable to interpret "e_glt0_bal-hsl01" as a number.
    If I do <fs_monat_bal> type GLT0-hslvt instead to type any
    Then assigning from w_monat_bal  is not possible.

  • 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.

  • 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

  • Dynamic coulmn in select query

    Hello,
    This is the table I have
    Country, ITEM,COST
    INDIA A 100
    THAILANDB 250
    INDIA B 200
    now in my select I would need as
    if item is A then cost column should be displayed as COST_test1
    if item is B then cost should be cost_test 2... something like this down
    Country, ITEM, COST_test1 , COST_TEST2
    INDIA A 100
    INDIA B 200
    THAILAND B 250
    Any help is appreciated.

    SQL> -- generating sample data:
    SQL> with t as (
      2  select 'INDIA' country, 'A' item, 100 cost from dual union all
      3  select 'THAILAND', 'B', 250 from dual union all
      4  select 'INDIA', 'B', 200 from dual
      5  )
      6  --
      7  -- actual query:
      8  --
      9  select country
    10  ,      item
    11  ,      case when item = 'A' then cost end cost_test1
    12  ,      case when item = 'B' then cost end cost_test2
    13  from   t
    14  order by country;
    COUNTRY  I COST_TEST1 COST_TEST2
    INDIA    A        100
    INDIA    B                   200
    THAILAND B                   250
    3 rows selected.Edited by: hoek on Jul 1, 2011 5:31 PM misread post, fixed that
    Edited by: hoek on Jul 1, 2011 5:33 PM Oh dear, misread even twice... time to call it a weekend

  • 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

  • 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

  • Dynamic Select query is failing with error "Invalid Table Name"

    OPEN rc FOR 'SELECT count(*) from :s' USING tab_name;
    fetch rc into rec_count;
    CLOSE rc;
    my requirement is to build dynamic select query to retrieve the total count of rows in each table ( variable tab_name contains the table_name )
    But I am getting stuck by this errror, not sure if there is any alternative !
    ORA-00903: invalid table name
    ORA-06512: at line 43

    OPEN rc FOR 'SELECT count(*) from '||tab_name;
    fetch rc into rec_count;
    CLOSE rc;
    -- This will work
    1. Create a sql statement.
    2. Open ref cursor for that statement.

  • Absolute dynamic select query with dynamic join and where

    Has anyone ever tried creating an absolutely dynamic SELECT query with dynamic Join and Where conditions.
    I have a requirement of creating such a query in an Utility Class, and i have written the code. But its throwing my sysntax errors.
    Please let me know where am I going wrong OR is it really possible to create such a dynamic Query??
        SELECT (FIELDS) INTO TABLE IT_TABLES
          FROM ( (ME->TABLE1)  inner join ( me->table2 )
          on ( on_condition ) )
          WHERE (me->where_fields).
    Ags.

    It worked for me in a following way:
    select * into corresponding fields of table <result_table>
            from (join_string)
            where (l_where).
    Where the contents of join_string were dynamically build using concatenation. So it will be something like
    concatenate ME->TABLE1 'as a INNER JOIN' me->table2 'as b ON (' into join_string separated by space.
    <...>
    add here matching/reference colums, something like
    concatenate 'a~' me->TABLE1_JOIN_COL into temp1.
    concatenate 'b~' me->TABLE2_JOIN_COL into temp2.
    concatenate join_string temp1 '=' temp2 into join_string separated by space.
    <...>
    concatenate join_string ')' into join_string separated by space.
    And then use similar approach for l_where variable.

  • Select query with variable no of conditions

    Hi,
    I want to write a select query such that the conditions mentioned under WHERE clause can be variable .like :
    Select * from TABLE where F1 = var1 and F2 = var2 and F3 = var3.
    Now on the basis of some conditons the equations in where clause should be used.Say condition is variable value >6.
    Now in this case ,if
    var1 =7 var2 =3 var3 = 8 then the query shud behave like
    select * from TABLE where F1 = var1 and F3 = var3
    if :
    var1 =3 var2 = 4 var3 =3 the :
    select * from TABLE
    But only one query is to be wrote that satisfies all of these
    thanx
    Edited by: aachal on Feb 4, 2011 11:36 AM

    Hi Aachal,
    Use Dynamic select statement.
    Ex:
    data : lv_wherecond type string.
    Select * from TABLE where ( lv_wherecond ).
    Before Select stmt, code as follows.
    if var1 > 6.
           if lv_wherecond is initial.
              F1 = var1.
           else.
              concatenate lv_wherecond ' and F1 = var1'  into lv_wherecond.
           endif.
    elseif var 2 > 6.
            if lv_wherecond is initial.
               F2 = var2
            else.
               concatenate lv_wherecond ' and F2 = var2'  into lv_wherecond.
           endif.
    elseif var3 > 6.
          same as above ..
    endif.
    Hope it helps..
    Regards,
    Sravan Guduru.

  • Dynamic filtering with BEx query variables in WebI 3.1

    Hi experts.
    Can anybody help me ?
    1) I use BEx query variables in WebI 3.1 .  But i can't understand how to order fields of selection screen in WebI reports
    2) How can i use Dynamic filtering with BEx query variables in WebI 3.1 ?
        It's need that  list of second field on selection screen will be accoding to result of selection first field on selection screen and so on .
        Need i use BEx user-exit variables ?
    Thank you

    Hi,
    1)  Variable sequence isn't respected in XI3.1 - and can't be modified in OLAP.unv  (this enhancement exists in 4.0 )
    2)  Dynamic filtering?  Yes, Exit routines are the best way to go for this.
    Regards,
    H

  • How to pass the feild names of a select query dynamically?

    Hi
    How can we pass the feilds names in select query dynamically?
    For example in my selection screen i wil be giving the table name, and feilds in that table.....
    those feilds should be taken in my select query...
    instead of
    PARAMETERS : tab_name TYPE ddobjname .
      SELECT *
        FROM (tab_name)
        INTO TABLE <newtab>
       UP TO 25 ROWS.
    parametrs : feild1 like-------
                     feild2----
    i need select feild1 feild2 feild3    FROM (tab_name)
        INTO TABLE <newtab>
       UP TO 25 ROWS.

    by the way, contrary to popular belief there is no performance problem when using
    SELECT * FROM dbtab INTO CORRESPONDING FIELDS OF TABLE itab WHERE ...
    as long as the structure of itab contains only the required fields.
    I ran some benchmarks against this and above construct is maybe 0.1% slower (Oracle 10g) than a
    SELECT f1 f2 f3 f4 ... FROM dbtab INTO TABLE itab WHERE ...
    but is saves you from maintaining a potentially very long field list in your code. So when you need additional fields later on, you just add them to the DDIC structure or type definition and that's it.
    Maybe something you want to factor in here.
    Cheers
    Thomas

  • Dynamic variable Time for Select

    Hi,
    I try to develop some scripts but always I have the same problem , when I try to put in a Select instruction the variable Time, it doesn´t work correctly (for example):
    *SELECT(%example%,"ID","TIME","[ID]='%TIME_SET%' ")
    It doesn´t read correctly the variable Time_Set.
    Have you got any idea to try to do selects using dynamic variable?
    Thanks for all.

    Hi,
    Dynamic variables like %TIME_SET% do not interact very well with the compiled default logic (LGX files) when it is run after a data send. If you look at the Default.LGX file, you will notice that your *SELECT statement does not appear there because that *SELECT statement has already been compiled. That is why the logic works when it is run via the debugger (because the LGF file is getting executed at run time) and it does not work when it is run via a data send (because the LGX is being executed).
    What you will need to do is:
    1. Create a another logic file (for example: Calculation1.LGF) and copy the text from the Default.LGF to this new logic file.
    2.  Place the following text in the Default.LGF file:
    *RUNLOGIC
    *LOGIC=Calculation1.LGF
    *ENDRUNLOGIC
    3. Validate and save the Default.LGF file
    Now try running the logic after a data send and see if that works.
    Good luck,
    John

  • How to create a Type Object with Dynamic select query columns in a Function

    Hi Every One,
    I'm trying to figure out how to write a piplined function that executes a dynamic select query and construct a Type Object in order to assigned it to the pipe row.
    I have tried by
    SELECT a.DB_QUERY INTO actual_query FROM mytable a WHERE a.country_code = 'US';
    c :=DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(c,actual_query,DBMS_SQL.NATIVE);
    l_status := DBMS_SQL.EXECUTE(c);
    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.DEFINE_COLUMN(c,j,v_val,2000);
    END LOOP;
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.COLUMN_VALUE(c,j,v_val);
    END LOOP;
    But got stuck, how to iterate the values and assign to a Type Object from the cursor. Can any one guide me how to do the process.
    Thanks,
    mallikj2

    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

  • Flash Crashing Browsers on Macbook Air

    A couple of days ago my bowsers started crashing with the message that a Flash Plugin has cuased an error. It happens on both Safari and FireFox. I have tried the Flash uninstaller. but when I reinstall the same thing happens. I have tried uninstalli

  • 10.5.5 and DPP

    Hi Maybe this is the wrong forum but i wont know until i post the question.... ok here go's... I am a professional architectural photographer and use all Canon equipment. I shoot in RAW format and up until a couple of weeks ago processed all my image

  • How do I get Pages to recognize the Norwegian language in spell-check?

    I'm Ameican and I got my beautiful MacBook air with me in Norway.  I use Pages to write notes and do homework, but it doesn't have Norwegian as a language amunst the spellcheck dictionary.  It has Swedish and Danish ofcours, but it's not the same.  I

  • Gl_interface help

    I need to get GL data to oracle financials 11.5.5 from an billing system AR the data is the GURFEED table. Can any one help advice how to get that data to the gl_interface table use a adaptor or write a pl/sql program I have not done this. Thanks in

  • How to use hamachi to play LAN games?

    We (group of 7 friends) played blur by connecting to same wi-fi. What we usually do is create a wi-fi hotspot on a mobile (keeping the data pack off, so no internet access, this is what I like to call offline LAN, all friends connected to the same wi