Measurement Series Tutorial: Sample Program
Procedure
Here is the complete program that is described in the measurement series tutorial.
The program performs the following tasks. It:
-
Creates a measurement series. If the series name already exists, then the program loads the existing series.
-
Creates default selection and configuration settings for the series. The resulting objects are used only when a series is created. The default settings cannot be changed after the initial save of the series.
-
Executes a code coverage measurement and calculates a result. The result uses the default calculation configuration and entity selection that were saved with the series. The program also calculates a second result for a specified package.
-
Saves the and result and implicitly the measurement and series.
-
Displays the current results in the graphical browser of the Coverage API. The coverage statistics could also be extracted as text for reuse.
REPORT z_coverage_api_series_example.
* The Series
DATA: factory TYPE REF TO if_scv_factory,
repository TYPE REF TO if_scv_repository,
series TYPE REF TO if_scv_series.
* Default configuration
DATA: configuration TYPE REF TO if_scv_result_configuration,
selection TYPE REF TO if_scv_selection,
users TYPE if_scv_measurement=>users.
* Measurements and results
DATA: measurement TYPE REF TO if_scv_measurement,
default_result TYPE REF TO if_scv_result,
package_result TYPE REF TO if_scv_result.
* Display
DATA: display TYPE REF TO if_scv_result_display.
* Exceptions
DATA: ops_ex TYPE REF TO cx_scv_execution_error,
call_ex TYPE REF TO cx_scv_call_error.
TRY.
* Create measurement series
factory = cl_scv_coverage_api=>get_factory( ).
repository = cl_scv_coverage_api=>get_repository( ).
series = factory->create_series( 'TEST_SERIES_NW_EHP3' ).
* Set defaults for the series - first the scope of recording
series->set_local_server_only( abap_false ).
* Set the default users
append 'KELLERH' to users.
series->set_users( users ).
* Then the selection of entities for which results are calculated
* (not changeable after initial save)
selection = series->get_selection( ).
selection->include_component( 'BC-CCM-MON' ).
" Exclude a sub-component of BC-CCM-MON
selection->exclude_component( 'BC-CCM-MON-SHM' ).
" Include explicitly two packages
selection->include_package( 'SCSM' ).
selection->include_package( 'SMOI' ).
" Exclude a class pool and function group - the full
" technical names of these entities must be used.
selection->exclude_program( 'CL_CCMS_AL_DOC_VIEW_AL_FILTER=CP' ).
selection->exclude_program( 'SAPLSALF' ).
* Then the configuration of the results calculation
* (read-only after initial save)
configuration = series->get_result_configuration( ).
" Calculate only top-level aggregated results
configuration->set_ignore_hierarchy( abap_true ).
* Try to save the series
repository->save_series( series ). " Uniqueness of series name is checked.
CATCH cx_scv_execution_error.
TRY.
* Load the series if it already has been created
series = repository->load_series( 'TEST_SERIES_NW_EHP3' ).
CATCH cx_scv_execution_error INTO ops_ex.
ENDTRY.
ENDTRY.
* Create a measurement in the series - the name can be the
* same for all instances of measurement
TRY.
measurement = series->create_measurement( 'MONITORING_API' ).
measurement->start( ).
* Run test programs - here a harmless CCMS standard program
SUBMIT rsdssmpl_status AND RETURN.
measurement->stop( ).
* Calculate the results using the defaults of the measurement series
* Series default selection and configuration are used
default_result = measurement->build_selection_result(
i_result_name = 'MONITORING_COVERAGE' ).
* Calculate the results for a separate package
package_result = measurement->build_package_result( 'SCSM' ).
* Save the results and implicitly the measurement and series
repository->save_result( default_result ).
repository->save_result( package_result ).
* Display the results in a graphical pop-up - show_as_fullscreen also available
* The display
display = cl_scv_coverage_ui=>get_result_display( default_result ).
display->show_as_popup( ).
display = cl_scv_coverage_ui=>get_result_display( package_result ).
display->show_as_popup( ).
CATCH cx_scv_execution_error INTO ops_ex.
CATCH cx_scv_call_error INTO call_ex.
ENDTRY.