Avoid Global Public variables...

Hello Experts,
I have declared few variables in package specification (l_test , l_test_2)and i'm using across the API procedures.
But when i run the TOAD expert it says "Avoid defining global public variables in the package specification."
So i thought of moving the code from package specification to package body...
Is this a good approach and will my code work as it was working before if i declare in the body...
Plz suggest ...
Thanks...
Earlier
Package Specification Part
CREATE OR REPLACE PACKAGE PKG_TEST
AS
l_test NUMBER(1);
l_test_2 NUMBER(2);
END;New
CREATE OR REPLACE PACKAGE BODY PKG_TEST
AS
  l_test NUMBER(1);
l_test_2 NUMBER(2);
   PROCEDURE process
   IS
   END process ;
   PROCEDURE process_2
   IS
   END process_2 ;
END PKG_TEST;

Linus,
Just so you are aware, the scope of those variables are different depending on if they are defined in the PACKAGE (SPEC) or PACKAGE BODY.
Declared in the PACKAGE (Spec): Globally accessible to everything on the Schema.
Declared in the PACKAGE (Body): Globally accessible to everything with that particular Package.
So as you can see, this quite a big difference. TOAD is warning you because putting globals in the PACKAGE is a pretty sloppy coding practice that can easily lead to difficult to maintain code. While you can ignore it, I'd suggest not doing that. ;)
In fact, I'd suggest avoiding globals altogether when possible. Passing parameters may be more time consuming, but it makes it very clear what each procedure/function should be doing, and future programmers will thank you. Time you'll save on initial programming will be made up when doing maintenance. But admittedly globals are useful, just be careful when using them. Getting your code to work isn't enough; you should aim to make it clear and understandable too.

