# Code Analysis - Rule 6407: Ensure item is defined in as deep a scope as possible.

**URL:** <https://forums.toadworld.com/t/code-analysis-rule-6407-ensure-item-is-defined-in-as-deep-a-scope-as-possible/35221>\
**Category:** Toad for Oracle - Beta\
**Created:** [March 7, 2016, 12:21am UTC](https://forums.toadworld.com/t/code-analysis-rule-6407-ensure-item-is-defined-in-as-deep-a-scope-as-possible/35221 "2016-03-07T00:21:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterLang](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@PeterLang](https://forums.toadworld.com/u/PeterLang)\
**Post date:** [March 7, 2016, 12:21am UTC](https://forums.toadworld.com/t/code-analysis-rule-6407-ensure-item-is-defined-in-as-deep-a-scope-as-possible/35221/1 "2016-03-07T00:21:26Z")

</div>

I am trying to clean my code with Code Analysis so I also try to get rid of false positives.

This is a way to reproduce one:

CREATE TABLE test\_table( test\_table\_id NUMBER );

CREATE PACKAGE BODY test\_package  
AS  
TYPE t\_test IS RECORD(  
**test\_table\_id test\_table.test\_table\_id%TYPE – Rule 6407: Ensure item is defined in as deep a scope as possible.**  
);

PROCEDURE test\_me AS BEGIN  
UPDATE test\_table SET **test\_table\_id** = 1 WHERE 1=1;  
END;  
END;

---

<div class="post-metadata">

**Author:** ![avergison](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/avergison/32/66_2.png) [@avergison](https://forums.toadworld.com/u/avergison)\
**Post date:** [March 7, 2016, 1:49am UTC](https://forums.toadworld.com/t/code-analysis-rule-6407-ensure-item-is-defined-in-as-deep-a-scope-as-possible/35221/2 "2016-03-07T01:49:51Z")

</div>

CA thinks that the test\_table\_id type would better be created _inside_ the test\_me procedure, as it is only used there. Proof: if you clone test\_me to test\_me\_2 then the warning will go away.

Perhaps we could drop it for types… What are your thoughts?

Thanks,

Andre

---

<div class="post-metadata">

**Author:** ![PeterLang](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@PeterLang](https://forums.toadworld.com/u/PeterLang)\
**Post date:** [March 7, 2016, 2:39am UTC](https://forums.toadworld.com/t/code-analysis-rule-6407-ensure-item-is-defined-in-as-deep-a-scope-as-possible/35221/3 "2016-03-07T02:39:40Z")

</div>

Thanks for looking into this.

I don’t think that this is true, the code below also shows the same violation.

Also, if the type has a problem the type name is highlighted, not the first member - also visible in the example below, and also wrong, unfortunately 😉

CREATE TABLE test\_table( test\_table\_id NUMBER );

CREATE PACKAGE BODY test\_package  
AS  
TYPE t\_test IS RECORD(  
test\_table\_id test\_table.test\_table\_id%TYPE – Rule 6407: Ensure item is defined in as deep a scope as possible.  
);

FUNCTION get\_test  
RETURN t\_test  
AS  
BEGIN  
RETURN NULL;  
END get\_test;

PROCEDURE test\_me AS BEGIN  
UPDATE test\_table SET test\_table\_id = 1 WHERE 1=1;  
END;  
END;

---

<div class="post-metadata">

**Author:** ![avergison](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/avergison/32/66_2.png) [@avergison](https://forums.toadworld.com/u/avergison)\
**Post date:** [March 7, 2016, 2:46am UTC](https://forums.toadworld.com/t/code-analysis-rule-6407-ensure-item-is-defined-in-as-deep-a-scope-as-possible/35221/4 "2016-03-07T02:46:56Z")

</div>

You’re right, I should have used t\_test. Let me look into this…
