<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: HANA Procedure - Cyclic Dependency Error - disable trigger, perform update, enable trigger in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/hana-procedure-cyclic-dependency-error-disable-trigger-perform-update/qaa-p/338122#M12703</link>
    <description>&lt;P&gt;A workaround for the from my point of view misleading error is to execute the insert statement in your procedure as dynamic sql too.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  
  ...
  begin
    exec 'alter table zh_trigger_test disable trigger';
    
    exec 'insert into zh_trigger_test select round(rand() * 100) from dummy';
      
    exec 'alter table zh_trigger_test enable trigger';
  end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;BR /&gt;Florian&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2016 08:03:19 GMT</pubDate>
    <dc:creator>pfefferf</dc:creator>
    <dc:date>2016-11-22T08:03:19Z</dc:date>
    <item>
      <title>HANA Procedure - Cyclic Dependency Error - disable trigger, perform update, enable trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-procedure-cyclic-dependency-error-disable-trigger-perform-update/qaq-p/338121</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Synopsis&lt;/STRONG&gt;: &lt;EM&gt;A 'Cyclic dependency' error is encountered when calling a procedure that disables a trigger, performs an update on a table, enables a trigger.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Steps to reproduce:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select version
    from m_database;

VERSION
1.00.112.00.1457525470

-- 1) Create a table:
create table zh_trigger_test (
  val integer
);

-- 2) Create a trigger on that table:
create trigger trg_zh_trigger_test
  before insert or update on zh_trigger_test
  referencing NEW ROW as new
  for each row
  begin
    declare l_hit_count int;
    
    select count(*) into l_hit_count from dummy;      
  end;


-- 3) Create a procedure to insert a record into that table:
create procedure zh_cyclic_test
  language sqlscript as
  begin
    execute immediate 'alter table zh_trigger_test disable trigger';
    
    insert into zh_trigger_test
      select round(rand() * 100) from dummy;
      
    execute immediate 'alter table zh_trigger_test enable trigger';
  end;

-- 4) Call procedure:
call zh_cyclic_test;
Could not execute 'call zh_cyclic_test' in 6 ms 246 µs . 
[129]: transaction rolled back by an internal error: "ATLAS"."ZH_CYCLIC_TEST": line 4 col 5 (at pos 71): [129] (range 3): transaction rolled back by an internal error: Cyclic dependency found in a runtime procedure: Not allowed to call/modify runtime procedure ATLAS.ZH_CYCLIC_TEST during its execution 

-- 5) Cleanup:
drop table zh_trigger_test;
drop procedure zh_cyclic_test;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this situation, the trigger needs to be disabled before performing a bulk update on the table because it basically crashes the database otherwise (separate issue). In a purely theoretical world, I can see how altering a table that a procedure depends on during the execution of that procedure could cause issues, however in this scenario we're simply disabling or enabling a trigger. Do we really need to drop and recreate the trigger, or possibly have a "trigger status" table that controls whether a trigger should act or not?&lt;/P&gt;&lt;P&gt;This would seem to be a common data warehousing operation, possibly more common with indexes.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 18:52:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-procedure-cyclic-dependency-error-disable-trigger-perform-update/qaq-p/338121</guid>
      <dc:creator>former_member229185</dc:creator>
      <dc:date>2016-11-21T18:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: HANA Procedure - Cyclic Dependency Error - disable trigger, perform update, enable trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-procedure-cyclic-dependency-error-disable-trigger-perform-update/qaa-p/338122#M12703</link>
      <description>&lt;P&gt;A workaround for the from my point of view misleading error is to execute the insert statement in your procedure as dynamic sql too.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  
  ...
  begin
    exec 'alter table zh_trigger_test disable trigger';
    
    exec 'insert into zh_trigger_test select round(rand() * 100) from dummy';
      
    exec 'alter table zh_trigger_test enable trigger';
  end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;BR /&gt;Florian&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 08:03:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-procedure-cyclic-dependency-error-disable-trigger-perform-update/qaa-p/338122#M12703</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2016-11-22T08:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: HANA Procedure - Cyclic Dependency Error - disable trigger, perform update, enable trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-procedure-cyclic-dependency-error-disable-trigger-perform-update/qaa-p/338123#M12704</link>
      <description>&lt;P&gt;The master of hacks missed this one. Thanks Florian!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 17:37:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-procedure-cyclic-dependency-error-disable-trigger-perform-update/qaa-p/338123#M12704</guid>
      <dc:creator>former_member229185</dc:creator>
      <dc:date>2016-11-23T17:37:23Z</dc:date>
    </item>
  </channel>
</rss>

