Skip to Content
The problem is very simple: how do you smartly stop an XI graphical mapping?
Suppose you volountarily want a graphical mapping step to fail based on certain conditions. You would throw an exception in a UDF (User Defined Function), yes, but XI doesn’t allow you to add the throws clause in a UDF, so no way. Another easy way is to write a statement that will 100% fail, like:

String youWillFail = new String("not.enough.long"); youWillFail.substring(0,100);

This would crash in a StringIndexOutOfBounds exception, the message would stop, but if you use this technique several times in your mapping, it’s a nightmare – if even possible – to understand where it was exactly generated!
So writing a couple of Java classes, and importing a .jar file in Integration Repository as Imported Archive can easily solve the problem.
Step by step, here’s what you need to do.

Create a java package with two classes inside: CustomMappingException and ExceptionThrower. Compile and export them as .jar file. Source code is below.

package com.guarneri.xi.mapping.udf; public class CustomMappingException extends RuntimeException { public CustomMappingException() { super(); } public CustomMappingException(String message) { super(message); } public CustomMappingException(Throwable cause) { super(cause); } public CustomMappingException(String message, Throwable cause) { super(message, cause); } } package com.guarneri.xi.mapping.udf; public class ExceptionThrower { public static void fire(String message) throws CustomMappingException { throw new CustomMappingException(message); } }

Note that the key of everything is to extend RuntimeException, and not Exception. Why? Because Java syntax check doesn’t allow you to call a method throwing an Exception without surrounding it with a try catch. While our method- in this case the static ExceptionThrower.fire() – throws a RuntimeException, for which you can omit the try catch.

Once you have created the Imported Archive containing the two classe, you can build up a UDF that will use it, as shown in the picture below.

Image

The choices upon which the UDF should hang the whole mapping are up to you. I chose to handle this three kind of problems:
– no incoming value
– empty incoming value
– forced exception, that is if you pass $error$ as first UDF argument
– otherwise the incoming value is returned, and the mapping happily continues its job.

Here’s a sample mapping, where the first argument is the incoming value, and the second is a constant containing the Exception message (“No SalesOrderNumber was requested” here).

Image

And now, the magic: in the Message Monitor (SXMB_MONI transaction) a qualified exception is reported!

Image

If I were an XI day-by-day Admin, I would be pleased by such an option. 🙂

To report this post you need to login first.

