Document directory
- The idea
- The variable-Interface
- Conclusion
If you want to control the processing of ex-queries you can define different types of variables: manual entry/default value, replacement path, SAP exit, authorization or customer exit. this blogs deals about how to define such variables and how you can
Develop them by using ABAP objects.
Introduction
For implementing customer-exit variables you have to implement the extension rsr00001 in the transaction smod. There have been some sort ents about it, like
Http://scn.sap.com/docs/DOC-26617.
The used customer-exit has to following interface-definition based on the function module exit_saplrrs0_001:
The parameters have the following meaning
- I _vnam: name of the Variable
- I _vartyp: Type of the Variable
- I _iobjnm: used infoobject
- I _s_cob_pro: structure with the properties of this infoobject
- I _s_rkb1d: structure with the properties of the executed Query
- I _periv: current fiscal-Period
- I _t_var_range: selected values of the variablen Screen
- I _step: processing step
- E_t_range: result-selection of the Variable
- E_meeht, e_mefac, e_waers, e_whfac these fields are not used!
- C_s_customer: Structure with steering data
The processing of the variable will be managed by the importing parameter I _step. each step represents a specific point in the processing of a variable screen. the following dimo-shows the several options. the green check marks means an error-free proceeding
And the red bolt means an error is raised by an exception.
For your own variables you will have to program in ABAP your extension and interpret the parameters. This behaviour will be discussed here:
Now-if you want to implement Customer-exit variables, you will have several options:
1. Implement directly in the include zxrsru01, as it is shown in the SAP help. Using this way, you will have a very fast implementation, but the price will be very high:
- Every user of exit-variables will have to change this include. The main disadvantage of this approach is the fact, that each modification of this peace of code will influence all users of exit-variables.
- An error in this include leads into an error for each report with exit-variables.
- Tracing and debugging will be very difficult because you will have to look about the whole source code.
- Some more...
2. encapsulate your exit-variables. e. g. use function modules or classes for building your user-exit variables. as we are in 2012, I will show a framework with ABAP objects, which makes it very easy to implement Bex merexit variables.
By using this approach, you will gain a lot of features, without dealing with them directly:
- Minimal effort for new variables through inheritance.
- Type-safe and clear structure for variables.
- No coding dependencies between different variables.
- No redundant parameters while step-processing.
- You can see at anytime, which coding implements a variable.
- Tracing and debugging will be very easy, through a clear structure.
The idea
The idea is quite simple: Just say, every variable is a instance of a class. every instance must support at least the following events of the processing-cycle (in brackets, I write the "old" abbreviation ):
-Initialization
-Before variablescreen (I _step = 1)
-After variablescreen (I _step = 2)
-Authority check (I _step = 3)
-Check (I _step = 0)
Now, put this events in methods of an interface. Why using a interface? I often talk about a contract, when building dynamic systems with ABAP oo based upon interfaces, because both partners (client and Service) can rely on it. If a class implements
Interface, every client can be sure, that this interface will be fulfilled by its specification.
In the following, I will show, how easy it is to encapsulate exit-variables with ABAP objects. You will need at least these classes:
- A factory for creating and managing variable instances
- An variable interface, which defines the methods of the Variable Processing
- A Abstract variable for building the first node in your variable hierarchy
- Concrete implementations of the variable Interface
Look at the UML digoal. the central element is the variable interface, which will be implemented by an abstract class and used by a factory. the used function-pool has been inserted due to the example-class later.
The factory used here based upon the pattern, which I have discussed in
Http://scn.sap.com/community/abap/application-development/objects/blog/2012/02/20/factory-pattern-in-abap-oo. At least, the implementation pattern for the Bex-variables is the so-called "strategy-pattern ".
I suggest the usage of an abstract class from which every concrete variable shoshould inherit. With this construction, you will gain more flexibility and can reuse a of Lot coding.
The variable-Interface
The interface shoshould looks like this:
Every method of the interface encapsulate a step in the variable-processing. But the main difference is the fact, that every method has only those parameters which are needed in this step.
Now you can see what is the big advantage of using this strategy: At least you have a simple but powerful method signature for each processing step. if you develop a new variable you do not have to consider about "I _vnam", "I _step" and those other parameters,
Because the method signature has been optimized for each step!
Customization
By using the described factory-oo-pattern, you will have to define a customing table, which holds all implementation classes for the variables. in this table, you can define foreign-keys to the table rszglobv where all variables are stored. with this key,
You can ensure, that only variables of type "customer-exits" are entered and you can ensure, that only classes with a valid interface are used-. (OK, this check have to be built by another view/search-help ).
By the way: Do you know who and how are your customizing-exit-variables are implemented within your system? Even if you have function modules and select them at runtime-you do not know exactly where they are and if they are existing. With oo-approach,
You can even ensure this at design-time!
Implementation in rsr00001
The implementation in the corresponding user-exit include is even quite easy:
As you can see, the coding in the include is very small and does not include any application specific coding.
At least, it is in the responsibility of each project to define and test the correct variables. But: No variable can destable the whole system!
If you have already an encapsulation, I will suggest that you only create the new variables with this new approach and only changes in existing exit-code will be migrated.
Example
The following class will show, how you can build an implementation class for a customer-exit variable. in my example, I need a customer-exit for determining the last day of the first quarter of the selected year. this exit has to be processed after the variable
Screen have been executed and the user inputs the selected year.
First, you will have to define your variable in the Bex-querydesigner-because without this definition, no entry will be made in the rszglobv-table and we use this for our customizing.
After this, you need to create a new class which implements the interface zif_biu001_variable. In the described framework, I implemented an abstract class, do this for me and give me some supporting features.
Then you have to redefine the method "after_variable_screen" of the corresponding interface:
In this method you implement your desired functionality. when you look at this code you will discover that it is very short and does not handle to much interaction with the classical ex-customer-exit interface. so, you can get a clean and stable implementation
For Bex-customer-exit variables.
The last step for using this variable is the customizing in the customizingtable above.
In one of my future blogs, I will show, how you can tests these variables with abapunit.
Conclusion
In this blog, I show how easy it is to implement Bex-user-exit-variables with ABAP objects. The here shown framework will bring up some very important features:
- A more use-case centric development. for those you will have to implement a user-exit, it will be easier to say "the variable have to been executed {before | after} the variables popup" instead of the classical "I _step"-handling
- Tracability: You can very easy track and debug each variable without having to much effort.
- Easy-enhancements: use an abstract class and inherit from this and you will have your new variable.
- Inherit different features for similar use-cases. Through a implementation hierarchy, You can reuse a lot of coding in similar variables.
- Using other patterns like proxy and adapter bringing new aspects to your variables. For example: Tracing-proxy or authority-proxy.
- Unit-testing with ABAP unit. No more to say: using a "variable-class", it will be very easy to build up a unit-test for this variable.
The coding examples, I have shown here and the framework itself has been published at the codeexchange project "Bi-utils ". in the future, I plan to publish some more nice tools in this context.