* ________ _______ _____ ___ ________ ______ _______ ________
* /" )/" "|(\" \|" \ /" ) / " \ /" \ /" )
* (: \___/(: ______)|.\\ \ |(: \___/ // ____ \ |: |(: \___/
* \___ \ \/ | |: \. \\ | \___ \ / / ) :)|_____/ ) \___ \
* __/ \\ // ___)_ |. \ \. | __/ \\(: (____/ // // / __/ \\
* /" \ :)(: "|| \ \ | /" \ :)\ / |: __ \ /" \ :)
* (_______/ \_______) \___|\____\)(_______/ \"_____/ |__| \___)(_______/
* The always up-to-date overview for system-wide health monitoring
* Class : zcl_sensor_fixer
* Title : Sensor fixer report helper class
* Description :
"! This class is a helper class for fixer reports (FXR). It holds logic that should
"! be available for all fixer reports. A template fixer report should be used together
"! with this class for compose fixer reports for sensors that support automatic fixing.
CLASS zcl_sensor_fixer DEFINITION
PUBLIC
FINAL
CREATE PRIVATE.
PUBLIC SECTION.
TYPES: BEGIN OF gty_textlog,
messagetype TYPE sy-msgty,
message TYPE c LENGTH 110,
END OF gty_textlog.
TYPES: gty_textlog_t TYPE STANDARD TABLE OF gty_textlog WITH DEFAULT KEY.
"! Singleton pattern
CLASS-DATA gv_instance type ref to zcl_sensor_fixer.
"! The go_i18n global attribute holds the text elements for the fixers. It is populated with
"! the texts that are applicable for all fixers and specific texts can be added in the
"! INITIALIZATION event of the fixer report.
DATA go_i18n TYPE REF TO zcl_i18n.
"! A BAL log is composed and a textual version of the BAL log is also maintained. Method
"! log to add entries to the log and method display to produce the output
"! of the log.
DATA gt_textlog TYPE gty_textlog_t READ-ONLY.
DATA go_log TYPE REF TO cl_bal_logobj.
CLASS-METHODS get_instance returning value(ro_instance) type ref to zcl_sensor_fixer..
CLASS-METHODS at_screen_output
IMPORTING iv_hide_group TYPE boolean DEFAULT abap_false
iv_hide_parvalue TYPE boolean DEFAULT abap_false.
METHODS constructor.
"! Queue and dequeue for the fixer run
METHODS enqueue_run RETURNING VALUE(rv_locked_fine) TYPE boolean.
METHODS dequeue_run.
"! Logging functionality (log is created in the constructor)
METHODS log IMPORTING iv_text TYPE string.
METHODS log_display.
ENDCLASS.
CLASS zcl_sensor_fixer IMPLEMENTATION.
METHOD get_instance.
if gv_instance is initial.
gv_instance = NEW zcl_sensor_fixer( ).
endif.
ro_instance = gv_instance.
ENDMETHOD.
METHOD at_screen_output.
LOOP AT SCREEN.
IF screen-name = 'PA_SENSO'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
"Hide the description fields for sensor and groupname
IF screen-name = 'PA_SENTX' OR screen-name = 'PA_GROUX'.
screen-input = '0'.
screen-display_3d = '0'.
MODIFY SCREEN.
ENDIF.
IF iv_hide_group = abap_true AND screen-name = 'PA_GROUP'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
IF iv_hide_parvalue = abap_true AND screen-name = 'PA_PARVA'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD constructor.
go_i18n = zcl_i18n=>get_instance( 'sensor.fixer.class' ).
go_i18n->feed( VALUE #(
( id = 'B01_main' nl = |Fixer rapportage voor sensor| en = |Fixer report for sensor| )
( id = 'P01_sensor' nl = |Sensor type| en = |Sensor type| )
( id = 'P02_group' nl = |Groep| en = |Group| )
( id = 'P03_parametervalue' nl = |Parameter waarde| en = |Parameter value| )
( id = 'P04_test' nl = |Test (geen verwerking)| en = |Test (no updates)| )
( id = 'B02_extra' nl = |Extra selectie instellingen| en = |Extra selection settings| )
( id = 'ALREADYACTIVE' nl = |Programma is al actief| en = |Report is already running| )
( id = 'TESTMODE' nl = |Test (geen verwerking)| en = |Test (no updates)| )
( id = 'NODATA'
nl = |Geen autofix verzoeken gevonden (niks te doen)|
en = |No autofix suggestions available (nothing to do)| )
) ).
TRY.
CREATE OBJECT go_log
EXPORTING
i_log_object = 'ALERT'
i_default_subobject = 'PROCESSING'.
CATCH cx_bal_exception INTO DATA(lx_exception).
MESSAGE lx_exception->get_text( ) TYPE 'E'.
ENDTRY.
ENDMETHOD.
METHOD enqueue_run.
"Lock the run (report + variant).
CALL FUNCTION 'ENQUEUE_ESVARIANT'
EXPORTING
relid = 'XX'
report = sy-repid
variant = sy-slset
srtf2 = ''
EXCEPTIONS
OTHERS = 4.
IF sy-subrc = 4.
MESSAGE go_i18n->get( 'ALREADYACTIVE' ) TYPE 'S'.
rv_locked_fine = abap_false.
ELSE.
rv_locked_fine = abap_true.
ENDIF.
ENDMETHOD.
METHOD dequeue_run.
CALL FUNCTION 'DEQUEUE_ESVARIANT'.
ENDMETHOD.
METHOD log.
TRY.
APPEND VALUE #(
messagetype = 'I'
message = iv_text ) TO gt_textlog.
go_log->add_statustext( i_statustext = iv_text ).
CATCH cx_bal_exception.
".. and ignore
ENDTRY.
ENDMETHOD.
METHOD log_display.
IF sy-batch = abap_true.
LOOP AT gt_textlog INTO DATA(ls_textlog).
MESSAGE |{ ls_textlog-messagetype }: { ls_textlog-message }| TYPE 'S'.
ENDLOOP.
ELSE.
go_log->display( ).
ENDIF.
ENDMETHOD.
ENDCLASS.