Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
Since the release of Enterprise version, the components of a package (be it a data type, a variable, a class, or any other component) is not accessible outside the given package, unless and until we include that package in the hierarchy of other packages. However, this necessarily means we allow access to all the components of a package from the destination package. In some of the business critical applications, it may sometime be required that we don’t allow access to all the components outside a given package, but make only some of the components visible outside it. To achieve this we can make use of the concept called USE ACCESS. Let us have an example to understand the concept better. Consider a package named ZVIN containing the following components:

                        Dictionary Objects:
                                    Data Elements:
                                               zdet TYPE test
                                               zdet1 TYPE myAttribute
                                    Structures:
                                               zseg1 TYPE zsegment
                                   Domain:
                                               zdomain TYPE test
                                   Database Tables:
                                               stable TYPE tabletype1
                        Class Library:
                                    Classes:
                                               classA TYPE REF TO myclass1.

Suppose, the class named classA present in the above package contains business critical logic and hence cannot be exposed to the outside world. However, other elements present in the package, say any other class or other components like zdet1, zseg1, zdomain etc, may or may not be required in other packages. To solve this problem, one way is to define a completely different package and include these reusable components in it. Include the newly defined package in the package hierarchy of ZVIN and also at all places wherever these components are required. However, if these components are not used anywhere else, then the declaration of the new package is just an overhead. To avoid this overhead, we can instead expose the selective components from the package interface of ZVIN only. Basically, each package has three attributes:
  • Nesting:

    The ability of a package to include other packages within the package hierarchy.

  • Visibility:

    A package element can only be visible to outer world if it is included in one of the Package Interfaces.

  • Use Access:

    To access elements of some other package, any given package needs to call respective Package Interface of that particular package. The data element(s) to be accessed from the package should be part of the package interface.

Since we have already ruled out the use of first attribute to prevent unnecessary overhead, let us try to understand the later two through the example mentioned below. We click on the package ZVIN. Tab strip item corresponding to Package Interface is selected and a new package interface ZVIN_P1 is created by clicking on Add button as shown in the Screen Shot 1 below. Screen Shot 1Once the package interface is created, we include all the components of the package that needs to be exposed to the outside world in it. To include elements in the package interface, double click the interface. Click on Add button and select the element (s) that needs to be part of this interface. Once elements are included, these will then be visible in the interface as shown in the Screen Shot 2 below: Screen Shot 2.Now to grant permission to any other package say, ZVIN1 to use this interface, go to tab strip item Restriction on user packages and include package ZVIN1 there. This interface ZVIN_P1 will now serve as a window to the package from the outside world. However, if we somehow try to use any of the elements of this interface directly, it will still give the error as shown in the Screen Shot 3 below: Screen Shot 3.To avoid this error, we have to create a use access for the package ZVIN1. For creating the USE ACCESS, double click on the package ZVIN1, select the tab strip item for Use Access and click on Create button. Below mentioned screen thus appears. Enter the name of package interface as ZVIN_P1 (the one created in package ZVIN) and click Ok. Screen Shot 4.Now if we try to use the elements of the package ZVIN, we can do it without any errors. If the access should only be given to some of the packages only, then list all those packages in the respective package interface. This means, if we don’t list the package ZVIN1 in the Restriction on user packages tab strip of ZVIN_P1, we get the error while accessing it in Use Access of ZVIN1 as shown in the Screen Shot 5 below. Screen Shot 5.Hence we can expose only selective components of a package outside it that too only to selective packages outside its own boundary. This way we can control accessibility of the components of a package as well as reuse them at selective places.

Thanks to Debasish Pattnayak and Vineet Popli for helping me explore and implement this concept.

3 Comments