Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
Introduction


There are many cases where it is necessary to reaise alerts from ABAP. For example, when a business critical condition happens during processing. SAP provides a function SALRT_CREATE_API for this purpose. This is a versatile function using which we can populate the alert container and raise alerts.

Steps in XI


In our example, we will use a simple BPM. This has 2 steps, a receive step and a send step.



The send step sends a message to inbound ABAP proxy (client proxy). Here is where we will use the function SALRT_CREATE_API to raise an alert.
The property of the send step:

The payload of the message is:

Define the container variables as below:

Container variables in alert definition:

The long & short texts are defined as:

These variables will be substituted at runtime.

When the inbound proxy is executed in the backend system, it triggers an alert.

If transaction ALRTDISP is executed, the alert can be seen and the container values can be displayed.

Finally the abap code

Please note that the version of SALERT_CREATE_API used here is XI 3.0. The signature of the function is different in XI 7.0 version.

The code for inbound proxy, specifically, the method ZII_VENDOR_FILE~EXECUTE_ASYNCHRONOUS is:

method ZII_VENDOR_FILE~EXECUTE_ASYNCHRONOUS.

      • **** INSERT IMPLEMENTATION HERE **** ***

  data: l_r_cnt type ref to IF_SWF_CNT_CONTAINER.

  data: l_t_receipients type table of SALRTSRCP.

  data: l_s_receipients type SALRTSRCP.

  data: l_t_container type table of SWCONT.

  data: l_s_container type swcont.

  data: begin of l_wi_head,

        wi_id type SWWWIHEAD-wi_id,

        CREA_TMP type swwwiHead-CREA_TMP,

        end of l_wi_head.

  data l_t_wi_head like standard table of l_wi_head with key wi_id.

  l_s_receipients-uname = 'SUKUMAR'.

  append l_s_receipients to l_t_receipients.

  l_r_cnt = cl_swf_cnt_factory=>create( ).

  select wi_id CREA_TMP from swwwihead client specified into

corresponding fields of table l_t_wi_head

         where client = '100'.

  • 100 is the Integration server client

  sort l_t_wi_head by crea_tmp descending.

  loop at l_t_wi_head into l_wi_head.

    exit.

  endloop.

  • Provide the container element name, value,length & type

  • Move the data to the container variable

  l_s_container-element = 'VENDOR'.

  l_s_container-value = input-Vendor-Vendor_Number.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'LASTNAME'.

  l_s_container-value = input-vendor-last_name.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'SEARCHTERM'.

  l_s_container-value =  input-vendor-search_Term.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'CURRENCY'.

  l_s_container-value =  input-vendor-currency.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'STREETADDRESS'.

  l_s_container-value =  input-vendor-address-Street.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'CITY'.

  l_s_container-value =  input-Vendor-address-city.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'ZIP'.

  l_s_container-value =  input-Vendor-address-zip.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'COUNTRY'.

  l_s_container-value =  input-Vendor-address-country.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  l_s_container-element = 'EMAIL'.

  l_s_container-value =  'sukumar.natarajan@sap.com'.

  l_s_container-elemlength = 20.

  l_s_container-TYPE ='C'.

  append l_s_container to l_t_container.

  CALL FUNCTION 'SALRT_CREATE_API'

    EXPORTING

      IP_CATEGORY                  = 'ALRTFRMWRKTEST'

  •                    IP_EXPIRATION_TIME           =

  •                    IP_EXPIRATION_DATE           =

       IP_WAIT_ON_COMMIT            = ''

  •                    IP_APPLICATION_GUID          =

  •                    IP_GET_SYNC_EXCEPTIONS       = ' '

  •                  IMPORTING

  •                    EP_ALERT_ID                  =

   TABLES

    IT_RECIPIENTS                = l_t_receipients

  •                    IT_ACTIVITIES                =

     IT_CONTAINER                 = l_t_container

  •                    IT_EXT_RECIPIENTS            =

  •                    IT_EXT_ADDR                  =

  •                    IT_ROLES                     =

  •                  EXCEPTIONS

  •                    ALERT_CATEGORY_UNKNOWN       = 1

  •                    ALERT_NO_RECIPIENTS          = 2

  •                    ALERT_ERROR_UNKNOWN          = 3

  •                    DESTINATION_UNDEFINED        = 4

  •                    COMMUNICATION_FAILURE        = 5

  •                    SYSTEM_FAILURE               = 6

  •                    OTHERS                       = 7

            .

  IF SY-SUBRC <> 0.

  if sy-subrc <> 0.

    exit.

  endif.

  commit work.

endmethod.

Unfortunately, in the function, we still need to provide the container variable name and its length.

Read this Integrating Alerts into UWL - it's no problem! to know how to integrate Alerts into UWL.

After configuring the UWL, you can see the alerts there.

3 Comments