Offset in Select Query

Hi,
Can we use offset in select statement. I was trying to compare the year and month of MBEWH table with the LINV table. MBEWH has seperate fields for year and month but LINV table has a date field.
TYPES:BEGIN OF TY_MBEWH,
        lfgja type lfgja,
        lfmon type lfmon,
      END OF TY_MBEWH.
Data: T_MBEWH TYPE TABLE OF TY_MBEWH,
      WA_MBEWH TYPE TY_MBEWH.
Select MBEWHLFGJA MBEWHLFMON
        INTO TABLE T_MBEWH FROM MBEWH INNER JOIN LINV
       ON MBEWHMATNR = LINVMATNR
       where MBEWHBWKEY = LINVWERKS
             and  MBEWHLFGJA >= *LINVIDATU(4)*
             and  MBEWH~LFMON > LINV.IDATU+4(2).
When I execute the above code Iam getting "Field LINV~IDATU is unknown. It is neither in one of the specified tables nor defined by a DATA statement.
Best Regards
Suresh

Hi Suresh,
  Try it this way:
W_YEAR  = LINV-IDATU+0(4).
W_MONTH = LINV-IDATU+4(2).
Select MBEWH~LFGJA MBEWH~LFMON
INTO TABLE T_MBEWH FROM MBEWH INNER JOIN LINV
ON MBEWH~MATNR EQ LINV~MATNR
where MBEWH~BWKEY EQ LINV~WERKS
and MBEWH~LFGJA GE W_YEAR
and MBEWH~LFMON GT W_MONTH.
With luck,
Pritam.

