Skip to Content

On a project we have a bespoke message tracking software to track our EDI messages. One issue that we are facing is that we would like know what was wrong with a message and why it failed in the mapping.

As I can see it we have three options.

  1. Use the new alert API to get the alerts
  2. Create an application that reads the status tables of SAP PI and based on it creates the alerting.
  3. Create our own error handling routine in the message mapping.

For the first two solutions is possible to make the connection between alerts and messages. It can be build using the standard java tables and scheduling.

The challenge is if will always have to be run in batch or scheduled, so it is not possible to perform the validation live. In most instances this will be just correct.

For some of the partners we would like to perform real-time alerting, so the first two approaches is not idea.

So I had to revert to a good trick that I tried in 2006. Hack: Using XPATH in XI Message Mappings. What says this is old school is that I still used XI all over the blog.

The idea here was to make a new execute method that overwrote the inhered mapping. Then I could make my calls before and then execute the mapping, by calling the inhered execute function.

So the API has changed and it looks different to I had to find a way to do the same on PI 7.31. After decompiled (I did a lot of trial and error experiments) the AMapping class I was able to find the way it works. It looked much the same and the Java mapping API. It made it a lot easier.

So I just had to go to Functions tab and the in the attributes and methods add the function

public void transform….

Enterprise Services Builder MM hack.jpg

Then I could but a try – catch around the call to the super method and then I could put my own error handling below. As a bonus I was able to get the dynamic properties for the messages using the TransformationInput.

The code looks like the following.

   public void transform(TransformationInput in, TransformationOutput out)
                              throws StreamTransformationException {
                    // TODO Auto-generated method stub
                    try{
                    super.transform(in,out);
                    }catch(Exception e){
                    // Custom Error handling.
                              throw new StreamTransformationException("Custom Exception handler:"+e.getMessage(),e);
                    }
          }

So the smart thing about this is that it works instant and I can get the error message directly. It has some downsides. It is not supported in production, so this is just a proof of concept using it at your own risk. But do share the result.

The other issue is that I have to maintain the code in all the mappings that I want to get alert on. It could probably be handled by using some code in an imported archive.

Do you have any ideas on how I can get more realtime updates with one of the two first approached, so I don’t have to make coding inside the message mappings.  Or do you use and other approach to get real time status information please share.

If you like the content and discussion please like or rate the blog.

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Daniel Graversen

    Update.

    I got around this by using the alerting API and in a mapping step save the link from the PI Message ID to the external ID.

    (0) 
      1. Daniel Graversen

        The risk is that you are running unsupported mapping and that it may change in the future.

        (0) 
    1. Bhavesh Kantilal

      Hello Daniel,

      Can you please elaborate on what you mean by using the Alert API and passing the PI message to external ID?

      Regards

      Bhavesh

      (0) 

Leave a Reply