Similar Messages

  • How to assign itemrender variables in global public variable of my applicaton.

    Hi Friends,
    How to assign internal item render values in global public variable. can u see below example.
    List have one itemrender,within the itemrender i am using data grid .The  dataGrid have itemrender.now i tried the data grid itemrender assign values to public variable of my application,but the Error came... How can u slove this Problem Any One can Help to me.
    Example:
    public var myData:arrayCollection;
    <mx:List variableRowHeight="true" dataChange="validateNow()"  width="900" id="Lst_userlist" verticalScrollPolicy="off"  horizontalScrollPolicy="off" 
         buttonMode="true">
    <mx:itemRenderer>
      <fx:Component>       
       <mx:VBox paddingTop="-5"  horizontalScrollPolicy="off" verticalScrollPolicy="off" >        
             <fx:Script>
              <![CDATA[        
               override public function set data(value:Object):void
              ]]>
             </fx:Script>
             <mx:VBox id="vbox_grid" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="890"  paddingLeft="10" paddingTop="5"
                     backgroundColor="#317152" color="#FFFFFF">        
              <mx:DataGrid visible="false" includeInLayout="false" height="100%" id="membershipGrid" alternatingItemColors="[#DCDCDC,#F8F8FF]"
                  paddingLeft="5"  horizontalScrollPolicy="off" color="black"
                  horizontalGridLines="false" verticalScrollPolicy="auto"  verticalGridLines="false"   rowHeight="25"
                  borderSkin="{null}" showHeaders="true" borderVisible="false" dataProvider="{data.dataCollection}" width="900" >
               <mx:columns>
                <mx:DataGridColumn width="180" headerText="Name" minWidth="150" sortable="true"  wordWrap="true" >
                 <mx:itemRenderer>
                  <fx:Component>
                   <mx:HBox horizontalScrollPolicy="off"   >
                    <fx:Script>
                     <![CDATA[
                      override public function set data(value:Object):void
                      function Click_Name():void
                        outerDocument.myData=data;  //  Here Error  came                 
                     ]]>
                    </fx:Script>
                    <mx:Image id="fileimg"    buttonMode="true"  toolTip="This is the User's Home Organization"/>          
                    <s:Label  id="lbl_Gridcloumn_name"  width="200" buttonMode="true" textDecoration="underline"  click="Click_Name()"  />
                   </mx:HBox>
                  </fx:Component>
                 </mx:itemRenderer>
                </mx:DataGridColumn>
    </cloumn>
    </datagrid>
    Error:
            Access of possibly undefined property myData through a reference with static  type com.istmanagement.views:ProgramAcessRights_ComponentInnerClass3.
    Thanks,
    Magesh R.

    Hi Flex harUI ,
    Thanks man....because  of i was stugle in last one week.... once again Thanks.......

  • How to declare a global/public variable in Oracle Forms

    Hi All,
    I have to get the value of a variable which is declared in the event 'When_Button_Pressed', in an another trigger with in the form.
    My variable & type
    l_db_handle EXEC_SQL.ConnType;
    This variable used to get the handle of a new database connection.
    (Here I am trying to make connection to two different databases from Form. That is working fine.)
    I have tried with Global variable to transfer this variable value to other triggers. But it is not working. It shows 'Wrong type error'
    Could you please let me know, how can I declare which DB handle variable as public in form(I mean i have to use this variable all the triggers with in the form)
    Thanking You,
    Manu

    Put the code in a package within the form, have the triggers call functions/procedures within the package. All variables which need to be referenced in more than one procedure can be created as package variables.

  • Referencing package public variables remotely

    According to Oracle 8i documentation, its not possible to reference - directly or indirectly - package global public variables remotely. This implies the construct <package_name>.<public_variable_name>@<remote_database> doesn't work. The only way possible is to create public functions in the remote package to return the value of the variable. (e.g. function return_variable return <public_variable_name>%type is begin return <public_variable_name>; end;)
    Can anyone please confirm this, otherwise suggest any other simpler way of accessing remote package variables?
    Thanks.

    Rahul,
    No unfortunately you can't get at them, nor can you get any constants. It sure would be a good thing if you could, but I use the following to get around this problem as getting global variables and constants is a very important thing. This method I've shown below actually works pretty slick and it uses a remote function and a view to get the job done.
    I actually like how this works better than calling a variable/constant directly. The example below I just did up, but it shows the basic idea. Basically you put a number beside your var/const as a comment marker. I usually use a sequence to keep track of the numbers I've assigned. A test package was made that has 1 variable and 1 constant. A function is made that gets these values. A view is made that calls this function and returns ALL of the variable and constant values. You can take this even further and have it return the actual variable/constant name itself as well.
    I like doing it this way as you now only have ONE entry point (the view) to get as many variables/constants as you like, even if spread across multiple packages. I have my own code that does all of this, but the example below gives you an idea of how to make one yourself. Remember this is just a simple example, you can make it so you don't have to do the union in the view, and you can make the function return more things if you like, but I'm kinda short on time so my example is pretty simple, but it works quite well.
    The following is from the Oracle docs telling you about trying to get remote values ...
    --[START]
    http://otn.oracle.com/docs/products/oracle9i/doc_library/901_doc/appdev.901/a88876/adg10pck.htm#2501
    Remote Procedure Calls and Parameter Values
    You must explicitly pass values to all remote procedure parameters, even if there are defaults. You cannot access remote package variables and constants.
    --[END]
    Ok here's the code and some output ...
    --[START]
    CREATE OR REPLACE PACKAGE PKG_TEST
    AS
    --[NOTE] : see the comment number markers below, these stay fixed even though they are just comments
    GI_VAR_ONE NUMBER := -100; --[1]
    GI_CONST_ONE CONSTANT NUMBER := -200; --[2]
    END;
    Package created.
    CREATE OR REPLACE FUNCTION FN_TEST(VAR_POSITION NUMBER)
    RETURN NUMBER
    AS
    LI_RETURN NUMBER := 0;
    BEGIN
    IF VAR_POSITION = 1 THEN
    LI_RETURN := PKG_TEST.GI_VAR_ONE;
    ELSIF VAR_POSITION = 2 THEN
    LI_RETURN := PKG_TEST.GI_CONST_ONE;
    END IF;
    RETURN LI_RETURN;
    END;
    Function created.
    CREATE OR REPLACE VIEW V_TEST
    VAR_POSITION,
    VAR_VALUE
    AS
    SELECT 1,FN_TEST(1) FROM DUAL
    UNION
    SELECT 2,FN_TEST(2) FROM DUAL;
    View created.
    SELECT * FROM V_TEST;
    VAR_POSITION VAR_VALUE
    1 -100
    2 -200
    begin
    PKG_TEST.GI_VAR_ONE := -123;
    end;
    PL/SQL procedure successfully completed.
    Commit complete.
    select * from v_test;
    VAR_POSITION VAR_VALUE
    1 -123
    2 -200
    --[END]
    Enjoy :)
    Tyler D.

  • Dealing with a turn based application with using a global static variable

    Hi there. I read some articles about JavaFX concurrency,so as a newbie i have to practice on it. Now i'm trying to implement a turn based application that can be played among 3-6 players. Moreover, i use a scene imported from a .fxml file and i have to update it correctly depends on some calculations of each thread (in other word players ). My main issue is, i don't wanna use a while loop which checks the state of game like;
    while( GameState != State.GAME_OVER ){
         currentPlayer = GameBoard.getNextPlayer();
         // do some actions,calculations etc.
    So, i want to use worker threads instead of this while loop. I guess using Service class for iterating and assigning the next player will be suitable instead of using the while loop and Tasks for doing each player's calculation,or waiting for some responses from Human players on UI based,however, i'm struggling with two problems.
    There should a global static variable ( like GameState which is an Enumarator ) determines the state of the game,so it should be updated and should be checked by each turn. Is there any way to do this ?
    How can i get rid off this while loop ?
    I will appreciate for every answer. Thanks anyway.

    It shouldn't make too much difference. The basic idea is that you have a model class representing your game state (the Game class in jsmith's example). When a player makes a move, you update the state of the game. Since this will result in changes to the UI, this update should be performed on the FX Application Thread.
    If the player making the move is a human player, the move will likely be made by a user action (button press or mouse click, etc); this will be handled on the FX Application thread anyway.
    When the state of the game changes so it is the turn of an "artificial" player to make a move, have the object representing the artificial player calculate its next move, and then update the game state. Since this is a response to the game state changing (it's now the turn of the artificial player), this will also be on the FX Application Thread.
    The only (slight) complexity comes if the calculation of the move for the artificial player takes a long time. You don't want to perform this long running calculation on the FX Application Thread. The cleanest way to manage this is to launch a Task which calculates the desired move, and then updates the game state when the move is ready. So, something like this:
    GameState game = ... ;
    // UI is bound to the game state.
    ExecutorService executorService = ... ;
    final Player currentPlayer = game.getCurrentPlayer() ;
    final Task<Move> calculateMoveTask = new Task<Move>() {
         @Override
         public Move call() {
              Move move = // compute next move...
              return move ;
    calculateMoveTask.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
         @Override
         public void handle(WorkerStateEvent event) {
              gameState.makeMove(currentPlayer, calculateMoveTask.getValue());
    executorService.submit(calculateMoveTask);
    If you're doing more threading than that, you're probably doing it wrong... . There should also be no need for anything to be held as a "global" static variable (the idea above is the only structural modification you need to the example posted by jsmith).

  • Global Application variable

    How do I set a global application variable in a Swing application?
    Namely
    MDI display opens a new window
    new window sets a variable
    close the new window and return to the MDI window
    MDI window needs to use the variable.
    Note: the new window is is its own class object.

    What are you talking about?
    Static variables are "global".
    In some class (it does not really matter which) define
    a static variable. O.K. now you have a "global"
    variable.
    Some people may say that this is "bad" programming
    practice, but it is what you asked for.public static variables of public classes are 'global' in the sense you can refer to them if anywhere in an application. Public classes are also 'global' in this sense.
    However, we don't call them global variables, they are class variables. A global variable is generally defined to be one that is associated with the running application. It has no context other than that. It can be used anywhere at any time without any qualifications. In other words, the are terrible.
    I had to maintain an application that had 50 or so global variables. Some of these variables represented the exact same piece of information so it was cruicial during modifications to make sure that they were kept in sync. Don't use this type of design.

  • How do I set a public variable in a native ActiveX DLL using Java?

    Hello,
    I have run into an issue that I cannot seem to find any documentation on, and all of my efforts with search engines have returned no useful results.
    Here is my situation:
    I have an Active X DLL that has a very simple configuration, but it is a third party DLL which I cannot modify. To interface with the DLL I have to set a series of public variables and then call a method with no parameters that will use the current values of the variables to perform a calculation. There are no "set" or "get" methods.
    At this point I have a very good idea about how to use JNI to create the class in java, and call the method. However, this does me no good at all if I cannot set the variables.
    Everything I have found so far defaults to an assumption of no direct access to variables, and that getter and setter methods would be available for that purpose. Anyone know of a way that this might be handled? I would provide source code, but it seems useless unless I know how to actually do this.
    Thanks in advance for any input.

    OK. Those are OLE/ActiveX/COM/WhateverTheyCallIt getters and setters, that VB makes look like object 'properties'.
    If you are familiar a bit with C#, they also have 'properties', which are getters and setters hidden behind a syntax that makes them look like member variables.
    I am affraid my help has to stop here, as I don't remember COM anymore.
    But, unless you find someone who really knows COM, you will have to investigate by yourself.
    One suggestion though: open a C++ project in VisualStudio 2005 or 2008 (not Express, it seems not to support what I describe).
    Go to something like References or Add Reference and you will see a tabbed dialog box with a COM tab (I describe all this from memory).
    Add your DLL. After this do View->Object Browser or alike. It should show your COM object. You will be able to examine its methods and properties.
    I think Visual Studio canl generate code for invoking them. This is the C code that somehow you should take from there and place in your JNI code.
    Edited by: baftos on May 9, 2010 11:22 AM
    Correction: VS2008 Express also supports this, but to get there, you do View->Object Browser->Click the "..." button->COM tab.
    VS2008 Express is free.
    Edited by: baftos on May 9, 2010 11:25 AM

  • Public variables in javascript

    how i can use public variables in javascript along with ADF. I am declaring a variable at the top of list but when an event is generated by ADF and i tries to access that variable, it gives me an error of undefined.
    Kindly help me

    Not directly, but you can with this:
    http://java.sun.com/products/plugin/1.3/docs/jsobject.html
    See also:
    http://www.codeproject.com/jscript/javatojs.asp?df=100&forumid=736&exp=0&select=700857

  • Using public variables in a servlet

    Hi, I have a public variable "CustID" in my servlet. Note that is a public member variable and not a static variable.
    In the doPost() method, I am trying to use the custId field.
    Pls. look at the code below. I want to know that in a multi-user environment since the custId field is defined at Servlet level as a member variable, is there a chance for this variable to be corrupted and I fire a wrong query ???
    Awaiting your answers
    public class QWCustomerServlet extends HttpServlet
    public boolean debug = false;
    public QWFieldList fieldList = new QWFieldList();
    public String custID = null;
    public doPost(HttpServletRequest req, HttpServletResponse res)
    HttpSession session = null;
    if ( (session = request.getSession(false))!= null){ 
    custId = session.getAttribute("cid");
    String query = "select * from customer where cust_id=" + custId;
    Statement stmt = conn.createStatement();
    stmt.executeQuery(query);
    }

    Yes. There is only one instance of a servlet and all requests thread through it. Don't use instance variables unless you want all threads to share (usually in a read-only manner such as a reference to a resource). In your example, move the custId declaration inside doPost and it will be thread-safe.

  • Accessing public variables

    I have the code below. What I am trying to do is to print out
    the value of a public variable. I am trying to change that public
    variable in the function that handles the result of the remote
    object call. The problem is the value only seems to change in the
    function and no where else. Any ideas?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="load_list()">
    <mx:script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    public var material1_ID: int;
    public function load_list():void{
    material1_ID = 0;
    public function addRec():void{
    Alert.show('value before' + material1_ID.toString());
    insertService.addMaterial('123'); // THis calls my webservice
    and returns a query
    Alert.show('value after' + material1_ID.toString());
    public function addMaterial(event:ResultEvent):void{
    material1_ID = 9;
    ]]>
    </mx:Script>
    <mx:RemoteObject
    id ="insertService"
    destination="ColdFusion"
    source ="insert"
    >
    <mx:method name="addMaterial" result="addMaterial(event)"
    >
    </mx:RemoteObject>
    </mx:Application>

    This function in your code:
    public function addRec():void{
    Alert.show('value before' + material1_ID.toString());
    insertService.addMaterial('123'); // THis calls my webservice
    and returns a query
    Alert.show('value after' + material1_ID.toString());
    Looks to me like you are making the remote call and then
    expecting the next line to access the result. Flex doesn't work
    that way. Remote calls (including HTTPService and WebService) are
    asynchronous. When you make the addMaterial call, the request goes
    out and the response comes back "later". So right after that
    request the value won't be changed.
    If you print the value in the result handler, you'll see that
    it will be changed.

  • Global Container Variable

    Hi
    Give me idea on Global Container variable in Graphical mapping.
    Thanx in Advance

    Hi
    Ref this
    /people/sravya.talanki2/blog/2005/12/21/use-this-crazy-piece-for-any-rfc-mapping-lookups
    http://help.sap.com/saphelp_nw04/helpdata/en/95/bb623c6369f454e10000000a114084/content.htm
    Design and Configuration [original link is broken]
    Thanks
    Sridhar

  • Global Constants / Variable in OSB

    I want to define global Constants / Variable in OSB and I want to access them in XSLT when I am tranforming the requests...
    Any idea how can I do that?
    I want to use these variables and constants for server name and ports (in different environment) and some other stuff.

    We have done a similar implementation for the same scenario. We have created a Xquery where we put in the configuration information as an XML and then in the pipeline stages we use the Assign the Xquery to a a temporary variable and then use the values of the xml using relative xpath expressions.
    This way any time we need to make any changes to the confguration we know once place we can change and it gets reflected in the complete code base.
    Below is how we have done it:
    - create a Xquery with xml configurations (say commonconfig.xq)
    - then using the Assign action get the output of this xquery into a temp var (say commonConfig)
    - then use the configurable values using the relative xpath in the Assign action (say Assign $commonConfig/param1/text() to param1Value
    Let me know if you need further information.
    Thanks,
    Patrick

  • Global Counter Variable - Graphical Mapping

    Hi there.
    Can anybody help with implementing a global counter variable in the graphical mapping please.
    I am trying to populate the "SEGMENT" field of an IDoc with the correct sequence, i.e. add 1 for each new segment. The IDoc has several segments, most of which are embedded. I have tried using the "<b>counter</b>" function but this seems to reset back to one for each instance of it being called.
    I would appreciate any pointers.
    Thank you.
    Mick.

    Hi see this for implementation
    <b>defining Global Variables</b>
    ArrayList arrVI;
    int counter =0;
    <b>Initialization Section</b>
    arrVI= new  ArrayList();
    <b>assignment</b>
    arrVI.add(sVI[iLoopCounter]);
    counter++;
    <b>
    fetch Values</b>
    for (int i =0;i<counter;i++)
    result.addValue(arrVI.get(i)+"");
    Mudit

  • How to avoid creating a variable to store a temporary value

    This is an artificial example, but it best illustrates what I am trying to do:
    I could create a local variable whose scope doesn't extend beyond the step, but I'd like to avoid that local variable clutter. Or I could dynamically create and delete properties in post expressions, but that would lead to variable names that are invalid at edit-time.  Or I could create a custom Sequence Call step type with a custom subproperty to hold the temporary value, but that is not a very generic solution.
    But really, I'd like to just have two expressions I could use in the sequence Parameter and the Custom Condition that somehow each point to the other, to keep the rest of the step configuration as clean as possible (although the two expressions I am seeking may end up being more complex than the alternatives).  Is this possible?  I think it may be, but I can't figure it out.  One of the alternative solutions wouldn't kill me, but the solution I have in mind would be nicer!

    What you have seems to be the most clear solution to this.  For the dynamic case, if you are worried about errors, you may want to use #NoValidation.  Here's a paragraph from the linked document about using #NoValidation.
    http://zone.ni.com/reference/en-XX/help/370052K-01/tshelp/infotopics/2012whatsnew/
    You can now use the #NoValidation directive in an expression to disable evaluation error checking for part or all of the expression. Use this directive to suppress errors reported at edit time that will not occur at run time, such as using a variable the sequence creates at run time by using the TestStand API. Use this directive without a parameter list to suppress error checking for the remainder of the expression or pass a separate expression as the parameter to this directive to suppress error checking for only the parameter expression.
    Jesse S.
    Applications Engineer
    National Instruments

  • Comma problem with global string variable

    Hi,
    I'm fiighting with comma problem for global string variable. I've on page string for example "7nndqrr52vzyb,0" and by dynamic column link I'm assigning this string to global variable. Then I'm trying to display value of that global variable on another page but I see only string till comma, nothings more. I'm not sure what I'm doing wrong because when I'm trying to assign that value normally by computation process as a constant value is fine and see on another page correct string. I'll be really glad for help.
    Thanks
    Cheers,
    Mariusz

    When it tries to display the string, it sees the comma and wants to believe the string is terminated. You could escape the , in the string or replace it with a different character..
    See this link: http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/concept.htm#BEIGDEHF
    Thank you,
    Tony Miller
    Webster, TX
    If vegetable oil is made of vegetables, what is baby oil made of?
    If this question is answered, please mark the thread as closed and assign points where earned..

Maybe you are looking for