UPDATE Statement executing for whole table even when WHERE Clause is presen

Hi Friends,
I have a problem in a stored procedure where i have written an update statement with a where clause. At a time only one row should get updated depending upon unique identifier in where clause.
But whats happening is that Update statement is getting executed for all the rows in the table neglecting the WHERE clause. I am not getting the clue as to why this is happening. Here is the stored Procedure And the update statement is in BOLD :-
CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
CntryMasterCode IN VARCHAR2,
CntryName IN VARCHAR2,
MDMUser IN VARCHAR2,
Exist IN INTEGER,
status IN VARCHAR2,
Inserted_By IN VARCHAR2 DEFAULT NULL,
Modified_By IN VARCHAR2 DEFAULT NULL,
Mdm_Code IN NUMBER DEFAULT 0,
Action IN VARCHAR2 DEFAULT 'add',
XGenAttNames IN VARCHAR2 DEFAULT NULL,
XGenAttValues IN VARCHAR2 DEFAULT NULL,
MirusAttNames IN VARCHAR2 DEFAULT NULL,
MirusAttValues IN VARCHAR2 DEFAULT NULL,
GenisysAttNames IN VARCHAR2 DEFAULT NULL,
GenisysAttValues IN VARCHAR2 DEFAULT NULL,
XGenModify IN VARCHAR2 DEFAULT NULL,
MirusModify IN VARCHAR2 DEFAULT NULL,
GenisysModify IN VARCHAR2 DEFAULT NULL
IS
strSQLXGen VARCHAR(1000);
strSQLMirus VARCHAR(1000);
strSQLGenisys VARCHAR(1000);
nMaxMDMCode INTEGER;
ifExist INTEGER;
NAME: proc_MDM_InsertCntryDetails
PURPOSE:
REVISIONS:
Ver Date Author Description
1.0 7/3/2009 1. Created this procedure.
NOTES:
Automatically available Auto Replace Keywords:
Object Name: proc_MDM_InsertCntryDetails
Sysdate: 7/3/2009
Date and Time: 7/3/2009, 7:11:20 PM, and 7/3/2009 7:11:20 PM
Username: (set in TOAD Options, Procedure Editor)
Table Name: (set in the "New PL/SQL Object" dialog)
BEGIN
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MASTER;
IF ifExist = 0 THEN
SELECT 1 INTO nMaxMDMCode FROM DUAL;
ELSE
SELECT MAX(MDM_CODE)+1 INTO nMaxMDMCode FROM MDM_COUNTRY_MASTER;
END IF;
IF Action='add' THEN
INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
     VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,Exist,status,Action,SYSDATE,Inserted_By);
strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || nMaxMDMCode || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen;
strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || nMaxMDMCode || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus;
strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || nMaxMDMCode || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys;
ELSE
UPDATE MDM_COUNTRY_MASTER
SET MDM_DESCRIPTION=CntryName,DAT_MODIFIED_BY=Modified_By,DAT_MODIFY_DATE=SYSDATE,
MDM_USER=MDMUser,MDM_ACTION=Action,MDM_STATUS=status,MDM_EXIST=Exist WHERE MDM_CODE=Mdm_Code;
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=1 AND MDM_CODE=Mdm_Code ;
IF ifExist = 0 THEN
strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || Mdm_Code || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen ;
ELSE
strSQLXGen := 'UPDATE MDM_COUNTRY_MAPPING SET ' || XGenModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=1' ;
EXECUTE IMMEDIATE strSQLXGen ;
END IF;
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=2 AND MDM_CODE=Mdm_Code ;
IF ifExist = 0 THEN
strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || Mdm_Code || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus ;
ELSE
strSQLMirus := 'UPDATE MDM_COUNTRY_MAPPING SET ' || MirusModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=2' ;
EXECUTE IMMEDIATE strSQLMirus ;
END IF;
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=3 AND MDM_CODE=Mdm_Code;
IF ifExist = 0 THEN
strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || Mdm_Code || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys ;
ELSE
strSQLGenisys := 'UPDATE MDM_COUNTRY_MAPPING SET ' || GenisysModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=3' ;
EXECUTE IMMEDIATE strSQLGenisys ;
END IF;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END proc_MDM_InsertCntryDetails;
Thanks

