We can raise an alert in SAP PI 7.31 by scheduling AlertConsumerJob for a particular Consumer (Default given by SAP is ALERT-TO-MAIL) using a Java Mail client. After setting up Java mail client we can send an alert email to the defined consumer of AlertConsumerJob.
The mail content and subject sent to the consumer (Recipients) is in very unreadable format. Below is the screenshot of the message sent when an alert get consumed.
Understanding of this message is quite difficult to a person who is not having technical background or rather PI background. Alert email body and subject line is not much of relevance if we raise an alert through alert scheduler job in standard way.
SAP has also provided some of the standard webservices and operations which we can use to customize this solution. With the help of these standard webservices we can create a scenario in SAP PI and raise an alert for each error. Have a look into below screenshot for interfaces provided by SAP for this purpose.
These are the namespaces where above service interfaces reside. We will use above service interfaces to create customized alert scenario.
Solution scenario is like File – Synchronous SOAP Call – Mail.
First work is to add an entry of Basis SWCV into underlying Software Component Version in our SWCV, and then only we will be able to use objects of other namespace. I assume all SLD settings are done.
I will use below message types from SAP Basis 7.31 SWC.
We will copy above message types into our SWCV. For this purpose, I have created below name space and message types. I am not explaining in detail about how to create name spaces data types and message types. Also, from below screenshot you can see
Outbound Message type structure MT_Alert_Struct_Out, which is similar to RetrieveSingleAlertsRequest of Basis SWCV. Have a look.
Inbound Message Type Structure MT_Alert_Struct_In structure is of output structure in which we will raise an alert.
Define service interfaces like below screenshots.
OutBound – Synchronous
Inbound Synchronous – in this service interface we have used standard message types provided in SAP Basis SWC.
Now next step is to create 2 message mapping. Create Mappings as per below screenshot.
Below mapping is simple one to one mapping in the request mapping.
Response mapping contains the parsing logic. And how do we map from source values to target values. Response values in this case will come from one of the standard webservices hosted in service registry.
Once we get response from webservice, it populates values into AlertPayload of RetrieveSingleAlertsResponse. AlertPayload receives values in below format –
To populate these values into target fields we will require doing conversions or writing UDF’s to parse above values. Below is the screenshot, about how I am parsing above values. It can be changed depending upon the logic of a person.
Note – I have mentioned an UDF under red square.
In above graphical mapping, Component in red circle is an UDF. Below is the UDF code we can reuse below code for other output fields too. I am showing UDF for one the component. In the below code, you just need to change the value of this line
if(value.equals(“AdapterType”)). In case, if you want to code for MsgID – you have to use like –
if(value.equals(“MsgID”)) and use the same graphical mapping as shown above.
String result = “”;
String value = “”;
String actual = “”;
int flag = 0;
int count = 0;
int qtnum = 0;
if(AlertPayload.length() != 0)
for(int i =0;i<AlertPayload.length();i++)
if(count == 3)
if(AlertPayload.charAt(i) != ‘”‘)
actual = actual + AlertPayload.charAt(i);
result = actual; flag = 0; count = 0;
flag = 0; count = 0; value = “”;
else if(flag ==1 && count != 3)
if(AlertPayload.charAt(i) != ‘”‘ && qtnum != 4)
value = value + AlertPayload.charAt(i);
flag = 0; count = count +1; qtnum = qtnum + 1;
if (qtnum == 5)
qtnum = 0;count = 0;
else if(AlertPayload.charAt(i) == ‘”‘)
flag = 1;
count = count +1;
qtnum = qtnum + 1;
//result = value;
Create Operations mapping to complete ESR part as below screenshot.
Operations Mapping – Request
Operations Mapping – Response
We are done with ESR developments. Activate it.
Second part will contain actual configuration of this scenario.