Google Search - Blog...........

ABAP - Use Of Preferred Parameter In A Method - OOPS Concept.

If there are more than one OPTIONAL import parameters in a method and no non-optional import parameters without values, one can type in the clause PREFERRED PARAMETER after the list of import parameters to specify which of the optional parameters will get more preference compared to others when the method will be called using syntax :- CALL METHOD objref->meth().

In other words, it decides which of the optional parameters will be assigned the value ‘VAL’.
------------------------------------------------------------------------------------------

REPORT YSUBDEL .
CLASS C1 DEFINITION.
PUBLIC SECTION.
METHODS : METH1 IMPORTING INPUT1 TYPE I optional
input2 TYPE I OPTIONAL
PREFERRED PARAMETER INPUT2.
ENDCLASS.

CLASS C1 IMPLEMENTATION.
METHOD : METH1.
write:/5 input1 ,
/5 input2 .
ENDMETHOD.
ENDCLASS.


START-OF-SELECTION.
DATA : OREF1 TYPE REF TO C1.
CREATE OBJECT : OREF1.
CALL METHOD : OREF1->METH1( input1 = 5 input2 = 3 ).
skip 2.
write:/5 'Next call'.
call method oref1->meth1( 10 ) .

Output
5
3


Next call
0
10

No comments:

Post a Comment