Business rules to  implement - BEST way -  triggers and mutating table

I have the following table where it has Foreign Key defined on itself(self reference for parent_id column which can be null or valid site_id)
create table test_virtual_site
site_id number CONSTRAINT site_id_pk primary key,
parent_id number CONSTRAINT parent_site_id_unq UNIQUE ,
closed_date date default NULL ,
CONSTRAINT check_self_ref CHECK(parent_site_id <> site_id), --avoid self refernce
CONSTRAINT check_valid_site foreign key(parent_site_id) references test_virtual_site(site_id)
I have the following business rules to implement and my problem is related to their implementation
1)     A check should be made that Site_id specified as parent_id should not be a child of any other store (parent should have its parent_id column as NULL)
Site_id Parent_id
1
2 1
3 2 =>NOT VALID 2 is a child of another store
2)     Parent is not closed
Site_id Parent_id Closed_date
1 10-May-2005
3     1 =>NOT VALID 1 is a closed
3)
when parent store is closed - updated so at closed_date is not null
Want to set the parent_id as NULL for the child store.
OR
SET the closed_date for child store too same as the parent_store.
Example
Site_id Parent_id Closed_date
1     
1 2
Update test_virtual_site
SET closed_date = sysdate
Where site_id = 1 ;
Through Trigger
Site_id Parent_id Closed_date
1     22-Mar-06
1 2 22-Mar-06
OR
Site_id Parent_id Closed_date
1     22-Mar-06
1
When I am trying to do the above mentioned through constraints I am running into mutating trigger problem. Can you please guide me what is the best way to handle the above-mentioned scenarios.
I am aware that I can avoid the 3rd problem using the following
-- - Initialize an array in the before statement trigger.
-- - Add the processed rowid to the array in the after row
-- trigger.
-- - In the after statement trigger: get each rowid from the
-- array and process it. When all rowids are processed, clear
-- the array.
BUT for 1 and 2 I need to look at the parent specified , the parent exists in the same table BUT I can not perform the lookup from the BEFORE INSERT ROW LEVEL trigger but I want to ensure at the row level , so if the parent store is closed or parent specifed itself is a child(not permissible) I want to rollback the insert – RAISE_APPLICATION_ERROR.
Can you please guide me what is the best way to handle the above mentioned conditions .

I have the following table where it has Foreign Key defined on itself(self reference for parent_id column which can be null or valid site_id)
create table test_virtual_site
site_id number CONSTRAINT site_id_pk primary key,
parent_id number CONSTRAINT parent_site_id_unq UNIQUE ,
closed_date date default NULL ,
CONSTRAINT check_self_ref CHECK(parent_site_id <> site_id), --avoid self refernce
CONSTRAINT check_valid_site foreign key(parent_site_id) references test_virtual_site(site_id)
I have the following business rules to implement and my problem is related to their implementation
1)     A check should be made that Site_id specified as parent_id should not be a child of any other store (parent should have its parent_id column as NULL)
Site_id Parent_id
1
2 1
3 2 =>NOT VALID 2 is a child of another store
2)     Parent is not closed
Site_id Parent_id Closed_date
1 10-May-2005
3     1 =>NOT VALID 1 is a closed
3)
when parent store is closed - updated so at closed_date is not null
Want to set the parent_id as NULL for the child store.
OR
SET the closed_date for child store too same as the parent_store.
Example
Site_id Parent_id Closed_date
1     
1 2
Update test_virtual_site
SET closed_date = sysdate
Where site_id = 1 ;
Through Trigger
Site_id Parent_id Closed_date
1     22-Mar-06
1 2 22-Mar-06
OR
Site_id Parent_id Closed_date
1     22-Mar-06
1
When I am trying to do the above mentioned through constraints I am running into mutating trigger problem. Can you please guide me what is the best way to handle the above-mentioned scenarios.
I am aware that I can avoid the 3rd problem using the following
-- - Initialize an array in the before statement trigger.
-- - Add the processed rowid to the array in the after row
-- trigger.
-- - In the after statement trigger: get each rowid from the
-- array and process it. When all rowids are processed, clear
-- the array.
BUT for 1 and 2 I need to look at the parent specified , the parent exists in the same table BUT I can not perform the lookup from the BEFORE INSERT ROW LEVEL trigger but I want to ensure at the row level , so if the parent store is closed or parent specifed itself is a child(not permissible) I want to rollback the insert – RAISE_APPLICATION_ERROR.
Can you please guide me what is the best way to handle the above mentioned conditions .