Similar Messages

  • How to use offset in select query

    Suppose i have data like ssonje     00000001 as a one field in database table . i have to segregate this two data. how should I do this.the first part is of 12 characters and the last is of 10 character long.

    Hi Naveen,
    I am again in trouble, Now the requirement were changed. I am sending you the code which i had implemented.
    Now, the user enter username(ie UNAMED) and document id (ie. TEMPD) and the output should be doucment id, which has been search through database table RFDT , field SRTFD, this field contains both the username and the document id.
    That means: suppose user enters UNAMED as SSONJE and TEMPD as 0000000030, then i want to fier the select query from RFDT on field SRTFD and get only the document id of that user which user enter on input field-UNAMED.
    i had tried but result were not coming.
    please go through the code.
    data:uname type UF05A-UNAMD.
    data:temp type UF05A-TEMPD.
    TYPES: BEGIN OF TEITAB_RFDT,
           SRTFD TYPE RFDT-SRTFD,
           END OF TEITAB_RFDT.
    DATA: ITAB_RFDT TYPE TABLE OF TEITAB_RFDT.
    DATA: WA_RFDT TYPE TEITAB_RFDT.
    DATA: STR(22) TYPE c.
    SELECT-OPTIONS:UNAMED FOR uname,
    TEMPD FOR TEMP.
    UNAMED-option = 'CP'.
    append UNAMED.
    CONCATENATE UNAMED TEMPD INTO STR.
    SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB_RFDT WHERE SRTFD eq str.
    LOOP AT ITAB_RFDT INTO WA_RFDT.
    SPLIT WA_RFDT AT SPACE INTO STR1 STR2.
      WRITE: / STR1,STR2.
    ENDLOOP.
    Please mentioned what is the way to do this.
    Thanks

  • Hibernate - limit and offset in select query

    Hi All
    is there any way to use limit and offset features of mysql in hibernate queries?
    For exmple I have 100 rows in my results. I want to display the results page by page. How can I select rows starting from a particular index (for example from 10 to 20 instead of starting at the first record). The 'setMaxRows()' function can limit the number of results, but how can I specify the offset ? Thanks in advance.
    regards
    boolee

    You could specify the offset with
    query.setFirstResult(offsett);
    The drawback is (at least with DB2) that the whole query will be executed anyway, however you save space on the Java side.

  • Offset problem in select query

    Hi experts,
    I have a select query , in my where condition , comparing fields types are different
    following is my select query
    SELECT spras  prctr  ktext FROM cepct INTO CORRESPONDING FIELDS OF TABLE it_cepct FOR ALL ENTRIES IN it_vbsegd
                                                               WHERE prctr = it_vbsegd-bupla .
    here prctr length = 10
    and bupla length = 4.
    we can give offset after "=" sign, but i want to use on prctr field,  could anybody please give me some idea to achieve this.
    thanks in advance

    Hi,
    created another internal table it_tab to get the result which you wanted.
    DATA : it_cepct TYPE TABLE OF cepct,
               it_vbsegd TYPE TABLE OF vbsegd,
               wa_vbsegd type vbsegd.
    TYPES : BEGIN OF ty_tab,
             bupla(10),
             END OF ty_tab.
             DATA : it_tab TYPE TABLE OF ty_tab,
                    lv_bupla(10).
       select * UP TO 2 ROWS  FROM vbsegd INTO TABLE it_vbsegd.
       loop at it_vbsegd INTO wa_vbsegd.
         UNPACK wa_vbsegd-bupla to lv_bupla.
         append lv_bupla to it_tab.
         CLEAR : lv_bupla,wa_vbsegd.
       ENDLOOP.
       SELECT spras  prctr  ktext FROM cepct INTO CORRESPONDING FIELDS OF TABLE it_cepct FOR ALL ENTRIES IN it_tab
                                                                WHERE prctr = it_tab-bupla.

  • Please validate my select query with offset

    Could you please  validate my select query below :
    AND   kadky+0(4) IN s_gjahr is correct ?
    =====================================
    SELECT-options:
    s_gjahr FOR ckhs-gjahr NO-EXTENSION NO INTERVALS OBLIGATORY  DEFAULT sy-datum+0(4).
    SELECT bzobj
             kalnr
             kalka
             kadky
             tvers
             bwvar
             kkzma
             matnr
             werks
             feh_sta
        FROM keko
        INTO TABLE i_keko
        FOR ALL ENTRIES IN i_mackw
       WHERE  matnr = i_mackw-matnr
        AND   werks = i_mackw-werks
        AND   kadky+0(4) IN s_gjahr       <==
        AND  ( feh_sta = 'FR'
        OR     feh_sta = 'VO' )

    Hi,
    Use the below code.
    ranges: r_gjahr for ckhs-gjahr.
          r_gjahr-low = s_gjahr-low.
          r_gjahr-sign = 'I'.
          r_gjahr-option = 'EQ'.
          append r_gjahr.
          r_gjahr-low = s_gjahr-low - 1.
          r_gjahr-sign = 'I'.
          r_gjahr-option = 'EQ'.
          append r_gjahr.     
    SELECT bzobj
    kalnr
    kalka
    kadky
    tvers
    bwvar
    kkzma
    matnr
    werks
    feh_sta
    FROM keko
    INTO TABLE i_keko
    FOR ALL ENTRIES IN i_mackw
    WHERE matnr = i_mackw-matnr
    AND werks = i_mackw-werks
    AND ( feh_sta = 'FR'
    OR feh_sta = 'VO' ).
    if sy-subrc = 0.
    delete i_keko where not kadky+0(4) IN r_gjahr.
    endif.
    Regards,
    Kumar Bandanadham
    Edited by: Velangini Showry Maria Kumar Bandanadham on May 28, 2009 7:37 AM

  • Select  query

    hi all,
    in the selection screen i have a posting date from MKPF Table but date should display only month and year  as
    DATE : 1/2008      TO   12/2008
    I have written as below using offset.
    select-options:  l_date for mkpf-budat+2(6).
    but how to get the values from MKPF table using select query.
    in below query budat+2(6) is not working how can i compare and get the values based on month and year.
    select mblnr
                  mjahr
                  bldat
                  budat
                  into table gt_mkpf
                  from mkpf
                  for all entries in gt_mseg
                  where mblnr  eq gt_mseg-mblnr
                  and   mjahr  eq gt_mseg-mjahr
                  and   budat+2(6)  in l_date.
    please , thanks in advance

    HI,
    Try this code
    DATE : 1/2008 TO 12/2008
    select-options: l_date for mkpf-budat+2(6). " value foramt will be YYYYMM
    Ranges : r_budat FOR mkpf-budat.
    Loop at l_date.
    r_budat-sign = l_date-sign.
    r_budat-option = l_date-option.
    concatenate l_date-low '01' into r_budat-low.
    concatenate l_date-high '01' into r_budat-high.
    CALL FUNCTION 'LAST_DAY_OF_MONTHS'                       
        EXPORTING
          day_in            = r_budat-high
        IMPORTING
          last_day_of_month = r_budat-high
       EXCEPTIONS
          day_in_no_date    = 1
          OTHERS            = 2.
    Append r_budat.
    ENDloop.
    select mblnr
    mjahr
    bldat
    budat
    into table gt_mkpf
    from mkpf
    for all entries in gt_mseg
    where mblnr eq gt_mseg-mblnr
    and mjahr eq gt_mseg-mjahr
    and budat in r_budat.

  • Select Query Using Two Tables

    Friends,
       I need to select some fields from two different tables which doesnot contain any field in common.How to Get this using a select query..
       But there is a field X in table 1 which is equalient to eight char of another field y in table 2.I tried using offset but it is giving error.
    Thanks in Advance
    Regards
    Yamini

    Hello,
    You can use a subquery
    SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                        WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
      WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID,
               WA_SFLIGHT-FLDATE.
    ENDSELECT.
    or simply query the first table and then the second table with select endselect.
    select * from table a.
       select * from table b into output_table
                     where b-field1 eq a-field2.
    endselect.
    or read the data into one internal table loop at it and then query the other table.
    Regards,
    Shekhar Kulkarni

  • 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

  • Oracle 11g :SELECT query blocked..??

    Hi Experts,
    could you please explain why the below SQL query is blocked?
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=469 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=367 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    I am scratching my head without any solution when I had a look at the db today. Thanks in advance for your help.
    Regards,
    Boris
    Edited by: user12075620 on Dec 4, 2012 8:58 AM

    The SELECT statement is not blocking the UPDATE. As I said in the previous reply, the string that this query produces does not match the logic.
    This query is (at least on the surface) correctly identifying that session 1 is blocking session 2. Session 1 holds some lock that session 2 is waiting on. So far, so good. Since session 2 is waiting on the lock, we can easily enough see what session 2 is running (the UPDATE statement). But since session 1 is not blocked, it is potentially off running a ton of other SQL statements (or no SQL statement at all). The query is looking to see what session 1 is running currently. It has no way of determining what session 1 ran at some point in the past to acquire the lock in the first place.
    Going back to my KING example,
    At noon, session 1 runs
    UPDATE emp
       SET sal = sal * 2
    WHERE ename = 'KING'Session 1 now has a lock on the KING row in the EMP table. But session 1 neither commits nor rolls back, it is still in a transaction. Session 1 might not have any more activity for a long time-- the user might go off to lunch, for example (obviously, applications should not be designed to allow users to maintain open transactions indefinitely, but not all applications are designed correctly). Or it might start running other queries. Let's say that session 1 now runs a query that is going to go for an hour
    SELECT *
      FROM giant_view_with_lots_of_computationsNow, at 12:45, session 2 comes in and runs
    UPDATE emp
       SET bonus = 100
    WHERE ename = 'KING'Session 2 is blocked. Session 2 is running the UPDATE statement. Session 1 still holds the lock but it is running some completely unrelated SQL statement.
    If we run the query you posted, the query will correctly report that session 1 is running the query against the GIANT_VIEW_WITH_LOTS_OF_COMPUTATIONS but incorrectly imply that this SELECT query is the source of the lock. It is not. It simply happens to be the query that the session that does hold the lock happens to be executing at the current moment (why the application seems to be running a lot of queries that select a constant from dual is a separate question).
    Justin

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Select query differences between oracle 9 and oracle 8.

    Hi,
    I have a problem using the select query between oracle 7 and oracle 9i I don't have the same result :
    ex:
    With oracle7
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP 'CHAMP
    champ1 champ2
    With Oracle 9
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP1' 'CHAMP2'
    champ1 champ2
    So Can someone tell me how to solve this problem ? Is there a parameter in oracle 9 to set?
    Thanx.

    Whenever you are posting anything over internet forums like this - you should be very careful about not just posting the details which requires to solve the problem - also should be sensible about your question.
    This is not at all desired when you are posting such question. It may be because - you may not well aware of the fact.
    My suggestion is -> First Go through the basics Of SQL in general.
    Then go for any specific product like Oracle/ SQL Server/ Sybase etc.
    And, finally learn the advanced commands of that DB.
    You asked it - may be you thought the difference in output in terms of lines. But, that is not your actual output. That is the graphical display part only.
    Anyway,
    You can get the quite familier output by first type the following command ->
    set lin 310Regards.
    Satyaki De.

  • Select Query resulting in Scientific Notation

    Hello all,
    I am running a Select query through a batch file that extracts data from an Oracle database. Several of the fields that I am extracting from contain numbers that are up to 38 digits long. When I extract the data, it converts the numbers into scientific notation and it is important for me to have the entire field. Is there something I can change to my query that will pull the data in its entire form? This is what I'm running now:
    select * FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy'
    I apologize in advance if this has been answered already.
    Thanks!

    >
    When the extractor finishes, it returns the data into a flat file.
    don't quite understand the TO_CHAR function. Does this function mean I need to say something like this: select "TO_CHAR('column name', 99999999999999999999999999999999999999" FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy')
    >
    Yes- if the tool you use to extract the data (your 'extractor') is converting the numeric data to a string then it is responsible for creating the string in the proper format. If the number is an integer that can have as many digits as you have '9's in your sample format string then that is what you need to do.
    Here is how sql*plus (Oracle's tool) will display the data using default settings
    SQL> select 12345678901234567890123456789012345678 no_format,
      2  to_char(12345678901234567890123456789012345678, '99999999999999999999999999
    999999999999') with_format
      3   from dual;
    NO_FORMAT WITH_FORMAT
    1.2346E+37  12345678901234567890123456789012345678
    SQL>
    ----- TOAD will display something similiar but the default uses more decimal digits in the scientific notation data
    NO_FORMAT,WITH_FORMAT
    1.23456789012346E37, 12345678901234567890123456789012345678You can either format the numeric data in the query using TO_CHAR or the 'extractor' can do it when it converts the data to a string.

  • Select-options in SELECT query - syntax error

    Hi all,
      I get the error below when I try to use the select options in a SELECT query . Please help me.
    "The IN operator with "SO_AWART" is followed neither by an internal
    table nor by a value list."
    The code i have used(Logical database  PNP is used):
    TABLES: pernr,
            catsdb.
    INCLUDE ztime_cwtr_top.    " global Data
    INCLUDE ztime_cwtr_f01.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
    SELECT-OPTIONS SO_AWART FOR CATSDB-AWART.
    PARAMETERS P_THRES TYPE I.
    SELECTION-SCREEN END OF BLOCK B1.
    Get data from CATSDB table. Workdates within the date interval are considered.
      SELECT pernr workdate awart catsquantity beguz enduz status
      FROM catsdb
      INTO TABLE it_catsdb
      WHERE pernr  = pernr-pernr    AND
           workdate GE pn-begda     AND
           workdate LE pn-endda     AND
           status   IN ('20', '30') AND
           awart    IN  so_awart .
          awart    IN ('1100', '1137', '1138', '1139', '1140',
                      '1147', '1148', '1149', '1157', '2003' ).
    when I give the values directly i do not get any syntax error, but when I use select options in the where condition I get the syntax error.
    I have tried different options like using only the select-options in the where condition.
    Thanks in advance.....
    Madhu

    Solved.
    Code with syntax error:
    include z...top .
    include z...fo1.
    select-options: xxxxxxx
    Code  with no syntax error:
    select-options: xxxxxxx
    include z...top .
    include z...fo1.
    Thanks for all your help,
    Madhu

  • Query in Select query operation

    Please excuse me for posting this again.
    I'm stuck up with this for 3 days. Lenghty post pls do read and help me.
    How is the select query going to be changed in the SAP so that the original database behind it understands it. I want to know the operation of IN operation in where clause where in we can use ranges.
    I'm asking this because I'm facing a problem using Native SQL.
    Query is like this:
    EXEC SQl.
    OPEN C1 for
    SELECT field1 from table@domain where field2 IN :ABAP_VAR.
    ENDEXEC.
    EXEC SQL.
    FETCH C1 NEXT INTO :VAR1 , :VAR2
    ENDEXEC.
    Oracle usually recognises this statement IN ( '2222' , '3658' , '6895' )
    But here this field that is build dynamically like this is not recognising them as seperate fileds but instead it is taking them as a single string and not selecting anything.
    But if a single value is passed it is fetching the data into the cursor. And the code is working fine.
    Any help in this is highly appreciable.

    "if a in r_range" is is effectively: does the value held in 'a' comply with the values held in range 'r_range'. Ranges can hold NE, patterns etc so this can get quite complex.
    You can see that it is very different from the SQL type IN.
    If your range hold several values you could unstrip it into a string varaible so that it ended up having a value something like: ( '2222' , '3658' , '6895' ). Not sure if you need the '(' but it would be something like this:
    eg,
    assuming your range is simple and only holds 'I' and 'EQ' values:
    data v_string type string.
    loop at r_range.
    concatenate v_string '@''' r_range-low  '''@' into v_string.
    endloop.
    REPLACE
      ALL OCCURRENCES OF '@'
      IN v_string
      WITH ' '.
    Then you can use:
    SELECT field1 from table@domain where field2 IN :v_string.

  • SELECt query in UNiX environment

    Iam using hp unix with oracle 11g
    when i try to spool 26 lack records it is giving me error
    " There is not enough memory available now.
    O/S Message: Broken pipe"
    is there is any other way SQL commands, we can limit the SELECT query to spool specific number of times other than using
    FOR LOOP.. with LIMIT cluase

    logdata=`${SQLPLUS} -S username/password<< EOF
                        SET ECHO OFF
                        SET LINESIZE 2000
                        SET NEWPAGE 0
                        SET SPACE 0
                        SET PAGESIZE 0
                        SET FEEDBACK OFF
                        SET HEADING OFF
                        SET TRIMSPOOL ON
                        SET TAB OFF
                        set autoprint on               
                        set serveroutput on
                        set spool on
                        spool ${SPOOL_FILE}     
                        set termout off
                   WHENEVER SQLERROR EXIT SQL.SQLCODE
                   whenever oserror exit 1;
                        $GetQuery ==> there come's the SELECT statement which spool's 25 lakh records.
                        spool off
                   EXIT
                        END`
    While spooling records it throws the error
    There is not enough memory available now.
    O/S Message: Broken pipe
    i want u use spooling instead of using util_file to write each and every rows in a file
    Edited by: user9080289 on Apr 29, 2010 5:04 AM

Maybe you are looking for