Friday, May 1, 2015

TIP: How to modify the text in an Alert

SAP provides the ability to create alerts (emails) through the Alert Framework. Other modules, like SAP Event Management, integrate with the Alert Framework in order to send notifications on exceptions uncovered in the process.

The text that is maintained in the Alert Category definition (tx: ALRTCATDEF) is either static or mapped in from the called system (e.g. SAP EM).

At times we need to have the ability to manipulate the resulting mapped text. To do this you can use BAdI ALERT_MODIFY_TEXT. Note that the BAdI requires filter values relating to your Alert Category Class. See values for my scenario below.

The method to implement is called MODIFY_LONG_TEXT

Scenario: We need to replace the uppercaps with Lowercaps for TORONTO... 

Sample code:

DATAlv_line TYPE soli.

*IP_LANGU         TYPE SYLANGU              Language
*IO_ALERT         TYPE REF TO CL_ALERT      Alert
*IP_APPL_GUID     TYPE GUID_32              Application GUID

LOOP AT ct_long_text INTO lv_line.

IF lv_line CS 'TORONTO'.
REPLACE 'TORONTO' IN lv_line WITH 'Toronto'.
MODIFY ct_long_text FROM lv_line INDEX sy-tabix.


And the result is: