zdet TYPE test
zdet1 TYPE myAttribute
zseg1 TYPE zsegment
zdomain TYPE test
stable TYPE tabletype1
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:
The ability of a package to include other packages within the package hierarchy.
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 dont 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.