14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3

ABAP Unit and Test-Driven Development

example, but the adva ntage increases proportionally with the complexity of the

class being tested.

Note

You can also use this same methodology if the importing parameter of the object constructor

is an interface. You just pass the interface name in to the INSTEAD_OF method

rather than the main class name.

The first method called in Listing 3.22 is the DURING CONSTRUCTION method. This

is shown in Listing 3.23; it analyzes el ementary parameters and then does nothing

fancier than adding entries to an internal table.

METHOD during_construction.

* Local Variables

DATA: lo_description TYPE REF TO cl_abap_typedescr,

ld_dummy

TYPE string ##needed,

ld_data_element_name TYPE string,

ls_parameter_values LIKE LINE OF mt_parameter_values.

ls_parameter_values-identifier = for_parameter.

CREATE DATA ls_parameter_values-do_value LIKE use_value.

GET REFERENCE OF use_value INTO ls_parameter_values-do_value.

CHECK sy-subrc = 0.

CALL METHOD cl_abap_structdescr=>describe_by_data_ref

EXPORTING

p_data_ref

= ls_parameter_values-do_value

RECEIVING

p_descr_ref

= lo_description

EXCEPTIONS

reference_is_initial = 1

OTHERS = 2.

IF sy-subrc <> 0.

RETURN.

ENDIF.

SPLIT lo_description->absolute_name AT '=' INTO ld_dummy ld_data_

element_name.

ls_parameter_values-rollname = ld_data_element_name.

164

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!