2015 Sep 15 3:03 PM
Hi,
I do have a bunch of classes, which are very similar. All this classes will have a bunch of method, which will have the same name and work similar processes. I'd like to bundle the methods into an interface. The problem is: Each implementation of this methods will get different importing-parameters.
How do I solve that? Type ANY? Or many optional importing parameters, to cover all possible implementations?
2015 Sep 15 3:17 PM
Hi Ralf,
this mecanism called in another languages Overloading, but ABAP does not provide this, but there is alternative to achieve this as you mentioned above, you have 2 options or you can use both, Tye any or optional parameters.
Regards
Ebrahim
2015 Sep 15 3:17 PM
Hi Ralf,
this mecanism called in another languages Overloading, but ABAP does not provide this, but there is alternative to achieve this as you mentioned above, you have 2 options or you can use both, Tye any or optional parameters.
Regards
Ebrahim
2015 Sep 15 3:36 PM
2015 Sep 15 4:55 PM
Would it be too strange, to define a public attribute in each class (not in the interface), which has the same name in each class, but a different type and the implementations of the interface could read this attribute (instead of getting an import parameter)?
2015 Sep 15 6:37 PM
it is really a good idea, each class has a public attribute with same name but different type.
the interface can access this attribute. My opinion , It is better than a method with optional parameters.
Regards
Ebrahim
2015 Sep 15 7:08 PM
You don't want to tell me, that I am the first one with this idea. I am sure, someone invented that, years ago an this way solving this problem has a name
2015 Sep 15 7:37 PM
I told you it is a good idea, but really I have studied at university and I have programmed, but this idea ( ist mir nieeeee eingefallen) .
so what can I say, I have learnt something new from you, Respect
2015 Sep 16 7:41 PM
You can also make the parameter as private and create a Setter, it would centralize the way you pass the data to the class.
Regards,
Felipe
2015 Sep 15 10:12 PM
Hi Ralf,
We have solved this when building a new application framework by using interfaces for both the classes (A) which implement the business logic and also the interface parameters (B) itself. E.g. instead of passing a structure to the methods of (A) we used classes implementing another interface that has generic setter and getter methods and allow to store the data which needs to be passed (you can have a look at class CL_FPM_PARAMETER from WDA UI as reference for this).
Hope this helps!
Best regards,
Alej
2015 Sep 16 8:32 AM
With SAP's coding, it's all the same. Class not documented, Interface not documented, Components not documented, no documentation at all.
So I have to ask: I don't really understand this. There is a class which implements an interface, which has set- and get- methods to maintain and read the content of mt_parameter. This table seems to have no sense at all, because there are only the content maintaining methods.
Perhaps you can get me more into it....?
2015 Sep 16 7:07 PM
Hello Ralf,
the class uses data references to store *everything* in its parameter list. A documentation for this technique can be found in SAP-Help via http://help.sap.com/saphelp_nw70/helpdata/en/14/11e70b0c5c11d3b9350000e8353423/content.htm?fullscree....
I will try to explain this in short…
The Type of mt_parameter is the following:
types:
BEGIN OF s_parameter,
key TYPE string,
value TYPE REF TO data,
END OF s_parameter .
Here you can see the special typing „TYPE REF TO data“ of field value. This is a so called data reference. Such fields can store pointers to any other variables (simple fields, structures, internal tables, object references, …). Data references can be created via statement GET REFERENCE OF and are accessed via ASSIGN with addition „->*”.
The other field in MT_PARAMETER is key. The class uses it to identify each data reference and allows to access it via GET_VALUE method.
Here you can see a short sample report:
DATA: lr_parameter TYPE REF TO cl_fpm_parameter,
lt_mara_input TYPE STANDARD TABLE OF mara,
lt_mara_output TYPE STANDARD TABLE OF mara.
SELECT * UP TO 10 ROWS FROM mara INTO TABLE lt_mara_input.
CREATE OBJECT lr_parameter.
lr_parameter->if_fpm_parameter~set_value(
EXPORTING
iv_key = `MaterialList`
iv_value = lt_mara_input
).
lr_parameter->if_fpm_parameter~get_value(
EXPORTING
iv_key = `MaterialList`
IMPORTING
ev_value = lt_mara_output
).
For your requirement, I would suggest to use a class or interface similar to CL_FPM_PARAMETER as method parameter.
The application that calls your method needs to create an object of CL_FPM_PARAMETER and uses SET_VALUE method to fill it with the variables. Your method can then use GET_VALUE method to access the data that was passed to it. Please pay attention that both the caller and the called class needs to use the same identifier to set and get values (you should use constants to enforce this).
Best regards,
Alej
2015 Sep 17 6:13 AM