Show TOC

Step 1: Creating a MeasurementLocate this document in the navigation structure

Procedure

Create a standalone measurement with the factory that is provided by the class CL_SCV_COVERAGE_API. This class is the central entry point to the Coverage API.

You might use standalone measurements for ad hoc checks of code coverage. For example, as a developer, you might produce such a measurement to verify and document the code coverage of a test program.

Sample Code: Creating a Measurement

Here is code for creating a measurement. All of the parameters of the measurement factory are shown, all are optional.

DATA: factory     TYPE REF TO if_scv_factory,
      measurement TYPE REF TO if_scv_measurement,
      users       TYPE if_scv_measurement=>users.

factory = cl_scv_coverage_api=>get_factory( ).

APPEND 'AUNIT_USER' TO users. "Coverage will be recorded
APPEND 'ECATT_USER' TO users. "for these users.

measurement = factory->create_measurement(
  i_name              = 'myMeasurement'   
  i_local_server_only = abap_false "Record activity on all servers
  i_users             = users 
  i_testkey_expiration = cl_scv_expiration=>create( i_weeks = 2) ).
    "Keep the raw data for two weeks - there are other parameters
    "and methods available.

            

For simplicity, exception handling is not shown in these tutorial code examples.

Continue to start the measurement and record code coverage statistics.

See also the complete sample program.

Parameters in More Detail

When you create a new measurement, you can specify the following optional parameters:

  • i_name: A name for the measurement. The name is not unique and has a purely documentary role. Default: No name.

    You can omit a name for standalone measurements that you do not save. If you save measurements, providing a name remains optional, but you can apply standard names to measurements (and also to results) that are semantically related. For example, if you calculate a weekly result for package SMOI, you can use the name i_name = 'Package SMOI' for each instance of the result.

  • i_local_server_only: Whether coverage should be measured on all servers of the system or only on the current server.

    Default: Coverage is measured only on the current logon server.

  • i_users: A list of the users for whom coverage is measured.

    Default: Coverage is measured only for the current user (system field sy-uname).

  • i_testkey_expiration: How long the raw data of the measurement should be kept before being automatically deleted. Express the retention interval as an instance of class CL_SCV_EXPIRATION, as the sample above shows. See also Finalizing a Measurement.

    Default: Raw data is deleted after one week. The measurement itself and any results that have been generated from the raw data are not deleted, if they have been saved to the repository.