Problem solve Get help with specific problems with your technologies, process and projects.

How to raise alerts from ABAP Proxy

SAP provides a function called SALRT_CREATE_API that can raise alerts from ABAP. This SAP Developer Network post explains how to use this function.

In many cases, it is necessary to raise alerts from ABAP, such as when a business critical condition happens during...

processing. SAP provides a versatile function SALRT_CREATE_API for this purpose that we can use to populate the alert container and raise alerts.

Steps in XI
In our example, we will use a simple BPM. This has two 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:
<?xml version="1.0" encoding="UTF-8"?>

<ns0:Vendor xmlns:ns0="urn:sukumar-test">
<VendorNumber>12345</VendorNumber>
<LastName>Smith</LastName>
<SearchTerm>Vendor12345</SearchTerm>
<Currency>USD</Currency>
<Address>
<Street>123 Main Street</Street>
<City>Plano</City>
<Zip>75075</Zip>
<Country>USA</Country>
</Address>
</ns0:Vendor>

Create the alert category
Using the transaction code ALRTCATDEF, an alert category ALRTFRMWRKTEST was created.

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 and 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 blog to know how to integrate Alerts into UWL.

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

Sukumar Natarajan works for XI Regional Implementation Group with SAP Labs.


This content is reposted from the SAP Developer Network.
Copyright 2007, SAP Developer Network

SAP Developer Network (SDN) is an active online community where ABAP, Java, .NET, and other cutting-edge technologies converge to form a resource and collaboration channel for SAP developers, consultants, integrators, and business analysts. SDN hosts a technical library, expert blogs, exclusive downloads and code samples, an extensive eLearning catalog, and active, moderated discussion forums. SDN membership is free.

Want to read more from this author? Click here to read Sukumar Natarajan's Weblog. Click here to read more about XI on SDN.



This was last published in January 2007

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close