Similar Messages

  • Best way to update RBSELBEST table for invoice

    what is the best way to update RBSELBEST table for PO invoice? Is there any BAPI or FM for this?

    Thanks. I tried this one also, but it does not update the table.
    in case if someone used this, what parameters i need to pass for this to work?

  • Succesfactors - Business Rule to trigger workflow (not triggering)

    Hi,
    I have used Business Rules and linked them to Base Objects to default values before and this worked just fine.
    Now I am trying to trigger a workflow from the moment a save is performed in the specific portlet.
    The rule is kicked off (I tested with defaulting a value and that worked correctly) but I don't get the notification that a workflow is started.
    This is how I configured my rule:
    The SF documentation talks a lot about using the pre-defined functions, but there is no real example for triggering workflows.
    I'm probably missing something... any suggestions?
    Already thanks in advance for your suggestions!
    Cheers,
    Gerrit

    Hi Sharma,
              There may be many reasons if the mail is not delivered from SAP .
    1. First Check with the transaction SCOT ( and SOST )
       This will tell you whether SMTP Configured is working fine or not.
       If there are pending ( Waiting ) items in SCOT , then it is not WF isssue ...it's related SMTP .
    2. You can very well test the SAP system for mails by sending a sample mail to your email id from SBWP
    3. If SCOT is working then you call drill down your analysis to application specific things i.e WOrkflow
    Hope this helps ur analysis
    Regards,
    Vijay

  • Business Rules not visible sometimes-via web and smartview

    We use EPM 11.1.2.
    we have a unique problem-Business rules (associated with forms)sometimes fail to appear either via web or smartview for our users.After logging out and back in,sometimes they appear again.
    If we explicitly 'disconnect all' from smartview, close Excel, and go back in again, then the rules are visible.
    It is becoming hard to tell when the users can or cannot see the business rules.
    All users have the right provisioning-interactive user.
    Has anybody seen this kind of behavior before?
    We had a similar issue a while back-with eas web versus eas desktop client. Oracle gave us a specific fix for the eas business rules problem.
    Edited by: 784749 on Sep 26, 2011 11:59 AM

    Thats the strange thing; We use (native) groups to provision. This works fine for the other 5 users.
    But even if I provision this one user for the Business Rules, they remain invisible to this user. (in Planning)
    I discovered this morning that this user can create a new BR, but when I try to open it in AAS console I get an error
    "Exception occured, Please check your log file for details."
    Unfortunately, the log doesn't provide any more details. (even if I set the level to Debug)

  • Best way to update custom table

    Hello experts,
    Iu2019m writing a report program and after pulling data from a custom table Iu2019m modifying certain fields within internal table and then eventually update custom table. The way Iu2019m updating custom table is working fine. However Iu2019m concern about performance issues because Iu2019m doing update on custom table within loop.
    Here is my code for reference.
    *&      Form  update_contracts
          text
    -->  p1        text
    <--  p2        text
    FORM update_contracts .
    Update record in an internal table first
      loop at izsc_compliance into wa_zsc_compliance..
        wa_zsc_compliance-zapproval = c_accepted.
        wa_zsc_compliance-CHANGED_DT = sy-datum.
        wa_zsc_compliance-CHANGED_TM = sy-uzeit.
        wa_zsc_compliance-CHANGED_BY = sy-uname.
        modify izsc_compliance from wa_zsc_compliance index sy-tabix.
        write:/ sy-tabix, wa_zsc_compliance-vbeln_new, wa_zsc_compliance-zapproval.
        if p_test is initial.
          move wa_zsc_compliance to zsc_compliance.
          update zsc_compliance.
        endif..
      endloop.
    Write records to database
      if p_test = 'X'.
        skip.
        write:/ 'Test mode'.
      endif.
    ENDFORM.                    " update_contracts
    Iu2019m not certain if there is any better way by not doing update within loop and update custom table outside this loop.
    Many thanks in advance.

    Hi,
    Yes, there is a better way to update the custom table. That will be more performance oriented and will be a much cleaner approach. As, I am not much aware of the custom table structure which you have in your program, the best way that I can suggest is to remove the update statement from that check. I guess you are checking against the mode - test or production. Once you have done the check, put the selected entries in an internal table which is same as database table. And then in a single command - a single array operation as it is commonly called, you can update the custom table.
    Have a look at the following link
    [Overwriting Several Lines Using an Internal Table|http://help.sap.com/saphelp_bw33/helpdata/en/fc/eb3a94358411d1829f0000e829fbfe/content.htm]
    [Inserting or Changing Lines|http://help.sap.com/saphelp_bw33/helpdata/en/fc/eb3ac8358411d1829f0000e829fbfe/content.htm]
    You can also scan the forum for multiple links and references and sample examples.
    Hope this will help. The above approach will be much more performance oriented and will help to optimize. Also, check where exactly you are providing the locking feature if at applicable in your business functionality.
    Regards,
    Samantak.

  • Implement two way replication on few tables

    Is there a way where I can implement 2 way replication.
    For instance I've two database A and B
    In a table in database A get updated or changed ..the effect should be shown on B
    and vice versa....
    Need ideas...

    * Oracle edition (enterprise, standard),
    Enterprise edition
    * network connectivity (is there a stable network link between the two),
    Yes we have a stable network
    * latency requirements (how quickly does a change on one have to appear on the other), and
    probably every 3 hrs
    * business requirements (why are you replicating the data in the first place)
    Well ours is call center, we work according to the availability of the interpereters and also we keep change pricing of call on daily basis.
    So there are few tables which needed to be updated regularly.

  • Opinion needed on best way to map multiple table joins (of the same table)

    Hi all
    I have a query of the format:
    select A.col1, B.col1,C.col1
    FROM
    MASTER_TABLE A, ATTRIBUTE_TABLE B, ATTRIBUTE_TABLE C
    WHERE
    A.key1 = B.key1 (+)
    AND
    A.key1 = C.key1(+)
    AND
    B.key2(+) = 100001
    AND
    C.key2(+) = 100002
    As you can see, I am joining the master table to the attribute table MANY times over, (over 30 attributes in my actual query) and I am struggling to find the best way to map this efficiently as the comparison for script vs. mapping is 1:10 in execution time.
    I would appreciate the opinion of experienced OWB users as to how they would tackle this in a mapping and to see if they use the same approach as I have done.
    Many thanks
    Adi

    SELECT external_reference, b.attribute_value AS req_date,
    c.attribute_value AS network, d.attribute_value AS spid,
    e.attribute_value AS username, f.attribute_value AS ctype,
    g.attribute_value AS airtimecredit, h.attribute_value AS simnum,
    i.attribute_value AS lrcredit, j.attribute_value AS airlimitbar,
    k.attribute_value AS simtype, l.attribute_value AS vt,
    m.attribute_value AS gt, n.attribute_value AS dt,
    o.attribute_value AS datanum, p.attribute_value AS srtype,
    q.attribute_value AS faxnum,
    R.ATTRIBUTE_VALUE AS FAXSRTYPE,
    s.attribute_value AS extno,
    t.attribute_value AS tb, u.attribute_value AS gb
    v.attribute_value AS mb, w.attribute_value AS stolenbar,
    x.attribute_value AS hcredit, y.attribute_value AS adminbar,
    z.attribute_value AS portdate
    FROM csi_item_instances a,
    csi_iea_values b,
    csi_iea_values c,
    csi_iea_values d,
    csi_iea_values e,
    csi_iea_values f,
    csi_iea_values g,
    csi_iea_values h,
    csi_iea_values i,
    csi_iea_values j,
    csi_iea_values k,
    csi_iea_values l,
    csi_iea_values m,
    csi_iea_values n,
    csi_iea_values o,
    csi_iea_values p,
    csi_iea_values q,
    CSI_IEA_VALUES R,
    csi_iea_values s,
    csi_iea_values t,
    csi_iea_values u,
    csi_iea_values v,
    csi_iea_values w,
    csi_iea_values x,
    csi_iea_values y,
    csi_iea_values z
    WHERE a.instance_id = b.instance_id(+)
    AND a.instance_id = c.instance_id(+)
    AND a.instance_id = d.instance_id(+)
    AND a.instance_id = e.instance_id(+)
    AND a.instance_id = f.instance_id(+)
    AND A.INSTANCE_ID = G.INSTANCE_ID(+)
    AND a.instance_id = h.instance_id(+)
    AND a.instance_id = i.instance_id(+)
    AND a.instance_id = j.instance_id(+)
    AND a.instance_id = k.instance_id(+)
    AND a.instance_id = l.instance_id(+)
    AND a.instance_id = m.instance_id(+)
    AND a.instance_id = n.instance_id(+)
    AND a.instance_id = o.instance_id(+)
    AND a.instance_id = p.instance_id(+)
    AND a.instance_id = q.instance_id(+)
    AND A.INSTANCE_ID = R.INSTANCE_ID(+)
    AND a.instance_id = s.instance_id(+)
    AND a.instance_id = t.instance_id(+)
    AND a.instance_id = u.instance_id(+)
    AND a.instance_id = v.instance_id(+)
    AND a.instance_id = w.instance_id(+)
    AND a.instance_id = x.instance_id(+)
    AND a.instance_id = y.instance_id(+)
    AND a.instance_id = z.instance_id(+)
    AND b.attribute_id(+) = 10000
    AND c.attribute_id(+) = 10214
    AND d.attribute_id(+) = 10132
    AND e.attribute_id(+) = 10148
    AND f.attribute_id(+) = 10019
    AND g.attribute_id(+) = 10010
    AND h.attribute_id(+) = 10129
    AND i.attribute_id(+) = 10198
    AND j.attribute_id(+) = 10009
    AND k.attribute_id(+) = 10267
    AND l.attribute_id(+) = 10171
    AND m.attribute_id(+) = 10184
    AND n.attribute_id(+) = 10060
    AND o.attribute_id(+) = 10027
    AND p.attribute_id(+) = 10049
    AND q.attribute_id(+) = 10066
    AND R.ATTRIBUTE_ID(+) = 10068
    AND s.attribute_id(+) = 10065
    AND t.attribute_id(+) = 10141
    AND u.attribute_id(+) = 10072
    AND v.attribute_id(+) = 10207
    AND w.attribute_id(+) = 10135
    AND x.attribute_id(+) = 10107
    AND y.attribute_id(+) = 10008
    AND z.attribute_id(+) = 10103
    AND external_reference ='07920490103'
    If I run this it takes less than a second in TOAD, when mapped in OWB it takes ages. 10:1 is a conservative estimate. In reality it takes 15-20 minutes. CSI_IEA_VALUES has 30 million rows CSI_ITEM_INSTANCES has 500,000 rows.
    Hope that helps. I would love to know how others would tackle this query.

  • Best way to clone a table?

    Hi,
    What is the best way to clone an existing table definition?
    What I mean is, I want to do the following:
    create table tab2 as
    select * from tab1;
    delete from tab2;
    commit;
    But clearly this involves copying all the data and then delete it. Is there a more efficient way?
    Another alternative I could think of is:
    create table tab2 as
    select * from tab1 where rownum < 2;
    delete from tab2;
    commit;
    This would copy only one row instead of all the rows in tab1. This is clearly much more efficient than the first approach, but I still don't like the idea of copying the data and deleting it.
    I am sure there would be a "cleaner" way. Any ideas?
    Thanks in advance,
    Rajesh

    Hi Justin,
    My work involves generating statistics by running various queries. So, I have written a few procedures that generate the statistics and insert into certain tables. Usually before starting to generate a new round of stats, I take back up of the previously generated data like this.
    Approach I:
    alter table summary_tab rename to summary_tab_20th;
    create table summary_tab as
    select * from summary_tab_20th
    where rownum < 2;
    delete from summary_tab;
    commit;
    Of course, another alternative I have is the following:
    Approach II:
    create table summary_tab_20th as
    select * from summary_tab;
    delete from summary_tab;
    commit;
    But I thought this is inefficient when compared to Approach I because it copies ALL the data from summary_tab to summary_tab_20th and then deletes ALL the data from summary_tab.
    However, one disadvantage with Approach I is that everytime I do this the stored procedure gets invalidated and I have to recompile it.
    So, that is where I stand. If all this looks very dirty, please suggest how I can 'clean up' my process :-)
    Thanks,
    Rajesh

  • Best way to check if table is empty or not

    Hi. I had to check if a table was empty or not, and found different solutions.
    One of them called my atention, I readed it was the best way to do it (some 'dual' trick from Steven Feuerstein, they say) :
    SELECT 1 FROM DUAL WHERE EXISTS (SELECT 'X' FROM TABLE);
    Plan
    SELECT STATEMENT ALL_ROWSCost: 4 Cardinality: 1           
         3 FILTER      
              1 FAST DUAL Cost: 2 Cardinality: 1
              2 INDEX FAST FULL SCAN INDEX (UNIQUE) TABLE.UB_PK Cost: 2 Cardinality: 1
    But doing some tests I found this query to have lower cost:
    SELECT 1 FROM TABLE WHERE ROWNUM=1;
    Plan
    SELECT STATEMENT ALL_ROWSCost: 2 Cardinality: 1           
         2 COUNT STOPKEY      
              1 INDEX FAST FULL SCAN INDEX (UNIQUE) TABLE.UB_PK Cost: 2 Cardinality: 1
    So, what about that dual table trick? Should I keep the 'select 1 where rownum=1' as best possible way?
    I know it shouldn't matter much, but just wanna know what method works best for checking empty tables :)
    Thanks.

    As already mentioned, you cannot just base it on cost, as the cost is not specifically a good indicator of the amount of work that will need to be done, it's just an internal figure calculated for that query and isn't really that comparible across different queries.
    If you're intending to see if there is data in a table because you want to know whether to query it or not, you are actually better to just try and query the data and capture the NO_DATA_FOUND exception and handle that.  In that case it requires no effort or cost up front.

  • Best way to to display tables with a select drop down

    I have created many SQL query report portlets, but I need a way for the users to select a specific acct nbr in a drop down list and then update a table on the same page. What is the best way to do this? I had created a Frame Driver, but I can not find a way to publish it to a page. Any ideas would be great, thanks.

    Hi,
    You can use a form based on table to do this. Build the form and publish it on the same page. The form can have a combination of various form items like textbox, textarea and drop down list etc. The form allows to query on the table and update the table.
    Thanks,
    Sharmila

  • Whats the best way to export a table.

    Hi guys
    i have a table with over 20 millions record in it. i want to export that table.
    my question is what is they best and fastest way to export this table and how much time it will take to export?
    Asif

    when i execute the export command i got the following error
    /u01/oracle/product/8.1.7/bin/exp dss/vox file=/usr/invoice_line_hist.dmp direct=Y feedback=25000 buffer=1000000 log=/usr/invoiceg
    Export: Release 8.1.7.4.0 - Production on Fri Dec 16 14:00:55 2005
    (c) Copyright 2000 Oracle Corporation. All rights reserved.
    Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production
    EXP-00041: Export done in server's UTF8, different from user's
    character set US7ASCII
    EXP-00000: Export terminated unsuccessfully
    What should i do to get rid of this problem.

  • Best way to create a table based on another table

    Hello,
    I am trying to create a table based on another table with all the data in it. It has large data.
    create table <tablename> as select * from table1.
    Is this the best way of doing it or is there any other way. please advice.
    thanks

    I am suggested to create new table as
    create table <newtable> as
    select * from <oldtable> where rownum < 1;
    then
    alter table <newtable> compress;
    then
    insert /*+ append */ into <newtable> as select * from <oldtable>;
    but i getting an error saying missing values key words ora- 00926.
    please advice

  • Best way to update a table with disinct values

    Hi, i would really appreciate some advise:
    I need to reguarly perform a task where i update 1 table with all the new data that has been entered from another table. I cant perform a complete insert as this will create duplicate data every time it runs so the only way i can think of is using cursors as per the script below:
    CREATE OR REPLACE PROCEDURE update_new_mem IS
    tmpVar NUMBER;
    CURSOR c_mem IS
    SELECT member_name,member_id
    FROM gym.members;
    crec c_mem%ROWTYPE;
    BEGIN
    OPEN c_mem;
    LOOP
    FETCH c_mem INTO crec;
    EXIT WHEN c_mem%NOTFOUND;
    BEGIN
    UPDATE gym.lifts
    SET name = crec.member_name
    WHERE member_id = crec.member_id;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN NULL;
    END;
    IF SQL%NOTFOUND THEN
    BEGIN
    INSERT INTO gym.lifts
    (name,member_id)
    VALUES (crec.member_name,crec.member_id);
    END;
    END IF;
    END LOOP;
    CLOSE c_mem;
    END update_new_mem;
    This method works but is there an easier (faster) way to update another table with new data only?
    Many thanks

    >
    This method works but is there an easier (faster) way to update another table with new data only?
    >
    Almost anything would be better than that slow-by-slow loop processing.
    You don't need a procedure you should just use MERGE for that. See the examples in the MERGE section of the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
    MERGE INTO bonuses D
       USING (SELECT employee_id, salary, department_id FROM employees
       WHERE department_id = 80) S
       ON (D.employee_id = S.employee_id)
       WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
         DELETE WHERE (S.salary > 8000)
       WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
         VALUES (S.employee_id, S.salary*.01)
         WHERE (S.salary <= 8000);

  • What is the best way to dynamically create table partition by year and month based on a date column?

    Hi,
    I have a huge table and it will keep growing. I have a date column in this table and thought of partition the table by year and month. Can any you suggest better approach so that partition will create automatically for new data also along with the existing
    data? Nothing but automatically/dynamically partition should create along with file group and partition files.
    Thanks in advance!
    Palash 

    Also this one
    http://weblogs.sqlteam.com/dang/archive/2008/08/30/Sliding-Window-Table-Partitioning.aspx
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Best way to JOIN 3 tables into internal table ?

    Hi friends,
    i have the following issue:
    i need to join information of 3 different tables ( BUT000, BUT020 and ADRC ) concerning Business Partners and i need them into one internal table.
    how would this be achieved with best performance ?
    regards,
    CL

    Hi clemens,
    As per my understanding, u can further improve this  SQL By:
    1. first select only BU000 and BU020 with inner join and then select material details in different different itabs. and process This will surely reduce load on DB and may increase load  on ABAP which u can improve by using BINARY SERARCH!.
    (Important: if u are using two table in join and giviing only PARTNER which is primary key field in both tables in WHERE clasuse ... this should be the only criteria in where clasue then i Dont think it will affect performance .... how many record may be there, this query will be BEST performer... I hope it will fetch 750000 records whithin few seconds)
    2. Generally, U try to give more and more conditions in where clause on PRIMARY KEY fiedls only and not on not KEY fields...
    3. In worst case, fetch data from three differnt tables into three different itabs and then process, this is best and last way to reduce load on DB and will increase load on ABAP which can be manages as above..
    Still u want more info .. send codes to me.. We will try to make it more and more fast....
    Jogdand M B
    null
    Message was edited by:
            Jogdand M B

Maybe you are looking for