Monday, December 10, 2007

Super Message Monitor for SAP XI


Once I was asked: "Hey Alex, is there a standard way we can use for searching XI messages in SXMB_MONI given the SAP IDoc number?". So I looked a little bit around in the XI ABAP stack, without success. That's a why I decided to enhance the message monitor and make this and other search ways possible.
This weblog assumes you are a little bit familiar with ABAP coding, but I will try - as usual - to keep so simple that even without this knowledge one should be able to replicate it! By the way, if you have a look at this forum thread, you'll see that the need for ABAP skill in XI it's still a matter of deep controversy, partially deriving from the stimulating ABAP/Java war, and you could also read a couple of opinions o' mine, for what it's worth. I think the job I'm about to describe here it's kinda proof for my (and others') position, but this is another story.
Let's get built our XI Super Message Monitor!

When you'll be finished coding up (approx. time needed 60 minutes), you'll be able to search XI messages for IDoc number and IDoc type both sender and receiver, and - believe to the unbelievable - even for message content (payload)!! This first version only searches the Inbound payload, that is before mapping takes place, but I will soon release a new one with the ability to choose it.


No standard code will be opened to changes, just a copy it's made, so don't worry about it. :-)

Let's go

First of all your user needs to be registered as a developer in XI ABAP stack: check out SCCR for this purpose.
Now that you have the power of building ABAP stuff, go to ABAP Developmemt Workbench (trx SE80) and create a new package that will contain all our custom objects.



You'll be asked for a workbench change request (which is basically a container for things we'll create that you will use when you want to transport everything to consolidation and production box): I suggest you create a new one, give it a meaningful name (such as "XI Super Monitor") and choose it. It will be automatically proposed afterwards.
The big ABAP program behind trx SXMB_MONI is RSXMB_SELECT_MESSAGES, which we need (along with other includes) to duplicate. To do this - always from SE80: we'll never move from here more or less! - choose Program from the upper left combo, type RSXMB_SELECT_MESSAGES in the edit box below it and press enter. Now right click on the program name, choose Copy... and a popup will ask you the name of your new program. Choose a suitable prefix for all the objects, ZXIMONI could be a good choice as it also reflects the package name (a warning will popup: if you don't like its message choose somthing else like ZMONI, otherwise just confirm).


In the next popup you're asked for which components of the program you'd like to copy: flag everything and confirm.


In the next popup you're asked to give new names to include programs: we need to duplicate only 2 of them actually (flagged in the picture below), but if you feel more confortable by working on custom objects only, just copy all of them and give them the same name with the above said prefix (ZXIMONI_ or ZMONI_).


In the final popup you will be asked for the package and yes, you guessed right, you'll put ZXIMONI, or whatever package name you chose before.
Ok, now we have all the objects we need and you can see them in the lower left tree. If you double click on the newly created program (the root one) its source code appears in the right frame: notice that declaration for includes we copied have been automatically adjusted!
From this point onwards we need to put our custom code in two places mainly and create a new include (just to be tidy :-)
  1. ZXIMONI_RSXMB_SEL_MSG_SEL represents message monitor selection screen, that is where you enter selection criteria for message retrieval: an additional tab - along with Standard and Advanced selection criteria - needs to be created to host our new selection fields.
  2. ZXIMONI_RSXMB_SEL_MSG_APPL is message monitor real core, in which messages are read from the database based upon the chosen selection criteria. Honestly this is a really a complicated piece of art, and for this reason my way to enhance it is just as simple as possibile. I just let the standard perform its selection and then I filter the result based on my own criteria. I know you could think "Could not be very performant...", and that's true, but as I said, it's the simplest and safest way I think. And it's anyway faster than you opening messages one by one :-)
  3. ZXIMONI_RSXMB_CUSTFILTERS is the heart of our own code, put in the right place of ZXIMONI_RSXMB_SEL_MSG_APPL include (which is an ABAP class actually).

The code

Double click on ZXIMONI_RSXMB_SEL_MSG_SEL include to open its source code.
In the tabbed block


you need to add at the end a new tab just before the end of the block:


Now we need to define screen 850, so put this code wherever you want, but outside of any other block:

For you info, text-xxx are text symbols. I cannot cover them here but just double click on them and ABAP workbench will understand they don't exist and ask you to create them: they provides meaningful descriptions, so just choose what you prefer (you should guess them as far as you see our brand new tab running! :-)
We should be set with the aesthetic part of the work.

Now double click on ZXIMONI_RSXMB_SEL_MSG_APPL include to open its source code (it's a more than 4000 lines program, wow!). Search for this string:

METHOD build_display_list.

and just below it, put this line of code:


Now double click on the newly inserted include name. It'll say it doesn't exist and ask if you wish to create it. Obviously answer yes, assign package and change request, and paste this code inside it.

Find out this line of code (in my version is on line 1165 but this may vary according to SP level) and comment it (put a * as first character), otherwise after selection you will receive a message counting the original number of messages found, without our filter (again, very aesthetic stuff :-)

MESSAGE s100(xms_adm) WITH l_result-text.

Last but not least, a couple of things need to be changed in the main program (ZXMONI_RSXMB_SELECT_MESSAGES).
Find out this event...


... And add management for our new tab:

  ELSEIF g_sel_tab = '''IDOC'''.
    tabstrip_tabstrip-activetab = g_sel_tab.
    tabstrip-dynnr = '0850'.

Finally find out this event:


And change the line below as follows (again to add management for one new tab):

  IF sy-ucomm = '''EXTD''' OR sy-ucomm = '''STRD''' OR sy-ucomm = '''IDOC'''.
That's it.
Now right click on the main program in the left tree and activate the whole stuff.


IDoc search it's not worth an explanation really, obviously in the sense that you may guess by yourself what you will input in the select-options...
Two words about message content (payload) search: put an XPath without the root element. If you have an incoming XML message like this...




... and you're seraching for an XI message with order ID=00123, put in the XPath just:

and not:

Ok? :-)

Last but not least: if the search doesn't seem to work, always keep in mind that standard selection criteria are applied first, so that for example if you're searching for a specific message by Sender IDoc Number in the whole day, you'll have probably to increase "Length of Output List" value at the top of the selection screen, otherwise your message could be the 201st (leaving the stadard value of 200) and it would not be found.


Give it a try and write down the amount of time you'll save by searching messages with our Super Selection Criteria!

Final comment: I don't consider myself an ABAP-monster, and the code I proposed can be enhanced for sure, but I feel in control of myself enough to enjoy a lot!!! :-p

No comments:

Blog Archive