
For ABAP Objects itself - meaning the statements for dealing with classes and objects in ABAP - there are two small but nice improvements in Release 7.40.
Before Release 7.40 a functional method could have only importing parameters besides its returning parameter.
A functional method can now have exporting and changing parameters besides its returning parameter.
In functional method calls you can use the additions EXPORTING, IMPORTING, and CHANGING to pass parameters.
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 class=>do_something( EXPORTING p1 = 333
p2 = 444
IMPORTING p3 = a1
p4 = a2 ) = 0.
"work with a1, a2
ENDIF.
You know that you have to implement all the methods of each interface that you include in your classes with the INTERFACES statement.While this is OK for normal classes, since the user expects the interfaces to be implemented, it can be become rather tedious in test classes of ABAP Unit. Especially when creating test doubles by implementing interfaces in test classes it is cumbersome to implement (sometimes many, many ) empty interface methods that are not needed for testing. And since empty method implementations are reported by the extended program check, you even have to add a pragma ##needed to each of those!
Fortunately, there is now a new addition PARTIALLY IMPLEMENTED to the statement INTERFACES that can be used in test classes and makes an end to these problems (don't tell me that you don't have such problems since you are not testing ...).
The following example is an excerpt from an test include of a http-handler class. Since a http-handler 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. "##needed
METHOD if_http_entity~set_data. ENDMETHOD. "##needed
METHOD if_http_entity~add_multipart. ENDMETHOD. "##needed
METHOD if_http_entity~append_cdate. ENDMETHOD. "##needed
...
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
4 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |