2008 Sep 30 9:55 PM
I have a very strange problem that no-one was able to help me with so far. I need to implement some code inside a method, which is based on a method's parameter that may or may not be in the method's signature.
This situation has arisen because the method in question is a BAdI implementation that needs to be enhanced, but the BAdI's interface is off-limits. At some point an extra parameter was added to the BAdI's interface, but it is possible that the application will be in a state where this change will not be applied. At the same time, the BAdI's implementation should make use of this parameter, if it's available.
So, in my method code I need smth like:
data: var1 type any.
if ( 'param1' ) exists
var1 = me->getThisMethodsParameterByName( 'param1' )
* do smth with var1
endif
where param1 is this fuzzy parameter, that may or may not be in the method's signature.
In other words, I need to shut the compiler up when the parameter is not in the method's signature, but at the same time I need to access it inside the method.
Any pointers will be greatly appreciated!
Oksana
Edited by: Oksana Korol on Sep 30, 2008 10:56 PM
Edited by: Oksana Korol on Sep 30, 2008 10:57 PM
Edited by: Oksana Korol on Sep 30, 2008 10:58 PM
2008 Sep 30 10:19 PM
See if this helps you
data: objeto type ref to CL_METHOD_PPF,
object_class type ref to CL_CLASS_PPF,
l_class type SEOCLSNAME,
l_method type SEOCPDNAME,
l_bool.
l_class = 'CL_GUI_FRONTEND_SERVICES'.
l_method = 'DIRECTORY_EXIST'.
create object object_class
exporting
ip_class = l_class.
create object objeto
exporting
ip_class = l_class
ip_method = l_method
io_class = object_class.
l_bool = objeto->exists( 'DIRECTORY' ).
write l_bool.
2008 Oct 01 4:18 AM
Hello Oksana
There is a very simple solution available for your problem.
The new signature parameter is optional because otherwise you would run into a dump when the standard method is called. Thus, you can use the
IS SUPPLIED statement
to check whether the parameter has been used in the method call or not.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_BADI_IF_ENHANCEMENT
*&
*&---------------------------------------------------------------------*
*& Thread: Dynamically get a method's parameter
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1069319"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_badi_if_enhancement.
*----------------------------------------------------------------------*
* CLASS lcl_badi_im_class DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_badi_im_class DEFINITION.
PUBLIC SECTION.
METHODS:
constructor.
METHODS:
enhanced_method
IMPORTING
value(id_standard_1) TYPE i
value(id_standard_2) TYPE c
value(id_enhanced_1) TYPE c OPTIONAL.
ENDCLASS. "lcl_badi_im_class DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_badi_im_class IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_badi_im_class IMPLEMENTATION.
METHOD constructor.
ENDMETHOD. "constructor
METHOD enhanced_method.
IF ( id_enhanced_1 IS SUPPLIED ).
MESSAGE 'Enhanced method signature is called' TYPE 'I'.
ELSE.
MESSAGE 'Standard method signature is called' TYPE 'I'.
ENDIF.
ENDMETHOD. "enhanced_method
ENDCLASS. "lcl_badi_im_class IMPLEMENTATION
data: go_badi type ref to lcl_badi_im_class.
START-OF-SELECTION.
create object go_badi.
" Enhanced parameter not used in method call => IS NOT SUPPLIED
call method go_badi->enhanced_method
exporting
id_standard_1 = 1
id_standard_2 = 'A'
* id_enhanced_1 =
.
" Enhanced parameter is used in method call => IS SUPPLIED
call method go_badi->enhanced_method
exporting
id_standard_1 = 1
id_standard_2 = 'A'
id_enhanced_1 = space.
" NOTE: There is no difference in the contents of parameter ID_ENHANCED_1
" between the two different method calls yet the parameter
" IS SUPPLIED only in the second method call.
END-OF-SELECTION.
Regards
Uwe
2008 Oct 01 2:19 PM
Hi guys,
Thank you very much for your detailed replies, but the problem is not in the calling of the method. The problem is inside the method. Uwe's example is not my case, since I don't have control over method definition. So the enhanced_method can have this signature:
enhanced_method
IMPORTING
value(id_standard_1) TYPE i
value(id_standard_2) TYPE c
value(id_enhanced_1) TYPE c OPTIONAL.
or this signature:
enhanced_method
IMPORTING
value(id_standard_1) TYPE i
value(id_standard_2) TYPE c
The method is a BAdI implementation and I have to run with the parameters that BAdI interface provides me. And it is possible that it will either be the first case, or the second case.
Now I need to use the id_enhanced_1 in my method implementation, but if I'm supplied with the second signature, referencing id_enhanced_1 inside the method will give a compiler error (since it's not in the signature).
So I need somehow dynamically to take care of this id_enhanced_1, whether it is in the method signature, or not. I'm not even sure if it's possible, just hope some bright minds out there can put my mind at rest
Oksana
2008 Oct 01 2:29 PM
You'll have to use dynamic parameters in any case, I think. So you could use
TRY.
CALL METHOD dynamically with first set of parameters
CATCH cx_sy_dyn_call_error.
TRY.
CALL METHOD dynamically with second set of parameters.
CATCH cx_sy_dyn_call_error.
* Do "It's all gone horribly" wrong processing here
ENDTRY.
ENDTRY
That's assuming, of course, that you know all possible alternatives. If the additional parameter(s) are completely aribitray, perhaps decided by some third party, then another approach is needed... which I'll think about.
matt
2008 Oct 01 2:44 PM
Matt,
Unfortunately I don't have control over how the method is called either. All I can modify is the method implementation...
Oksana