It might be helpful to search this forum and google for PL/SQL (variables, stored procs, etc) naming standards. There are quite a few out there and you can choose one that works for you.
As an example, a lot of standards adopt naming prefixes, ie v_ for VARCHAR variable, n_ for NUMBER variable, pv_ for paramater VARCHAR, etc.

Similar Messages

  • Ever since I got the new update 5.1 my iPod's been dying faster. It used to last for at least 3 hours, now it won't even last one hour and dies for no reason(even when it's in sleep mode, and not in use) What's wrong with it? Is it the update? lagging too

    Ever since I got the new update 5.1 my iPod's been dying faster, even after I charge it. It used to last for at least 3 hours, now it won't even last one hour and dies for no reason (even when it's in sleep mode, and not in use) What's wrong with it? Is it the update? It's lagging as well..

    Some Users have Reported that a  Restore as New  has helped Resolve issues...
    Backup and Set Up as New Device
    http://support.apple.com/kb/HT4137

  • Is it possible that my update stats used only correct tables?

    Whenever there is a schedule maintenance run I receive a error:
    Executing the query "UPDATE STATISTICS [Perf].[PerfHourly_F65954CD35A54..." failed with the following error: "Table 'PerfHourly_F65954CD35A549E886A48E53F148F277' does not exist.". Possible failure reasons: Problems with the query, "ResultSet"
    property not set correctly, parameters not set correctly, or connection not established correctly.
    Is it possible that my update stats used only correct  tables?
    Thanks

    Use below script ...(change if required)
    USE [dbname]
    go
    DECLARE @mytable_id INT
    DECLARE @mytable VARCHAR(100)
    DECLARE @owner VARCHAR(128)
    DECLARE @SQL VARCHAR(256)
    SELECT @mytable_id = MIN(object_id)
    FROM sys.tables WITH(NOLOCK)
    WHERE is_ms_shipped = 0
    WHILE @mytable_id IS NOT NULL
    BEGIN
     SELECT @owner = SCHEMA_NAME(schema_id), @mytable = name
     FROM sys.tables
     WHERE object_id = @mytable_id
     SELECT @SQL = 'UPDATE STATISTICS '+ QUOTENAME(@owner) +'.' + QUOTENAME(@mytable) +' WITH ALL, FULLSCAN;'
     Print @SQL
     EXEC (@SQL)
     SELECT @mytable_id = MIN(object_id)
     FROM sys.tables WITH(NOLOCK)
     WHERE object_id > @mytable_id
      AND is_ms_shipped = 0
    END
    Or use below for required table only but it will not execute only generate script, make change as per ur requirements:
    SELECT X.*,
      ISNULL(CASE
        WHEN X.[Total Rows]<=1000
        THEN
          CASE
            WHEN [Percent Modified] >=20.0
            THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name] + ' WITH ALL, FULLSCAN  --20% Small Table Rule'
          END
        WHEN [Percent Modified] = 100.00
        THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  --100% No real Stats Rule'
        --WHEN X.[Rows Modified] > 1000
        --THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  --1000 Rows Modified Rule'
        ELSE
          CASE
            WHEN X.[Total Rows] > 1000000000 --billion rows
            THEN CASE
                   WHEN [Percent Modified] > 0.1
                   THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  -- 1B Big Table Rule'
                 END
            WHEN X.[Total Rows] > 100000000  --hundred million rows
            THEN CASE
                   WHEN [Percent Modified] > 1.0
                   THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  -- 100M Big Table Rule'
                 END
            WHEN X.[Total Rows] > 10000000   --ten million rows
            THEN CASE
                   WHEN [Percent Modified] > 2.0
                   THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  -- 10M Big Table Rule'
                 END
            WHEN X.[Total Rows] > 1000000    --million rows
            THEN CASE
                   WHEN [Percent Modified] > 5.0
                   THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  -- 1M Big Table Rule'
                 END
            WHEN X.[Total Rows] > 100000     --hundred thousand rows
            THEN CASE
                   WHEN [Percent Modified] > 10.0
                   THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  -- 100K Big Table Rule'
                 END
            WHEN X.[Total Rows] > 10000      --ten thousand rows
            THEN CASE
                   WHEN [Percent Modified] > 20.0
                   THEN 'UPDATE STATISTICS ' + [Schema Name] + '.' + [Table Name]     + ' WITH ALL, FULLSCAN  -- 10K Big Table Rule'
                 END
            END
      END,'') AS [Statistics SQL]
    FROM (
    SELECT  DISTINCT
            DB_NAME()   AS [Database],
            S.name      AS [Schema Name],
            T.name      AS [Table Name],
            I.rowmodctr AS [Rows Modified],
            P.rows      AS [Total Rows],
            CASE
              WHEN I.rowmodctr > P.rows
              THEN 100
              ELSE CONVERT(decimal(8,2),((I.rowmodctr * 1.0) / P.rows * 1.) * 100.0)
            END AS [Percent Modified]
    FROM
            sys.partitions P
            INNER JOIN sys.tables  T ON P.object_Id = T.object_id
            INNER JOIN sys.schemas S ON T.schema_id = S.schema_id
            INNER JOIN sysindexes  I ON P.object_id = I.id
    WHERE P.index_id in (0,1)
      AND I.rowmodctr > 0
    ) X
    WHERE [Rows Modified] > 1000
    ORDER BY [Rows Modified] DESC
    Please click "Propose As Answer"
    if a post solves your problem, or "Vote As Helpful" if a post has been useful
    to you

  • Update statement with joining other tables

    Hi ,
    I have two table one is containing xml file , basically i need to read from those xml file then update to another table based on some condition.
    UPDATE TRCB_XBRL_STG_2 STG
    SET PROFIT =
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//PROFIT ', 'xmlns:acra=".."')
      ELSE STG.PROFIT
      END,
      SET REVENUE=
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE.', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//REVENUE', 'xmlns:acra="REVENUE"')
      ELSE STG.REVENUE
      END,
      ... (around 100 columns)
    FROM  TRCB_XBRL xbrl ,TRCB_XBRL_STG_2 STG
    WHERE STG.XBRL_ID = XBRL.XBRL_ID Number of columns are around 100 , please anyone suggest how to use update statement with joining two tables.

    Hi,
    If all the values needed to update a given row of table_x are coming from the same row of table_y (or from the same row of a result set of a query involving any number of tables), then you can do something like this:
    UPDATE  table_x  x
    SET     (col1, col2, col3, ...)
    =     (
             SELECT  NVL (y.col1, x.col1)
             ,         NVL (y.col2, x.col2)
             ,         NVL (y.col3, x.col3)
             FROM    table_y  y
             WHERE   x.pkey   = y.expr
             AND         ...
    WHERE   ...
    ;If the WHERE clause depends on the same row of table_y, then it will probably be simpler and more efficient to use MERGE instead of UPDATE.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • My iCloud keeps asking me for a password even when I enter it, it still keeps asking. I have tried turning it off but it doesn't work.

    My iCloud keeps asking me for a password even when I enter it, it still keeps asking. I have tried turning it off but it doesn't work. It is really annoying!!
    Please help me!! (The same thing happened on this device and when I reset it, it worked....why isn't my iPad 3rd gen. Working...?)

    Try reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • Update statement problem for jdbc adapter

    Hi all
    In the jdbc sender adapter, I configured as follows:
    Query statement
    select * from pickdiff where tid is null
    Update statement
    delete from pickdiff where tid is null
    I got following error message:
    Database-level error reported by JDBC driver while executing statement 'delete from pickdiff where tid is null'. The JDBC driver returned the following error message: 'java.sql.SQLException: [SQLServer 2000 Driver for JDBC][SQLServer]Die Unterabfrage gab mehr als einen Wert zurück. Das ist ungültig, wenn die Unterabfrage auf =, !=, <, <= , >, >= folgt oder als Ausdruck verwendet wird.'. For details, contact your database server vendor.
    If I change the Update statement to
    update pickdiff set tid = 'sapxi' where tid is null
    Then everything is ok.
    Doese any one have some idea about this problem?
    Regards
    Hui

    Hi,
    The below statements are from SAP help...
    http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/frameset.htm
    The UPDATE statement must alter exactly those data records that have been selected by the SELECT statement. You can ensure this is the case by using an identical WHERE clause. (See Processing Parameters, SQL Statement for Query, and SQL Statement for Update below).
    &#9679;      Processing can only be performed correctly when the isolation level for transaction is set to repeatable_read or serializable.
    SQL statement for query: SELECT * FROM table WHERE processed = 0;
    SQL statement for update: UPDATE table SET processed = 1 WHERE processed = 0;
    processed is the indicator in the database.
    please see if setting the isolation level would help....Also are you getting this error always or is it intermitent ?
    Thanks,
    Renjith

  • Auto update stats disabled for a user Database in Sql server

    While trying to improve the performance of few queries, we found via execution plan that there were lot of Index/Clustered index seeks. Therefore:
    First thing we did, was to check our Re-indexing and update stats job which runs weekly for this user DB ( Around 400 GB in size and is used 24*5). The job was running fine.
    Later when we ran SP_Blitz, we came to know that auto-update-stats is disabled for this user DB. We expected this to be a possible cause and change it from false to TRUE(Auto update stats)
    Also, per SP_blitz there are user-created statistics for this DB. When ran the query to check how many, we saw around 7K user stats out there.
    So my question would be 1) setting the Auto update stats to TRUE would require a reboot or once changed i need to track the performance and 2) Should we consider dropping those user created stats or manually look into them one by one.
    How should we proceed on this, please suggest, thanks!

    There may be good reasons for having auto-stats off, but those cases are not very common. It makes a little more sense to turn if off on table level. An example of the latter is a relatively small table, say < 100000 rows where not many new rows are added,
    but the existing rows are being updated frequently. This will trigger autostats, but probably without much benefit.
    But if you have a system which is very busy during peak times, you may not want autostats take resources during those hours. But if you turn off autostats, you will need to make sure that stats are updated in some other fashion.
    Here is a query that you can use review when your statistics last were updated:
    SELECT o.name, s.name, stats_date(o.object_id, s.stats_id) AS lastupdated
    FROM   sys.objects o
    JOIN   sys.stats s ON s.object_id = o.object_id
    --WHERE  s.user_created = 1
    ORDER BY lastupdated
    7000 user-created statistics sounds a little excessive, but I guess they were added to compensate for the autostats that SQL Server were not permitted to create. I would not recommend dropping these statistics, as SQL Server would spend cycles on recreating
    them.
    You should not have to restart SQL Server for the Auto-update stats setting to take effect; it takes effect immediately.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • HT204368 iPhone continues to search for bluetooth devices even when connected thus affecting battery.

    iPhone 4S continues to search for bluetooth devices even though it is connected to one.
    Can this be stopped to save battery?

    Why do you believe this is true?  If you're looking at the bluetooth settings page, simply opening that page in settings initiates the search. It stops when you close it.
    Like the light in your fridge.

  • Auto stats gathering for partitioned table

    Hi,
    We are in 10gR2 in sun solaris. We are using auto stats gathering for our DB. Here is my question,
    i know oracle gather statistics of the table, if the table changes more than 10%. How this work out for partitioned table? If the partition table changes more than 10% will last partition analyzed or the full table. We have partitioned based on insertion date.
    Appreciate your responds.
    Regards,
    Satheesh Shanmugam
    http://borndba.com

    I hope it will be only current partition which has teh stale statistics will be gathered the stastics instead of full table.
    Anil Malkai

  • "Missing most detailed table for dimension tables" eror when I run the Global Consistency check

    ERRORS:
    Business Model DAC Measures:
    [nQSError: 15003] Missing most detailed table for dimension tables: [D_DETAILS,D_EXECUTION_PLAN,D_TASK].
    [nQSError: 15001] Could not load navigation space for subject area DAC Measures.
    I am also attaching my Business Model layer for easy understanding. I have a fact table and several Dimension table. I got this error only after creating the following hierarchies:
    Execution Plan -> Tasks -> Details
    Start Date Time Hierarchy
    End Date Time Hierarchy
    Is there a solution for this problem? Thanks in advance!

    Yes ! My Task Hierarchy has 3 dimension tables that form a hierarchy :Execution Plan -> Tasks -> Detail
    All the 3 levels in the hierarchy are 3 different dimension tables.

  • Update 1 column,1 single table based on where results of multiple tables

    I would like the my_id column in 1 table updated to the static value of 247 for my_id stored in the 1 single table based on the where clause, which uses the my_id column in it.
    The update statement updates all rows in table1, instead of just the rows where
    the condition ( (b.my_id=a.my_id)
    and ( b.my_name like 'OIS SrClerk%')
    and (a.f_id=m.f_id)
    and (trunc(m.cr_time) < '02-Apr-2008')) is true
    What needs to be changed?
    update table1 a
    set a.my_id=247
    from table1 a, table2 b, table3 m
    where
    (b.my_id=a.my_id)
    and ( b.my_name like 'OIS SrClerk%')
    and (a.f_id=m.f_id)
    and (trunc(m.cr_time) < '02-Apr-2008')

    Are you looking for this?
    UPDATE table1 A
       SET A.my_id = 247
    WHERE EXISTS (SELECT 'x'
                     FROM table2 b,
                          table3 M
                    WHERE b.my_id = A.my_id
                     AND b.my_name LIKE 'OIS SrClerk%'
                     AND A.f_id = M.f_id
                     AND TRUNC (M.cr_time) < to_date('02-apr-2008 00:00:00','dd-mon-yyyy HH:MI:SS') )changed date string to to_date
    Message was edited by:
    devmiral

  • Select statement having internal table in the wher clause...

    Hi,
    will all the entry from the internal i_crhd will be pased to the next select statement in the sample code below without looping? Thanks  a lot!
    REFRESH i_crhd.
       SELECT objid vgwts
         FROM crhd INTO CORRESPONDING FIELDS OF TABLE i_crhd
         WHERE arbpl IN s_arbpl.
    pulling the cost centre linked to the resource
       IF sy-subrc EQ 0 AND i_crhd[] IS NOT INITIAL.
         REFRESH i_crco.
         SELECT kostl FROM crco
           INTO CORRESPONDING FIELDS OF TABLE i_crco
           FOR ALL ENTRIES IN i_crhd
           WHERE objid = i_crhd-objid.
         IF sy-subrc EQ 0.
          do nothing.
         ENDIF.
       ENDIF.

    Hi,
    The code looks fine..u can very well go ahead with the code...
    Wht all other ABAPers said about FOR ALL ENTRIES is absolutely rite.
    But i have a small suggestion...
    Why cant u use a INNNER JOIN for those 2 queries...
    like...
    SELECT cr~objid
                 cr~vgwts
                 co~kostl
    FROM crhd AS cr INNER JOIN
              crco AS co
    ON  crobjid = coobjid
    INTO TABLE i_crco
    WHERE cr~arbpl IN s_arbpl.
    Now in i_crco 3 fields will be thr
    objid, vgwts, kostl.....this one can change as u wish...
    Why i suggest not to ue FOR ALL ENTRIES is sometimes it is a performanc killer....in this code i feel this will do fine...
    Please let me know if u feel not ok with this code...
    Reward if found useful...
    Regards,
    ABAPer 007.

  • Mutating table exception & use of a table column in where clause

    Hello,
    I have a scenario in which I am getting a Mutating table exception in which I have a trigger using which I insert into a second table in case there is an insert in the first table or the one which is associated with the trigger .
    my trigger code has this line which is causing the Mutating table exception :
    BEGIN
    IF INSERTING THEN
    SELECT a,b INTO var_a,var_b
    FROM tableA,tableB,tableC
    WHERE tableC.c = :new:c
    The problem is the tableC reference in my where clause is causing a Mutating table exception , but I don't see any other way in which I can get rid of it cause I need to check if new:c values exists in the table or not , can anybody suggest how I can get rid of the tableC reference in my SQL statement yet be able to check for the value of :new:C in my statement ?

    Hopefully this demonstrates the problem , the bold portion or the where clause is where I am getting flummoxed , I need to be able to compare the new value to a column in table C but if I use tableC reference I get mutating table exception
    create or replace
    trigger myTrigger
    after insert or delete or update on TableC
    referencing old as old new as new
    for each row
    DECLARE val1 number; val2 CHAR(1);
    BEGIN
    IF INSERTING THEN
    SELECT tableA.val1,tableB.val2 INTO val1,val2
    FROM TableA tableA,TableB tableB
    WHERE :new.val1
    AND :new.val1 is not null
    AND tableA.val2 = :new.val2
    AND tableB.val3 = tableA.val3
    AND tableC.val4 = :new.val5
    INSERT INTO TableD (col1 ,
    col2,
    col3,
    col4,
    col5,
    col6,
    col7,
    col8,
    col9)
    VALUES(:new.val1,
    :new.val2,
    :new.val3,
    tableA.val1,
    tableB.val2,
    :new.val4,
    :new.val5,
    :new.val6,
    :new.val7);

  • Query for Find Mode Fails-AutoGenerated WHERE clause missing quotation mark

    Using Oracle JDev 10.1.3.2. In 'Find Mode' the query execution fails.
    The error shown below is caused by the WHERE clause statement. The column name is quoted in the database but the code generated by the ADF framework does not use quotes. As a result the column name is illegal. Is there a way to hint to the ADF framework to ALWAYS use quotation marks?
    (oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT "PLATE","WROW","WCOL","WFIELD","AVGNUC.NUC_CELL_INTENSITY","MEDNUC.NUC_CELL_INTENSITY","AVGORG.INCLUSION_BCKG_INTE","MEDORG.INCLUSION_BCKG_INTE","MEDORG.COUNT","MEDORG.SPACING","MEDORG.NEIGHBOR_COUNT" FROM ICSUMSTAS_1888_295) QRSLT WHERE ( ( (MEDORG.COUNT >0) ) )

    It is true that these are not the most column 'friendly' names, but they are what they are. In the database these columns are quoted and they must be so in order for the query to work correctly.
    The suggestion of directly manipulating the View Criteria is a good one and I have implemented a solution based on it but it's cumbersome. Here is how it works:
    First, use the default query mode UI to add new View Criteria. If you were to execute the query at this point it would fail due to the columns names not being quoted. So, instead, implemented my own execute query button that first uses the View Criteria to create a properly quoted WhereClause for the ViewObject.
    I then reset the ViewCriteria (or they will interfere with the WhereClause), set the custom constructed WhereClause on the ViewObject, and re-execute the query. The cumbersome part is that I have to create my own parser for user input to write a valid WhereClause. And when the user uses query mode again the previously set ViewCriteria have been reset (which is annoying, and not the typical query mode behavior which might confuse the user)
    below are some of my code snippets:
    * This action is triggered by clicking the FIND button on the UI.
    * It uses a combination of the ViewCriteria default UI and custom code that processes
    * user input into a whereClause for the ViewObject
    private void jbFind_actionPerformed(ActionEvent e) {
    jbAddRow.setEnabled(false);
    //reset old where clause
    System.out.println("OLD WHERE:"+myView.getWhereClause());
    myView.setWhereClause(null);
    String customWhere=getCustomWhere();
    /* The case for null and blank View Criteria is tested below
    * when there are blank ViewCriteria the sequence (--) is generated from getCustomWhere
    * Note the use of contains instead of equals
    * The use of equalIgnoreCase etc for unexplained reasons seem to fail to detect when customWhere is (--)
    if(customWhere==null||customWhere.contains("(--)")){
    return;
    }else{
    /*remove ViewCriteria because they can not handle special Column names
    * That's why we go into the trouble of creating our own find function
    myView.getViewCriteria().removeAllElements();
    myView.setWhereClause(customWhere);
    myView.executeQuery();
    jUNavigationBar1.doAction(JUNavigationBar.BUTTON_EXECUTE);
    jTable1.revalidate();
    private String getCustomWhere(){
    StringBuffer custom=new StringBuffer();
    ApplicationModule am = (ApplicationModule) panelBinding.getApplication().getDataProvider();
    DCJboDataControl jbodc = new DCJboDataControl(am);
    JUIteratorBinding iterBinding = new JUIteratorBinding(jbodc,myView );
    int criteriaCount=iterBinding.getViewCriteria().getRowCount();
    //Validation when no ViewCriteria are defined
    if (criteriaCount==0){
    System.out.println("ViewCriteria Count: "+criteriaCount);
    return null;
    }else{
    System.out.println("ViewCriteria Count: "+criteriaCount);
    int attr=iterBinding.getViewCriteria().getCurrentRow().getAttributeCount();
    int criteriaRows=iterBinding.getViewCriteria().getAllRowsInRange().length;
    String[] attrNames=iterBinding.getViewCriteria().getCurrentRow().getAttributeNames();
    for (int r=0;r<criteriaRows;r++)
    {custom.append("(");
    for (int k=0;k<attr;k++){
    if(iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)!=null){
    custom.append("(\""+attrNames[k]+"\"");// LIKE '"+(String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)+"') AND ");
    //trim white space
    String attrK=((String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)).trim();
    String qual=attrK.substring(0,1);
    if(qual.equalsIgnoreCase(">")||qual.equalsIgnoreCase("<")||qual.equalsIgnoreCase("=")||qual.equalsIgnoreCase("!")){
    custom.append(" "+qual+"'"+attrK.substring(1)+"') AND " );
    }else{
    custom.append(" LIKE '"+(String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)+"') AND ");
    }custom.append("--");
    custom.append(")");
    custom.append(" OR ");
    }//end criteria rows
    custom.append("--");
    //now need to remove terminal AND and OR tagged with --
    String cleanWhere=custom.toString().replaceAll("AND --","").replaceAll("OR --","");
    System.out.println("NEW CUSTOM WHERE: "+cleanWhere);
    return cleanWhere;
    }

  • How can i use the internal table as a WHERE clause ?

    Dear Support ,
    I have one internal table that save the material information ...
    data : begin of itab ,
              matnr like mara-matnr ,
    end of itab .
    And now i want to fetch the material desription text base on this internal table .
    As i know that the "FOR ALL ENTRIES" statement is not allowed us to use "IN" this keyword ....
    So , Has another solution for this case ? I don't want to use "LOOP AT ...." this way ...
    Many thanks .
    Carlos

    Why can't you do
    SELECT MATNR MAKTX INTO TABLE ITAB2 FROM MAKT FOR ALL ENTRIES IN ITAB WHERE MATNR = ITAB-MATNR.

Maybe you are looking for

  • BW_BO Webi prompt Problem

    Hi Experts, I'm using BI 7.0 EHP1  with BO XI 3.1 SP2 and creating Webi reports on top of OLAP Universes. I have a BW variable of Type-User enty/default value Variable entry -Optional and ready for ready for Input. and I'm able to key in the values o

  • How to use Swing in a Web applicatrion

    Can you suggest me some good PDF or some good site for reading about using SWING in a Web Application. In our web application we plan to use JSP/Struts for the presentation layer. However there are a few screens that require some advanced UI like col

  • Why don't Firefox load the updated JCPenney web page?

    I've just spent nearly an hour on the phone with JCPenney, and then we got cut off. The gal is telling me where things are at on their new web site, and I'm telling her that no such thing appears on my page. After we got cut off I opened Google Chrom

  • Is Business Objects and Crystal Reports are the same?

    Hi all, What is the difference between crystal reports and business objects. And what is the advantage of business objects. Can anyone let me know the forums for Business objects in SAP. And what is the latest version for business objects. thanxs har

  • Export single fields

    Hi all, I'm trying to figure out if it's possible to export specific fields (but not necessarily all fields) from an editable PDF form (made in Acrobat X Standard) to specific cells in Excel? (Excel 2010 version) Some guidance on how to do it would b