Abap Objects - Abap 7.40
Abap Objects - Abap 7.40
Abap Objects - Abap 7.40
Example
The following kind of functional method declaration and invocation was not possible before
Release 7.40.
CLASS class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS do_something IMPORTING p1 TYPE i
p2 TYPE i
EXPORTING p3 TYPE i
p4 TYPE i
RETURNING VALUE(r) TYPE i.
ENDCLASS.
...
IF
ENDIF.
Example
The following example is an excerpt from an test include of a http-handler class. Since a httphandler normally works with objects like request or response of the ICF-framework, for
standalone testing you have to create appropriate test doubles (mock framework) by
implementing the according interfaces. In the case shown here, a class for a mock request is
created by implementing if_http_request. Before Release 7.40 this was rather awkward,
since you had to implement all of the about 50 interface methods! In Release 7.40 you have to
implement only those that are needed for testing.
Before Release 7.40
CLASS mock_request DEFINITION FOR TESTING FINAL.
PUBLIC SECTION.
INTERFACES if_http_request.
ENDCLASS.
CLASS mock_request IMPLEMENTATION.
METHOD if_http_request~get_form_field.
value = SWITCH spfli-carrid( name WHEN 'carrid' THEN 'LH'
ELSE space ).
ENDMETHOD.
METHOD if_http_entity~set_cdata.
ENDMETHOD.
METHOD if_http_entity~set_data.
"##needed
ENDMETHOD.
"##needed
"##needed
METHOD if_http_entity~append_cdate.
"##needed
ENDMETHOD.
...
ENDCLASS.
Release 7.40
CLASS mock_request DEFINITION FOR TESTING FINAL.
PUBLIC SECTION.
INTERFACES if_http_request PARTIALLY IMPLEMENTED.
ENDCLASS.
CLASS mock_request IMPLEMENTATION.
METHOD if_http_request~get_form_field.
value = SWITCH spfli-carrid( name WHEN 'carrid' THEN 'LH'
ELSE space ).
ENDMETHOD.
ENDCLASS.