Why this select statement is failing

Hi to all experts.
Im not able to understand why this select statement is not fetching the record with this parameters. When i give the same parameters in se11 table t512w.. It has one record, but here the sy-subrc Value is 4.
select  * from t512w where molga EQ '15'
         and lgart in g_lgart01
       and endda gt pn-endda
   and begda lt pn-endda.

Dear Mohamed,
This Select Statement is bound to Fail. When you are doing a select * from T512W, you intend to get a single record from T512W into the work area T512W which you have declared using TABLES statement. So, here you need to use Select single instead of Select *
If you want more data, then you declare an internal table, say gt_t512w type standard table of t512w and use "
Select from T512W
Into TABLE GT_T512W
WHERE ........
Hope this solves your problem.
Regards,
Amit Sharma

Similar Messages

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • In how many ways we can filter this select statement to improve performance

    Hi Experts,
    This select statement taking 2.5 hrs in production, Can we filter the where condition, to improve the performance.Plz suggest with coding ASAP.
    select * from dfkkop into  table t_dfkkop
               where   vtref   like 'EPC%'        and
                   ( ( augbd      =  '00000000'   and
                       xragl      = 'X' )
                               or
                     ( augbd between w_clrfr and  w_clrto )  )  and
                       augrd      ne '03'         and
                       zwage_type in s_wtype .
    Regards,
    Sam.

    if it really takes 2.5 hours, try the followingtry to run the SQL trace and
    select *
              into table t_dfkkop
              from dfkkop
              where vtref like 'EPC%'
              and augbd = '00000000' and xragl
             and augrd ne '03'
             and zwage_type in s_wtype .
    select *
              appending table t_dfkkop
              from dfkkop
              where vtref like 'EPC%'
             and augbd between w_clrfr and w_clrto 
             and augrd ne '03'
             and zwage_type in s_wtype .
    Do a DESCRIBE TABLE after the first SELECT and after the second,
    or run an SQL Trace.
    What is time needed for both parts, how many records come back, which index is used.
    Siegfried

  • How to optimize this select statement  its a simple select....

    how to optimize this select statement  as the records in earlier table is abt i million
    and this simplet select statement is not executing and taking lot of time
      SELECT  guid  
                    stcts      
      INTO table gt_corcts
      FROM   corcts
      FOR all entries in gt_mege
      WHERE  /sapsll/corcts~stcts = gt_mege-ctsex
      and /sapsll/corcts~guid_pobj = gt_Sagmeld-guid_pobj.
    regards
    Arora

    Hi Arora,
    Using Package size is very simple and you can avoid the time out and as well as the problem because of memory.  Some time if you have too many records in the internal table, then you will get a short dump called TSV_TNEW_PAGE_ALLOC_FAILED.
    Below is the sample code.
    DATA p_size = 50000
    SELECT field1 field2 field3
       INTO TABLE itab1 PACKAGE SIZE p_size
       FROM dtab
       WHERE <condition>
    Other logic or process on the internal table itab1
    FREE itab1.
    ENDSELECT.
    Here the only problem is you have to put the ENDSELECT.
    How it works
    In the first select it will select 50000 records ( or the p_size you gave).  That will be in the internal table itab1.
    In the second select it will clear the 50000 records already there and append next 50000 records from the database table.
    So care should be taken to do all the logic or process with in select and endselect.
    Some ABAP standards may not allow you to use select-endselect.  But this is the best way to handle huge data without short dumps and memory related problems. 
    I am using this approach.  My data is much more huge than yours.  At an average of atleast 5 millions records per select.
    Good luck and hope this help you.
    Regards,
    Kasthuri Rangan Srinivasan

  • Regarding this select statement

    hi,
    i am not getting value i write like this select statement
    plz check error in this code.
    TABLES: VBAK,
    vbrk.
    TYPES: BEGIN OF TYP_VBAK,
          VBELN TYPE VBELN_VA,
          VBTYP TYPE VBTYP,
          VGBEL TYPE VGBEL,
          END OF TYP_VBAK,
           BEGIN OF TYP_VBRK,
              VBELN TYPE VBELN,
              WAERK TYPE WAERK,
              VKORG TYPE VKORG,
              KNUMV TYPE KNUMV ,
              FKDAT TYPE FKDAT,
              LAND1 TYPE LLAND,
              NETWR TYPE NETWR,
              KUNRG TYPE KUNRG,
              EXNUM TYPE EXNUM,
              MWSBK TYPE MWSBP,
              END OF TYP_VBRK.
    DATA: GT_VBAK TYPE TABLE OF TYP_VBAK,
          IT_VBRK TYPE standard TABLE OF TYP_VBRK WITH HEADER LINE.
         LS_VBRK TYPE TYP_VBRK,
      SELECT VBELN
             WAERK
             VKORG
             KNUMV
             FKDAT
             LAND1
             NETWR
             KUNRG
             EXNUM
             FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_VBRK
             WHERE VBELN = '0090060045'.

    Check from SE16 whether vbeln = 0090060045 is present in VBRK or not.
    Regards,
    Joy.

  • Why would this select statement give an error?

    *LOOKUP Z_HELPER
    *DIM TGT1 : ACCOUNT="AA_1070100"
    *DIM CATEGORY="ACTUAL"
    *DIM TIME="2011.JAN"
    *ENDLOOKUP
    *SELECT(%TGTDEST2%, "[ID]", TARGETDESTINATION, "[UNIQUEIDENTIFIER]"=LOOKUP(TGT))
    UniqueIdentifier is a property of Targetdestination dimension. Here is the error its giving:
    Validation status of executable file: Failed
    - Unclosed quotation mark after the character string '=LOOKUP(TGT'. in:select [ID] from mbrTARGETDESTINATION where [UNIQUEIDENTIFIER]"=LOOKUP(TGT
    Validation status of syntax: Failed
    - Invalid syntax found; see statements in red

    Nilanjan, I changed TGT to TGT1, still same thing.  Here is the big picture outcome I am trying to achieve.
    Reporting App
    Entity   Costcenter    Shipto   Time          Category  Account    Signed data
    ABC        CO1             USA    2011.jan      Actual     ACT123       200
    So data is coming in like this, the business wants to set up rules such as.....when Costcenter is CO1 AND Shipto is USA AND Entity is ABC....Change the shipto from USA to INDIA. These rules have to be able to be updated by a business user, So I cant hardcode these rules. My manager doesnt want to use Stored procedures, so here is what I did....
    Z_Helper App(Non reporting App)
    Entity Costcenter Shipto   signeddata (other required dimensions are just dummy values)
    ABC     CO1            USA       9
    Now how does 9 get linked to INDIA? I created a new dimension called TARGETDESTINATION. it has ID(which is nothing but shipto country values), and a property called UNIQUEIDENTIFIER. Unique Identifier basically just assigned a unique value to that shiptocountry member row.
    So now I need to write a script logic in reporting app that will look up signed data of 9 in this example, and I was thinking use a select statement to pull INDIA from TARGETDESTINATION dimension.
    Let me know if you have any suggestions. thanks.

  • Why am I getting an error in this Select statement ?

    Any reason why this SQL string does not work on Oracle ?
    SELECT * From kestjori.vatnshaed_web WHERE TIEINS = '1' AND TIDTIM BETWEEN To_Date('01.01.2000') AND To_Date('27.10.2000');
    TIEINS is of the datatype NUMBER(3)
    TIDTIM is of the datatype DATE
    I am getting this error :
    SQLException: [ORACLE][ODBC Oracle Driver][Oracle OCI] ORA-00911: invalid character
    With thanks in advance,
    Oskar Jensson

    i think there is one exact problem in sql and other is optional.
    1. u write field
    TIEINS is of the datatype NUMBER(3)
    but in query in where part u write
    where TIEINS = '1'
    so problem is of data type.
    second optional problem can be removed by given date format in to_Date() function.
    like To_Date('27.10.2000','dd.mm.yyyy')
    i hope it will help u
    bye
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Oskar Jensson ([email protected]):
    Any reason why this SQL string does not work on Oracle ?
    SELECT * From kestjori.vatnshaed_web WHERE TIEINS = '1' AND TIDTIM BETWEEN To_Date('01.01.2000') AND To_Date('27.10.2000');
    TIEINS is of the datatype NUMBER(3)
    TIDTIM is of the datatype DATE
    I am getting this error :
    SQLException: [ORACLE][ODBC Oracle Driver][Oracle OCI] ORA-00911: invalid character
    With thanks in advance,
    Oskar Jensson<HR></BLOCKQUOTE>
    null

  • Getting error while executing this select statement

    Hi All,
    I am new to this community.
    I am getting error whie compiling the below code. Its telling 'Text' is invalid identifier. Also i want to know how can we obtain 'parseable' version of the below query?
    my basic intention is to create a trigger header through a select statement and show it the complete text as a single column..
    select text from
    (select 'CREATE OR REPLACE TRIGGER '||SUBSTR(column_name,2,4)||'aud
    AFTER INSERT
    OR UPDATE
    OF '||column_name||',
    OR DELETE ON '||table_name||'
    FOR EACH ROW'
    FROM(SELECT lower(REPLACE(column_name,'O_','')) column_name , /*changing O to O_*/
    lower(replace(t.table_name,'_A_','_')) table_name,
    lower(t.table_name) table_name1,
    c.column_id
    FROM all_tab_columns c,
    (SELECT object_name table_name
    FROM all_objects
    WHERE object_name LIKE '%/_A/_%' ESCAPE '/') t
    WHERE c.table_name(+) = t.table_name
    AND SUBSTR(column_name(+),1,2) = 'O_'))

    thanks prathamesh. it solved the problem. i have one more question.
    as of now it creates single create trigger statement for each column on a table.
    example:
    CREATE OR REPLACE TRIGGER ust_aud
    AFTER INSERT
    OR UPDATE
    OF cust_id,
    OR DELETE ON characteristic_t
    FOR EACH ROW
    however, i want to create trigger for all columns in a single statement. can you please help me how to do it?
    basically want to 'CREATE TRIGGER' for all columns in a table. i am finding difficult how to change my query to suit this!!
    i am pasting my original query again for your reference. pls advise...
    example:
    CREATE OR REPLACE TRIGGER ust_aud
    AFTER INSERT
    OR UPDATE
    OF cust_id,
    fixed_item_val,
    copy_item_val,
    rgn_id,
    txn_id,
    OR DELETE ON characteristic_t
    FOR EACH ROW
    ORIGINAL QUERY
    select text from
    (select 'CREATE OR REPLACE TRIGGER '||SUBSTR(column_name,2,4)||'aud
    AFTER INSERT
    OR UPDATE
    OF '||column_name||',
    OR DELETE ON '||table_name||'
    FOR EACH ROW' text
    FROM(SELECT lower(REPLACE(column_name,'O_','')) column_name , /*changing O to O_*/
    lower(replace(t.table_name,'_A_','_')) table_name,
    lower(t.table_name) table_name1,
    c.column_id
    FROM all_tab_columns c,
    (SELECT object_name table_name
    FROM all_objects
    WHERE object_name LIKE '%/_A/_%' ESCAPE '/') t
    WHERE c.table_name(+) = t.table_name
    AND SUBSTR(column_name(+),1,2) = 'O_'))

  • How to convert this select statement into update

    Hai All
    I have two table Namely Daily_attend , Train_mast
    Daily_attend Consist Of fields are Train_mast consist Of fields are
    Name varchar Train no var
    Empcode Num T_date date
    Intime Date Train_name var
    Outtime date Late_hrs var
    IND_IN Number
    IDE_OUT Number
    Attend_date date
    I need to update IDE_IN In Daily_attend table Depend upon late_hrs in the Train_mast table
    I have got Through in select statement This is my select statement
    select to_number(TO_DATE(TO_CHAR(Intime,'DD-MON-YYYY')||' '||
    TO_CHAR(0815,'0000'),'DD-MON-YYYY HH24:MI')+late_hrs/(24*60)-intime
    ) * 24*60 from dail_Att,train_mast;
    How can i convert it to update
    Any help is highly appricateable
    Thanks In Advance
    Regards
    Srikkanth.M

    Srikkanth,
    Try this code. And 1 more thing, i can't see any WHERE condition to join between the 2 tables DAIL_ATT, TRAIN_MAST.
    UPDATE DAIL_ATT A SET A.IDE_IN = (SELECT TO_NUMBER(TO_DATE(TO_CHAR(INTIME, 'DD-MON-YYYY')|| ' ' || TO_CHAR(0815, '0000'), 'DD-MON-YYYY HH24:MI') + LATE_HRS / (24 * 60) - INTIME) * 24 * 60 FROM TRAIN_MAST B WHERE <condition>);Regards,
    Manu.
    If my response or the response of another was helpful or Correct, please mark it accordingly

  • Can't figure out the correct syntax for this select statement

    Hello,
    The following statement works great and gives the desired results:
    prompt
    prompt Using WITH t
    prompt
    with t as
       select a.proj_id,
              a.proj_start,
              a.proj_end,
              case when (
                         select min(a.proj_start)
                           from v b
                          where (a.proj_start  = b.proj_end)
                            and (a.proj_id    != b.proj_id)
                        is not null then 0 else 1
              end as flag
         from v a
        order by a.proj_start
    select proj_id,
           proj_start,
           proj_end,
           flag,
           -- the following select statement is what I am having a hard time
           -- "duplicating" without using the WITH clause
            select sum(t2.flag)
              from t t2
             where t2.proj_end <= t.proj_end
           ) s
      from t;As an academic exercise I wanted to rewrite the above statement without using the WITH clause, I tried this (among dozens of other tries - I've hit a mental block and can't figure it out):
    prompt
    prompt without with
    prompt
    select c.proj_id,
           c.proj_start,
           c.proj_end,
           c.flag,
           -- This is what I've tried as the equivalent statement but, it is
           -- syntactically incorrect.  What's the correct syntax for what this
           -- statement is intended ?
            select sum(t2.flag)
              from c t2
             where t2.proj_end <= c.proj_end
           ) as proj_grp
      from (
            select a.proj_id,
                   a.proj_start,
                   a.proj_end,
                   case when (
                              select min(a.proj_start)
                                from v b
                               where (a.proj_start  = b.proj_end)
                                 and (a.proj_id    != b.proj_id)
                             is not null then 0 else 1
                   end as flag
              from v a
             order by a.proj_start
           ) c;Thank you for helping, much appreciated.
    John.
    PS: The DDL for the table v used by the above statements is:
    drop table v;
    create table v (
    proj_id         number,
    proj_start      date,
    proj_end        date
    insert into v values
           ( 1, to_date('01-JAN-2005', 'dd-mon-yyyy'),
                to_date('02-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 2, to_date('02-JAN-2005', 'dd-mon-yyyy'),
                to_date('03-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 3, to_date('03-JAN-2005', 'dd-mon-yyyy'),
                to_date('04-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 4, to_date('04-JAN-2005', 'dd-mon-yyyy'),
                to_date('05-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 5, to_date('06-JAN-2005', 'dd-mon-yyyy'),
                to_date('07-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 6, to_date('16-JAN-2005', 'dd-mon-yyyy'),
                to_date('17-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 7, to_date('17-JAN-2005', 'dd-mon-yyyy'),
                to_date('18-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 8, to_date('18-JAN-2005', 'dd-mon-yyyy'),
                to_date('19-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           ( 9, to_date('19-JAN-2005', 'dd-mon-yyyy'),
                to_date('20-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           (10, to_date('21-JAN-2005', 'dd-mon-yyyy'),
                to_date('22-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           (11, to_date('26-JAN-2005', 'dd-mon-yyyy'),
                to_date('27-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           (12, to_date('27-JAN-2005', 'dd-mon-yyyy'),
                to_date('28-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           (13, to_date('28-JAN-2005', 'dd-mon-yyyy'),
                to_date('29-JAN-2005', 'dd-mon-yyyy'));
    insert into v values
           (14, to_date('29-JAN-2005', 'dd-mon-yyyy'),
                to_date('30-JAN-2005', 'dd-mon-yyyy'));

    Hi, John,
    Not that you asked, but as you proabably know, analytic functions are much better at doing this kind of thing.
    You may be amazed (as I continually am) by how simple and efficient these queries can be.
    For example:
    WITH     got_grp          AS
         SELECT     proj_id, proj_start, proj_end
         ,     proj_end - SUM (proj_end - proj_start) OVER (ORDER BY  proj_start)     AS grp
         FROM     v
    SELECT       ROW_NUMBER () OVER (ORDER BY grp)     AS proj_grp
    ,       MIN (proj_start)                         AS proj_start
    ,       MAX (proj_end)               AS proj_end
    FROM       got_grp
    GROUP BY  grp
    ORDER BY  proj_start
    ;Produces the results you want:
      PROJ_GRP PROJ_START  PROJ_END
             1 01-Jan-2005 05-Jan-2005
             2 06-Jan-2005 07-Jan-2005
             3 16-Jan-2005 20-Jan-2005
             4 21-Jan-2005 22-Jan-2005
             5 26-Jan-2005 30-Jan-2005This is problem is an example of Neighbor-Defined Groups . You want to GROUP BY something that has 5 distinct values, to get the 5 rows above, but there's nothing in the table itself that tells you to which group each row belongs. The groups are not defined by any column in hte table, but by relationships between rows. In this case, a row is in the same group as its neighbor (the row immediatly before or after it when sorted by proj_start or proj_end) if proj_end of the earlier row is the same as proj_start of the later row. That is, there is nothing about 03-Jan-2005 that says the row with proj_id=2 is in the first group, or even that it is in the same group with its neighbor, the row with proj_id=3. Only the relation between those rows, the fact that the earlier row has end_date=03-Jan-2005 and the later row has start_date=03-Jan-2003, that says these neighbors belong to the same group.
    You're figuring out when a new group starts, and then counting how many groups have already started to see to which group each row belongs. That's a prefectly natural procedural way of approaching the problem. But SQL is not a procedural language, and sometimes another approach is much more efficient. In this case, as in many others, a Constant Difference defines the groups. The difference between proj_end (or proj_start, it doesn't matter in this case) and the total duratiojn of the rows up to that date determines a group. The actual value of that difference means nothing to you or anybody else, so I used ROW_NUMBER in the query above to map those distinct values into consecutive integers 1, 2, 3, ... which are a much simpler way to identify the groups.
    Note that the query above only requires one pass through the table, and only requires one sub-query. It does not need a WITH clause; you could easily make got_grp an in-line view.
    If you used analytic functions (LEAD or LAG) to compute flag, and then to compute proj_grp (COUNT or SUM), you would need two sub-queries, one for each analytic function, but you would still only need one pass through the table. Also, those sub-queries could be in-line views; yiou would not need to use a WITH clause.

  • Whats wrong in this select statement

    SELECT A~BUKRS
           A~FKART
           A~FKDAT
           A~VBELN
           B~POSNR
           B~MATNR
           B~MEINS
           B~FKIMG
           INTO TABLE IT_DATA
           FROM VBRK AS A INNER JOIN VBRP AS B ON BVBELN = AVBELN
           WHERE A~BUKRS = P_BUKRS AND
                 A~FKART IN S_FKART AND
                 A~FKDAT IN S_FKDAT AND
                 B~MATNR IN S_MATNR.
    i am getting dump in this select statement

    Error analysis                                                                               
    The data read during a SELECT access could not be inserted into the       
    target field.                                                             
    Either conversion is not supported for the target field's type or the     
    target field is too short to accept the value or the data are not in a    
    form that the target field can accept                                                                               
    000890   FORM GET_DATA.                                                
    000900                                                                 
    000910                                                                 
    000920                                                                 
    000930   SELECT A~BUKRS                                                
    000940          A~FKART                                                
    000950          A~FKDAT                                                
    000960          A~VBELN                                                
    000970          B~POSNR                                                
    000980          B~MATNR                                                
    000990          B~MEINS                                                
    001000          B~FKIMG                                                
    001010          INTO TABLE IT_DATA                                     
    001020          FROM VBRK AS A INNER JOIN VBRP AS B ON BVBELN = AVBELN
    001030          WHERE A~BUKRS = P_BUKRS AND                            
    001040                A~FKART IN S_FKART AND                           
    001050                A~FKDAT IN S_FKDAT AND                           
        >                B~MATNR IN S_MATNR.                              
    001070                                                                 
    001080                                                                 
    001090                                                                 
    001100    DESCRIBE TABLE IT_DATA1 LINES LINES.                         
    001110   IF LINES = 0.                                                 
    001120   MESSAGE I001 WITH 'No data available for the selection'.      
    001130   ENDIF.                                                        
    001140                                                                 
    001150   CLEAR : LINES.                                                
    001160                                                                 
    001170                                                                 
    001180                                                                 
    001190   ENDFORM.                    " GET_DATA                        
    001200                                                                 
    the above is the dump

  • Why does this select statement fail.....

    declare
    t_name varchar2(100):='america';
    begin
    execute immediate '
    select * from'|| t_name;
    end;

    Because it looks like you need to add a space after 'from' and add an INTO CLAUSE?
    introduction to bulk pl/sql enhancements in 9i

  • Help me to solve this. select statement!

    hello alll
    is there any functional module which gives me the BELNR(of bseg) by passing the vbeln.
    yeah ...we can do tht by passing bseg table ,,,,but its taking loads of time to give me the output as its not a primary key or secondary key.....
    when i m using this condition in the prog i cannot use inner join as its a cluster table . if i m writing a condition it is effecting my prog performance
    this statement is really taking long time to process.
    in bseg table as vbeln is not primary key or seconday key, i guess thz the reason it is taking so much time ,,,
    can anyone help me to sort this out... ??
    any fun mod to get the data of bseg cluster table by giving vbeln?/
    or any other conditions to reduce the processing time?
    clear t_vbrkvbrp.
    sort t_vbrkvbrp by vbeln.
    loop at t_vbrkvbrp.
    at new vbeln.
    select bukrs belnr vbeln
    from bseg
    into corresponding fields of table t_temp
    where bukrs = t_vbrkvbrp-bukrs
    and vbeln = t_vbrkvbrp-vbeln.
    endat.
    endloop.
    SELECT bukrs belnr buzid koart shkzg dmbtr vbeln hkont kunnr werks
    FROM bseg
    INTO TABLE t_bseg
    for all entries in t_temp
    WHERE hkont IN s_hkont
    AND bukrs = t_temp-bukrs
    AND belnr = t_temp-belnr
    AND buzid = ' '
    AND koart = 'S'
    AND shkzg = 'H'.
    i need to get the g/l account number and belnr from bseg for the above condition type so i have to use bseg table
    as there is no apporpriate index it is scanning the full table ,,,, so can anyone tell me how to create a index or like wise to get the data faster??

    Don't use BSEG, use BKPF and fields AWTYP, AWREF which link a financial document to the application and document that generated it. (The "original document" under transaction like FB03)
    <i>Example: "RMRP" + invoice number for purchase invoice</i>
    In  some case you need an intermediate table
    <i>Example: from EKPO, EKBE, you get the MKPF records and from them the BKPF/BSEG</i>
    For a list of "referenced procedures" Look at TTYP (text table is TTYPT), you will get the code, structure used to build the key (if more than one field) and a function module used to display the origin
    <i>Example :  MKPF "Material document" structure MKPF_AWKEY function module MB_DOCUMENT_SENDER_MKPF</i>
    You can also look at your accounting documents found with the "slow" BSEG version of your program and establish a list of AWTYP used in you company/customer.
    An other way, used in some companies, is to append a structure with EBELN field to BSIS and BSAS table, these table are filled via a MOVE-CORRESPONDING statement, so the nesw records will be filled (You may write a program to update past records) then create an index on EBELN on these fields.
    Regards
    PS: BSEG is a cluster table, so the only real criteria are the primary keys, if you select via EBELN, the program read the whole table, may be correct in Development, but not in Production and there it will be more and more resources consuming. So NEVER select from BSEG vithout the primary keys, use the secondary tables : BSIS/BSAS, BSIM, etc.

  • Why this SQL statement is wrong?

    When I trying update my database using following statement:
    String query = "UPDATE Flights" +
    "SET AircraftType ='" + inputPanel.type.getText() +
    "', EnterPoint = '" + inputPanel.point.getText() +
    "',GroundSpeed = " + Integer.parseInt(inputPanel.speed.getText()) +
    ",Altitude =" + Integer.parseInt(inputPanel.altitude.getText()) +
    "WHERE FlightNumber =" + inputPanel.flight.getText();
    //where speep and altitude are ints
    it always say:Syntax error in UPDATE statement.
    I cannot understand why because this is a standard SQL statement I think.
    Please help me!
    Thanks in advance

    this part is causing you problems:
    "WHERE FlightNumber =" + inputPanel.flight.getText();
    if FlightNumber is an integer then you should convert the text to an int:
    "WHERE FlightNumber =" + Integer.parseInt(inputPanel.flight.getText());
    or if it is a String then:
    "WHERE FlightNumber ='" + inputPanel.flight.getText()+ "'";
    Jamie

  • How to make this select statement faster?

    this statement is really taking long time to process.
    in bseg table as vbeln is not primary key or seconday key, i guess thz the reason it is taking so much time ,,,
    can anyone help me to sort this out... ??
    any fun mod to get the data of bseg cluster table by giving vbeln?/
    or any other conditions to reduce the processing time?
    clear t_vbrkvbrp.
    sort t_vbrkvbrp by vbeln.
    loop at t_vbrkvbrp.
    at new vbeln.
    select bukrs belnr vbeln
           from bseg
           into corresponding fields of table t_temp
           where bukrs = t_vbrkvbrp-bukrs
            and vbeln = t_vbrkvbrp-vbeln.
    endat.
    endloop.
    SELECT bukrs belnr buzid koart shkzg dmbtr vbeln hkont kunnr werks
           FROM bseg
           INTO TABLE t_bseg
           for all entries in t_temp
           WHERE hkont IN s_hkont
           AND bukrs = t_temp-bukrs
           AND belnr = t_temp-belnr
           AND buzid = ' '
           AND koart = 'S'
           AND shkzg = 'H'.
    i need to get the g/l account number for the above condition type so i have to use bseg table
    Message was edited by:
            shahid mohammed syed

    Shahid,
    Usually BSEG SELECTs are slow as it is a Clu8ster table. More over you are not passing the PKeys in the WHERE condition. That's alcso one reason for slow retrieval. You can also use the table BSIS (Accounting: Secondary Index for G/L Accounts) for the G/L accounts. But first of all, I suggest you cnange your where condition as below:
    SELECT bukrs belnr buzid koart shkzg dmbtr vbeln hkont kunnr werks
    FROM bseg
    INTO TABLE t_bseg
    for all entries in t_temp
    WHERE  bukrs = t_temp-bukrs
    AND belnr = t_temp-belnr
    AND buzid = ' '
    AND koart = 'S'
    AND shkzg = 'H'
    <b>AND hkont IN s_hkont.</b>
    Not much diff. I just re-ordered the condition based on the order of BSEG fields... Lemme know if it helps.
    Regards,
    Karthik
    Message was edited by:
            Karthik

Maybe you are looking for