33 Comments

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

    1. Alessandro Guarneri Post author
      Thanks for your opinion.
      RuntimeException can be used, but a qualified exception type is much more self-describing, and inside the huge trace header section of a message can be easily found: with a CTRL+F and exception class name you get straight to the point.
      Not mentioning that froma a Java architectural point of view, this approach is much more correct than throwing generic exception.

      Regards,
      Alessandro

      (0) 
    2. Alessandro Guarneri Post author
      Thanks for your opinion.
      RuntimeException can be used, but a qualified exception type is much more self-describing, and inside the huge trace header section of a message can be easily found: with a CTRL+F and exception class name you get straight to the point.
      Not mentioning that froma a Java architectural point of view, this approach is much more correct than throwing generic exception.

      Regards,
      Alessandro

      (0) 
    3. Alessandro Guarneri Post author
      Thanks for your opinion.
      RuntimeException can be used, but a qualified exception type is much more self-describing, and inside the huge trace header section of a message can be easily found: with a CTRL+F and exception class name you get straight to the point.
      Not mentioning that froma a Java architectural point of view, this approach is much more correct than throwing generic exception.

      Regards,
      Alessandro

      (0) 
      1. sachin kotalwar
        I think throwing user defined exception also gives us control like if any corrective action needs to be taken (e.g. calling other function etc) rather than just using standard class like RuntimeException.

        cheers,

        sachin kotalwar.

        (0) 
  1. Thorsten Nordholm Søbirk
    The biggest problem with throwing exceptions in mapping programs is that there is no way to get your exception to show in the Error Header of the message monitor. The exception always gets wrapped in a …BaseRuntimeException, which is what is shown in the the Error Header.

    Now if only SAP had declared an exception class to be thrown by user-defined functions as well as from Java mappings, we could simply subclass that exception and have our custom exception messages appear in the Error Header. Then we would seldom need to look in the trace at all.

    I hope this will show up in a future release.

    – Thorsten

    (0) 
  2. Otto Frost
    Hi, I’m using SP14.
    I have had problems with ABAP mappings, when called from BPM. When the ABAP map ceaches for some reason, the BPM get stuck, and you have to manually go in and reset the lasw workflow instance to logically deleted, to be able to continue.

    Have you any experience of errorhandling in concjunction with BPM?
    BR /Otto

    (0) 
    1. Alessandro Guarneri Post author
      Hi Otto,
      I think an Exception Handling Branch could solve your issue. Every step you put in this EHB will be performed whenever your transformation step crashes for whatever reason. Just embed your transf. step in a block, define an exception in the transf. step, right click on the block->insert->exception branch. Specify the above said exception, put something to do in the EHB  and you’re set.

      Alex

      (0) 
  3. Bhavesh Kantilal
    Alex,
    Just going go step forward to this solution, is there any way in which we can trigger XI’s Alerts from our User Defined Function or even Java Mapping?

    Regards,
    Bhavesh

    (0) 
    1. Alessandro Guarneri Post author
      Good point Bhavesh, I should investigate whether there’s a std class doing this job…
      Anyway, as alerting is ABAP-stack based, an easy way could be to invoke some related RFC functions via JCo, like SALERT_CREATE… Have a look into that!

      Cheers,
      Alex

      (0) 
    1. Alessandro Guarneri Post author
      Actually raising an exception here already stops the whole mapping, and not only the specific mapping step.
      So it probably already does what you need, but have a look at one of the last Michal’s blog on this topic for a more fine-grained handling.

      Alex

      (0) 
  4. Barry Neaves

    Hi<br/><br/>I have implemented the coding and logic in this blog.  When I test the mapping locally (message mapping), all works fine, but when I send a document from end to end I get the following error:<br/><br/><?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes” ?> <br/>- <!–  Request Message Mapping <br/>  –> <br/>- <SAP:Error xmlns:SAP=”http://sap.com/xi/XI/Message/30” xmlns:SOAP=”http://schemas.xmlsoap.org/soap/envelope/” SOAP:mustUnderstand=””><br/>  <SAP:Category>Application</SAP:Category> <br/>  <SAP:Code area=”MAPPING”>NO_STREAM_TRANSFORMATION</SAP:Code> <br/>  <SAP:P1>com/guarneri/xi/mapping/udf/CustomMappingExceptio</SAP:P1> <br/>  <SAP:P2>urn:com.server.system.function</SAP:P2> <br/>  <SAP:P3>8c51b220-9f3c-11db-94ce-eb180ddf0074</SAP:P3> <br/>  <SAP:P4>-1</SAP:P4> <br/>  <SAP:AdditionalText /> <br/>  <SAP:ApplicationFaultMessage namespace=”” /> <br/>  <SAP:Stack>Java class com/guarneri/xi/mapping/udf/CustomMappingExceptio does not implement the required interface “StreamTransformation”</SAP:Stack> <br/>  <SAP:Retry>M</SAP:Retry> <br/>  </SAP:Error><br/><br/><br/><br/>Have I missed something?

    (0) 
    1. Yash Agarwal
      Hi Alex,

      thanks for the blog. I have used this in my mapping. when i test my mapping from the test tab, it gives me the specific error but when i run the scenario end to end, it doesnt show me the specific error in the MONI. can you tell me where i m missing the trick. May be some parameter setting. My trace level is set to 3. I am working on PI 7.1 SP05.

      Regards,
      Yash

      (0) 
  5. Yash Agarwal
    Hi Alex,

    thanks for the blog. I have used this in my mapping. when i test my mapping from the test tab, it gives me the specific error but when i run the scenario end to end, it doesnt show me the specific error in the MONI. can you tell me where i m missing the trick. May be some parameter setting. My trace level is set to 3. I am working on PI 7.1 SP05.

    Regards,
    Yash

    (0) 
      1. Yash Agarwal
        Thats fine Alex.

        Principly the concept should be the say in 7.0 or 7.1! Just wanted to know if there is any other configuration which i need to do like in Adminstration etc. for it to work and show the desired error in MONI.

        Regards,
        Yash

        (0) 
  6. Philippe Addor
    I have a much easier solution via UDF (user defined function) to achieve this. I don’t know why it is done with imported archives in this blog. It might be that my solution was not possible with XI 3.0 (we use PI 7.1).

    1. Create a new user defined function in the message mapping (Function tab or white paper on the bottom left corner of the graphical mapping)
    2. Call the function for ex. “ThrowException”
    3. Choose “Single Values” for Execution Type
    4. Insert this code:
    throw new StreamTransformationException(“Error occured xy);

    You can also make use of the parameter function to include a parameter for the error message (which can then be defined in the graphical mapping).

    Phil

    (0) 
  7. Aaron Long
    Good blog!
    good to know throwing RuntimeException is permited in UDF.

    to make it easy, just throw RuntimeException in the UDF code intead of using another CustomException.

    (0) 
    1. Alessandro Guarneri Post author
      Thx

      Indeed RuntimeException every time is an option

      BUT
      my approach aimed to be throwing different exception just to better qualify the error, that is to give it an application aspect.

      Cheers,
      Alex

      (0) 
  8. Vamsi Krishna
    Hello Alex,

    I used your blog to raise smart exceptions in mapping and working fine.When i run the interface end to end, i can able to see the exception message under TRACE only. when i receive alert email, i can receive every time saying like MAPPING.EXCEPTION_DURING_EXECUTE . I would like to receive the exception that came under TRACE.

    Is there any way to capture this exception and send with alert category??

    Is there any container variable that gets this runtime content??

    Please help me

    (0) 
    1. Alessandro Guarneri Post author
      Hi,
      It’s possible but it’s a mess…
      I did it once but on the ABAP stack, and by hardly parsing the trace SOAP header of the XI message, which is badly a characterized XML, and you just need to go and search for string in order to extract something useful.

      BR

      Alex

      (0) 
  9. Michael Dames
    hello,

    where can i locate the jar file within SAP or anywhere for importing com.guarneri.xi.mapping.udf into my java mapping programs. I need to include it within my JDK tool kit libraries for compiling map archives.

    (0) 
  10. Jens Schwendemann

    Alessandro, I know this is a long time since you created the blog. But if you still happen to be around here, would you have a look at the missing pictures? That’ll be great

    Cheers

    Jens

    (0) 
    1. Eng Swee Yeoh

      Hi Jens,

      This is really old and no longer necessary, IMHO. It’s probably a limitation in the XI 3.0 or PI 7.0 days.

      These days, you can just add a line throw a RuntimeException in UDF.

      /wp-content/uploads/2016/06/runtime_973358.png

      Regards

      Eng Swee

      (0) 

Leave a Reply