PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom...

21
SDN Contribution PAYLOAD MONITOR FOR SAP XI 3.0 Applies to: SAP Netweaver™ Exchange Infrastructure 3.0 Summary This article gives you a method and necessary coding for Payload Based XI and BPM monitor. Y familiar with ABAP Workbench, BSP and Java coding to apply this article on your system. Plea directly on your productive systems. Special thanks to Hüseyin Bulutoglu for his support on ABAP coding. Created on: 12 April 2006 Author Bio Ibrahim GUNDUZ is a Netweaver consultant working for SAP Türkiye. He is certifi SAP Exchange Infrastructure and SAP Enterprise Portal and KMC. © 2006 SAP AG 1

Transcript of PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom...

Page 1: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

SDN Contribution

PAYLOAD MONITOR FOR SAP XI 3.0 Applies to:

SAP Netweaver™ Exchange Infrastructure 3.0

Summary

This article gives you a method and necessary coding for Payload Based XI and BPM monitor. You must be familiar with ABAP Workbench, BSP and Java coding to apply this article on your system. Please do not try it directly on your productive systems.

Special thanks to Hüseyin Bulutoglu for his support on ABAP coding.

Created on: 12 April 2006

Author Bio

Ibrahim GUNDUZ is a Netweaver consultant working for SAP Türkiye. He is certified on SAP Exchange Infrastructure and SAP Enterprise Portal and KMC.

© 2006 SAP AG 1

Page 2: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

Table of Contents

Purpose of This Document .............................................................................................................. 3

Methodology .................................................................................................................................... 3

Step by Step Solution ...................................................................................................................... 3

Step 1 – Designing Table on ABAP Stack................................................................................... 3

Step 2 – Coding RFC Function for Table Update ........................................................................ 4

Step 3 – Coding User-Defined Java Function in Message Mapping ........................................... 4

Step 4 – Creating BSP Application .............................................................................................. 5

Step 4.a – Creating Remote-Enabled Function Module on Receiver SAP Business System . 6

Step 4.b – Creating BSP Application on SAP XI System......................................................... 7

Step 4.c – Implementing Frame Page “default.htm” ................................................................ 8

Step 4.d – Implementing Search Page “selection.htm”............................................................ 9

Step 4.e – Implementing Results Page “messagelist.htm” .................................................... 11

Step 4.f – Implementing Process Status Page “process.htm”................................................ 14

Disclaimer & Liability Notice .......................................................................................................... 20

Disclaimer & Liability Notice .......................................................................................................... 21

Related Content............................................................................................................................. 21

© 2006 SAP AG 2

Page 3: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

Purpose of This Document

This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload of incoming message, is logged on ABAP stack and searched by a BSP application. The BSP application also is able to show the flow of the Integration Process and status of outbound IDocs on destination systems, if IDoc adapter is being used on outbound side.

Methodology

A simple methodology is used to keep track of incoming data. If a message has been transferred by the adapter successfully;

1. As a first step a message mapping maps requested field value through a user-defined java function, which is put the field value in a table on ABAP stack. The user-defined function is named as SetStatus. Source code is given in step-by step solution.

2. A BSP application makes a simple search on this table (actually selects a record).

3. Search list given as links, and each link opens process tree with status of each passed step. Optionally, you may put some process-control features on the process status page.

Step by Step Solution

Step 1 – Designing Table on ABAP Stack

A table defined on ABAP stack of XI server, in order to hold payload data, with corresponding message GUID including date and time information. The table should have at least sender system and interface information. In our case the table is called ZDURUM. Okay, that might be weird for you, but “DURUM” means “STATUS” in Turkish. You can name it as you want.

Use transaction code SE11 for table definition.

Table Properties Transparent Table ZDURUM

Short Text Table for payload

Delivery and Maintenance Delivery Class A

Fields Field Name Key Init Data Element Data Type Len Dec Short Text

MANDT X X MANDT CLNT 3 0 Client

OBJECT_ID X X DML_OBJECT_UI CHAR 32 0 Object GUID

MSG_GUID X X SXMSMGUID RAW 16 0 XI: Message ID

CHDATE DATUM DATS 8 0 Date

CHTIME UZEIT TIMS 6 0 Time

SENDER_SYS AIT_SNDR CHAR 60 0 Sending System

SENDER_IF RM_OIFNAME CHAR 120 0 Outbound Interface Name

Technical Data Data Class APPL1 Transaction data, transparent tables

Size Category 6 Data records expected: 660.000 to 1.300.000

A primary index will be generated automatically by the system. However, you may define additional index according to your needs.

© 2006 SAP AG 3

Page 4: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

Step 2 – Coding RFC Function for Table Update

You need an RFC enabled ABAP function module to update your tables defined in Step 1 from Message Mapping.

Go to SE37 and create function module “ZSET_STATUS” for this purpose.

FUNCTION ZSET_STATUS. *"---------------------------------------------------------------------- *"*"Local Interface: *" TABLES *" STATUS_TAB STRUCTURE ZDURUM *"---------------------------------------------------------------------- LOOP AT STATUS_TAB. MOVE SY-DATUM TO STATUS_TAB-CHDATE. MOVE SY-UZEIT TO STATUS_TAB-CHTIME. MODIFY STATUS_TAB. ENDLOOP. MODIFY ZDURUM FROM TABLE STATUS_TAB. ENDFUNCTION.

Do not forget to set “Remote Enabled Function Module” property for this function module.

Step 3 – Coding User-Defined Java Function in Message Mapping

Now, you have to proceed with your design of integration and/or process. With your design, you have to decide which field from the incoming message should be kept for search term. Let’s say, you need to keep values of field “INV_NUM”, invoice number. In this case, you have to develop a user-defined java function, which is called “SetStatus” here, in your message mapping. The mapping should like this:

Your java function must be a simple function which imports com.sap.mw.jco.* for connecting to ABAP stack using Java Connector. The necessary java code is given below:

Imports com.sap.mw.jco.*; public String SetStatus(String InvoiceNumber,Container container){ JCO.Repository mRepository;

JCO.Client mConnection = JCO.createClient( "<CLIENT>", // Client "<USERNAME>", // Username "<PASSWORD>", // Password "EN", // Language "<HOSTNAME>", // Host "<SYSNR>"); // System Number

mConnection.connect (); mRepository = new JCO.Repository("SET_STATUS", mConnection); JCO.Function function = null; IFunctionTemplate ft = mRepository.getFunctionTemplate( "ZSET_STATUS" ); function = ft.getFunction(); JCO.Table stattab = null; stattab = function.getTableParameterList().getTable("STATUS_TAB"); stattab.appendRow(); // Write Object Number stattab.setValue(InvoiceNumber, "OBJECT_ID");

© 2006 SAP AG 4

Page 5: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

// Parameter Declarations for Message Header java.util.Map map; String message_id; String sender_sys; String sender_if; String map_trace; // Get Message Header map = container.getTransformationParameters(); // Get Message GUID message_id = (String) map.get("MessageId"); message_id = message_id.trim(); if ( !message_id.equals("") ) { stattab.setValue(message_id, "MSG_GUID"); // Get Sender System Name sender_sys = (String) map.get("SenderService"); stattab.setValue(sender_sys, "SENDER_SYS"); // Get Sender Interface Name sender_if = (String) map.get("Interface"); stattab.setValue(sender_if, "SENDER_IF"); mConnection.execute( function ); } mConnection.disconnect(); return InvoiceNumber;

}

Step 4 – Creating BSP Application

This step is a bit complicated. First, it is important to understand the philosophy, and after that you can make changes according to your needs. First, you try to copy and paste the coding as is.

The BSP application is consist of one frame page and three pages in each frame. The default page “default.htm” will only have frame definitions. A selection page, “selection.htm”, which lets user to make a search, will appear on upper left frame. Search results will be on lower left frame as a link list. And when a user clicks on a link from the search results, process or message status will appear on right frame.

You can see a screenshot of the BSP application below.

© 2006 SAP AG 5

Page 6: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

Search

(selection.htm)

Step 4.a – Creating Remote-Enabled Function Module on Receiver SAP Business System

We will start by writing a remote-enabled function module, which gives status of a given IDoc number. The function will be on the receiver business system, which is considered to have a receiver IDoc adapter. We need to post Sending System and IDoc Number (the number in sending system) to the function, and get a status code, status text and a traffic light from the function. Here is the code:

default.htm

Process Status

(process.htm) Search Results

(messagelist.htm)

FUNCTION ZGET_IDOCSTATUS. *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" VALUE(DOCNUM_S) TYPE EDI_DOCNUM *" VALUE(LOGSYS_S) TYPE LOGSYS *" EXPORTING *" VALUE(DOCNUM_R) TYPE EDI_DOCNUM *" VALUE(STATUS) LIKE EDIDC-STATUS *" VALUE(IDOC_MESSAGE) LIKE BDIDOCATTR-MESSAGE *" VALUE( STALIGHT) TYPE ICON_D *"---------------------------------------------------------------------- DATA: lt_idocs TYPE TABLE OF bdidocrel. DATA: ls_idocs TYPE bdidocrel. DATA: lv_docnum TYPE swotobjid-objkey.

© 2006 SAP AG 6

Page 7: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

DATA: trafficlight TYPE EDI_SLIGHT. REFRESH lt_idocs. CLEAR: docnum_r, status, idoc_message. ls_idocs-docnum_s = docnum_s. ls_idocs-logsys_s = logsys_s. APPEND ls_idocs TO lt_idocs. CALL FUNCTION 'READ_IDOC_INBOUND_OUTBOUND' TABLES idocs = lt_idocs. READ TABLE lt_idocs INTO ls_idocs INDEX 1. docnum_r = ls_idocs-docnum_r. IF docnum_r <> '000000000000000'. lv_docnum = docnum_r. CALL FUNCTION 'GET_STATUS_FROM_IDOCNR' EXPORTING idocnr = lv_docnum IMPORTING status = status. CALL FUNCTION 'IDOC_GET_MESSAGE_ATTRIBUTE' EXPORTING idoc_number = docnum_r IMPORTING idoc_message = idoc_message. ********************************************************************** * Get traffic light for the IDoc status according to the customizing SELECT SINGLE STALIGHT INTO trafficlight FROM STALIGHT AS L INNER JOIN STACUST AS C ON L~STATVA = C~STATVA WHERE C~STATUS = status. CASE trafficlight. WHEN 1. " Yellow light STALIGHT = '@5D@'. WHEN 2. " Green light STALIGHT = '@5B@'. WHEN 3. " Red Light STALIGHT = '@5C@'. WHEN OTHERS. " Question mark STALIGHT = '@8Q@'. ENDCASE. ********************************************************************* ENDIF. ENDFUNCTION.

Step 4.b – Creating BSP Application on SAP XI System

You must create a BSP application from ABAP Development Workbench. Go to transaction code SE80, select BSP Application from the combo box, put the name of new BSP Application, and respond Yes to the creation question. After completing the last step, your BSP will look like this:

© 2006 SAP AG 7

Page 8: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

Note that your BSP Application will have all the staff shown in the picture after you implement all the steps given below.

Step 4.c – Implementing Frame Page “default.htm”

The frame page is an ordinary HTML page. You may refer to http://www.w3schools.com web site if you need more knowledge on HTML coding.

Right click on BSP Application “zstatus” and Add a “Page with Flow Logic”. You have to put the HTML code in Layout tab of the BSP Page.

Here is the HTML code for “default.htm”.

<html> <head> <title>Payload Monitor</title> </head> <frameset cols="450,*" border="0" framespacing="0" frameborder="yes"> <frameset rows="220,*" border="0" framespacing="0" frameborder="no"> <frame src="selection.htm" name="selection" marginwidth="0" marginheight="0" scrolling="no" noresize frameborder="no" border="0" framespacing="0"

© 2006 SAP AG 8

Page 9: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

target="messagelist" > <frame src="messagelist.htm" name="messagelist" marginwidth="0" marginheight="0" scrolling="yes" noresize frameborder="no" border="0" framespacing="0" target="process" > </frameset> <frame src="process.htm" name="process" marginwidth="0" marginheight="0" scrolling="yes" noresize frameborder="no" border="0" framespacing="0" > </frameset> <noframes> <body bgcolor=#FFFFFF> <h2>Non-Frame Browser Detected</h2> <p>You must have frames enabled to view these web pages.</p> </body> </noframes> </html>

Step 4.d – Implementing Search Page “selection.htm”

Add a new page called “selection.htm” with the same method as in the previous step. Basically, a javascript function is submitting the clicked link with its value to the next page. Here is the HTML code of the page:

<%@page language="abap"%> <%@extension name="htmlb" prefix="htmlb"%> <%

© 2006 SAP AG 9

Page 10: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

TYPES: BEGIN OF SENDER_SYS_TYPE, SENDER_SYS TYPE AIT_SNDR, END OF SENDER_SYS_TYPE. DATA: SENDER_SYS_LIST TYPE TABLE OF SENDER_SYS_TYPE INITIAL SIZE 1, WA_SENDER TYPE SENDER_SYS_TYPE. SELECT DISTINCT SENDER_SYS INTO TABLE SENDER_SYS_LIST FROM ZDURUM. %> <script language="JavaScript"> function submitform() { document.selectionform.submit(); } </script> <htmlb:content design="design2003"> <htmlb:page title = "Payload Monitor"> <htmlb:form id="selectionform" method="POST" target="messagelist" action="messagelist.htm"> <htmlb:group title="Selection"> <htmlb:groupBody> <htmlb:gridLayout columnSize="2" rowSize="6" cellSpacing="5" cellPadding="5"> <htmlb:gridLayoutCell columnIndex="1" rowIndex="1"> <htmlb:label for="sendersys" text="Sender System"/> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="2" rowIndex="1"> <htmlb:dropdownListBox id="sendersys" width="197"> <htmlb:listBoxItem key=" " value=" " /> <% LOOP AT SENDER_SYS_LIST INTO WA_SENDER. %> <htmlb:listBoxItem key="<%= WA_SENDER-SENDER_SYS %>" value="<%= WA_SENDER-SENDER_SYS %>" /> <% ENDLOOP. %> </htmlb:dropdownListBox> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="1" rowIndex="3"> <htmlb:label for="begda" text="From Date/Time" /> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="2" rowIndex="3"> <htmlb:inputField id="begda" type="DATE" value="<%= SY-DATUM %>" showHelp="true"/> <htmlb:inputField id="begtim" type="TIME" value="00:00:00" width="50"/> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="1" rowIndex="4"> <htmlb:label for="endda" text="To Date/Time" /> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="2" rowIndex="4"> <htmlb:inputField id="endda" type="DATE" value="<%= SY-DATUM %>" showHelp="true"/> <htmlb:inputField id="endtim" type="TIME" value="23:59:59" width="50"/> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="1" rowIndex="5"> <htmlb:label for="search_term" text="Search Term" /> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="2" rowIndex="5"> <htmlb:inputField id="search_term" type="STRING" width="150"/> </htmlb:gridLayoutCell> <htmlb:gridLayoutCell columnIndex="1" colSpan="2" rowIndex="6" horizontalAlignment="CENTER"> <htmlb:button id="submit" text="Submit" onClientClick="javascript: submitform();"/> </htmlb:gridLayoutCell>

© 2006 SAP AG 10

Page 11: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

</htmlb:gridLayout> </htmlb:groupBody> </htmlb:group> </htmlb:form> </htmlb:page> </htmlb:content>

Step 4.e – Implementing Results Page “messagelist.htm”

In this page, we will put some attributes in order to pass parameters when calling it.

Here are Page Attributes:

Attribute Auto TypingMeth Associated Type Description Begda X TYPE DATUM Date Begtim X TYPE UZEIT Time Endda X TYPE DATUM Date Endtim X TYPE UZEIT Time search_term X TYPE CHAR32 Parameter name

And the following code must reside in the Page Layout:

<%@page language="abap"%> <%@extension name="htmlb" prefix="htmlb"%> <script language="JavaScript"> function submitform() { document.selectionform.submit(); } </script> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"> body, td {padding:2;margin:0;font-family:tahoma,helvetica,sans-serif;font-size:8pt;color:#000;} body {padding-right:5px;background:#F6F9FC;} p {margin:2px 3px;padding:2px 0;} a:link, a:visited {text-decoration:none;color:#333;} a:hover {text-decoration:underline;} .designbar {width:6px;background-color:#525552;} .emphasizeline {height:2px;background-color:#525552;line-height:0;} .trayhead {padding-left:6px;font-weight:bold;color:#525552;}

© 2006 SAP AG 11

Page 12: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

.trayhead {background:#2060C0;} .traycontent {background:#80C0FF;} .trayfooter {height:3px;background:#AEB6BA;text-align:right;} .passivep {background-color:transparent;} .activep {background-color:#FC6;} .activep a:link, .activep a:visited {text-decoration:none;font-weight:bold;color:#000;} .activep a:hover {text-decoration:underline;} a.relogin:link, a.relogin:visited {padding:0 8px 2px 8px;background:#FFF;text-decoration:none;font-size:8pt;color:#666;border:solid 1px #666;border-left-width:8px;} a.relogin:hover {color:#FF7900;border-color:#FF7900;} #navpanelfooter {background:#AEB6BA;vertical-align:top;text-align:center;height:100%;} #ExpandLink {width:15px;height:100%;margin:0;padding:0;background:#FC6;border:solid 1px #FFF;cursor:pointer;} #expcollbar {background:url(/~sapidp/002006825000000023952004E.gif) no-repeat top right #525552;cursor:pointer;} .hidden {display:none;} .visible{display:block;} </style> <% DATA: MSGLIST TYPE TABLE OF ZDURUM INITIAL SIZE 0, MESSAGE TYPE ZDURUM, A(255) TYPE C. CALL FUNCTION 'ZGET_PROCESS_LIST' EXPORTING START_DATE = begda START_TIME = begtim END_DATE = endda END_TIME = endtim SEARCH_TERM = search_term SENDER_SYS = sendersys TABLES MESSAGE_LIST = MSGLIST. %> <htmlb:content design="design2003"> <htmlb:page title = "Message List "> <htmlb:form id="messagelist" method="POST" target="process" action="process.htm"> <table cellpadding="1" cellspacing="0" border="1" id="messages" ct="SapTable" pv="messages_pager" width="430"> <tr class="trayhead"> <td width="100">VIN/CMOS<br>Commission Number</td> <td width="210">Sender System/Interface</td> <td width="60">Date</td> <td width="60">Time</td> </tr> <% LOOP AT MSGLIST INTO MESSAGE. MOVE MESSAGE-MSG_GUID TO A. %> <tr> <td width="100" class="traycontent"><a href="process.htm?MSG_GUID=<%= A %>&OBJECT_ID=<%= MESSAGE-OBJECT_ID %>" target="process"><%= MESSAGE-OBJECT_ID %></td> <td width="200" class="traycontent"><a href="process.htm?MSG_GUID=<%= A %>&OBJECT_ID=<%= MESSAGE-OBJECT_ID %>" target="process"><%= MESSAGE-SENDER_SYS %><br><%= MESSAGE-SENDER_IF %></td> <td width="60" class="traycontent"><a href="process.htm?MSG_GUID=<%= A %>&OBJECT_ID=<%= MESSAGE-OBJECT_ID %>" target="process"><%= MESSAGE-CHDATE %></td>

© 2006 SAP AG 12

Page 13: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

<td width="60" class="traycontent"><a href="process.htm?MSG_GUID=<%= A %>&OBJECT_ID=<%= MESSAGE-OBJECT_ID %>" target="process"><%= MESSAGE-CHTIME %></td> </tr> <% ENDLOOP. %> </table> </htmlb:form> </htmlb:page> </htmlb:content>

You can see that an ABAP function on XI server, ZGET_PROCESS_LIST, is being called by this page. Here is the function module source code:

FUNCTION ZGET_PROCESS_LIST. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(START_DATE) LIKE SY-DATUM OPTIONAL *" VALUE(START_TIME) LIKE SY-UZEIT OPTIONAL *" VALUE(END_DATE) LIKE SY-DATUM OPTIONAL *" VALUE(END_TIME) LIKE SY-UZEIT OPTIONAL *" VALUE(SEARCH_TERM) TYPE CHAR32 OPTIONAL *" VALUE(SENDER_SYS) TYPE AIT_SNDR OPTIONAL *" TABLES *" MESSAGE_LIST STRUCTURE ZDURUM *"---------------------------------------------------------------------- TABLES: ZDURUM. * You may have better ideas for wildcard search * If this is the case, implement your solution CONCATENATE SEARCH_TERM '%' INTO SEARCH_TERM. IF SENDER_SYS NE SPACE. SELECT * FROM ZDURUM INTO TABLE MESSAGE_LIST WHERE CHDATE BETWEEN START_DATE AND END_DATE AND CHTIME BETWEEN START_TIME AND END_TIME AND OBJECT_ID LIKE SEARCH_TERM AND SENDER_SYS EQ SENDER_SYS . ELSE. SELECT * FROM ZDURUM INTO TABLE MESSAGE_LIST WHERE CHDATE BETWEEN START_DATE AND END_DATE AND CHTIME BETWEEN START_TIME AND END_TIME AND OBJECT_ID LIKE SEARCH_TERM . ENDIF. * Sort output list according to date/time SORT MESSAGE_LIST BY CHDATE CHTIME DESCENDING. ENDFUNCTION.

© 2006 SAP AG 13

Page 14: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

Step 4.f – Implementing Process Status Page “process.htm”

The final page is showing our process status with its each passed step. If the passed step generated any IDoc, the IDoc status has been requested from the remote system by the function module given in Step 4.a.

The page has following attributes:

Attribute Auto TypingMeth Associated Type Description MSG_GUID X TYPE SXMSMGUID XI: Message ID OBJECT_ID X TYPE DML_OBJECT_UI Object GUID PROCESS_TREE TYPE TVIEW2 Tree View WI_ID X TYPE SWW_WIID Work item ID

Here, PROCESS_TREE is the main hierarchy in the BSP page to hold message flow. It is declared as TVIEW2 to be used directly in a TreeView control of HTMLB. And the code in the Page Layout is as follows:

<%@page language="abap"%> <%@extension name="htmlb" prefix="htmlb"%> <htmlb:content design="design2003"> <htmlb:page> <htmlb:tray id="process_tray" title="Process Flow for Object <%= OBJECT_ID %>"> <htmlb:form> <htmlb:image id="Refresh" src="@42@" alt="Refresh" tooltip="Refresh Window" onClientClick="javascript: history.go();" /> <htmlb:tree id="Root_Process" table="<%= PROCESS_TREE %>" /> </htmlb:form> </htmlb:tray> </htmlb:page> </htmlb:content>

Now, we need event handlers for our output. First, we generate a tree of the process in OnInitialization event handler:

OnInitialization: REFRESH PROCESS_TREE. CLEAR WI_ID. CALL FUNCTION 'ZGET_PROCESS_HIER' EXPORTING MSG_GUID = MSG_GUID IMPORTING HIER = PROCESS_TREE ROOTPROCESS = WI_ID.

© 2006 SAP AG 14

Page 15: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

And the function module ZGET_PROCESS_HIER that is being called from the event handler above:

FUNCTION ZGET_PROCESS_HIER. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(MSG_GUID) TYPE SXMSGUID OPTIONAL *" EXPORTING *" VALUE(HIER) TYPE TVIEW2 *" VALUE(ROOTPROCESS) TYPE SWW_WIID *"---------------------------------------------------------------------- TYPES: BEGIN OF IDOC_SELECTION, IDOCNUMBER TYPE EDI_DOCNUM, CREDATE TYPE DATUM, CRETIME TYPE UZEIT, IDOCTYP TYPE IDX_IDOCTP, RCVPRN TYPE EDI4RCVPRN, SNDPRN TYPE EDI4RCVPRN, END OF IDOC_SELECTION. DATA: IDOC_TAB TYPE TABLE OF IDOC_SELECTION INITIAL SIZE 1. DATA: WA_IDOC TYPE IDOC_SELECTION. DATA: PROCESSES TYPE SWFXIPROCESS_T, DEPENDENT_PROCESSES LIKE SWWWIHEAD OCCURS 0 WITH HEADER LINE, WA_TREE TYPE LINE OF TVIEW2, WA_TREE_TEMP TYPE LINE OF TVIEW2, MSGSTATUS TYPE LINE OF SXI_MDM_MESSAGE_STATUS_LIST, WA_PROCESS TYPE LINE OF SWFXIPROCESS_T, MESSAGE_GUID TYPE SXMSMGUIDT, MSG_DETAILS TYPE SXMSMSGTAB, WA_MSG_DETAILS TYPE LINE OF SXMSMSGTAB, WORKITEM_ID LIKE SWR_STRUCT-WORKITEMID, MSG_PER_WI LIKE SWR_CONT OCCURS 0 WITH HEADER LINE . DATA: ORIG_MSG_GUID(255) TYPE C. DATA: NODETEXT(255) TYPE C. TABLES: SWWSTATUS, IDXRCVPOR, SXMSMSTAT, SXMSPMAST, SWDSTEXT, ICON. * Preserve original message ID MOVE MSG_GUID TO ORIG_MSG_GUID. ********************************************************************************** DISPLAY ORIGINAL XML MESSAGE *********************************************************************************PERFORM APPEND_XML_NODE TABLES HIER USING '' " Parent ORIG_MSG_GUID " Child ORIG_MSG_GUID " Text '1' " Level . ********************************************************************************** Check if top level message has initiated an IDoc *********************************************************************************REFRESH IDOC_TAB. SELECT IDOCNUMBER CREDATE CRETIME IDOCTYP RCVPRN SNDPRN FROM IDXRCVPOR INTO TABLE IDOC_TAB WHERE GUID = ORIG_MSG_GUID. IF SY-SUBRC EQ 0. LOOP AT IDOC_TAB INTO WA_IDOC. PERFORM APPEND_IDOC_NODE TABLES HIER

© 2006 SAP AG 15

Page 16: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

USING ORIG_MSG_GUID " Parent WA_IDOC-IDOCNUMBER " IDoc Number WA_IDOC-IDOCTYP " IDoc Type '2' " Level WA_IDOC-RCVPRN " Receiver WA_IDOC-SNDPRN " Sender . ENDLOOP. ENDIF. CLEAR MSG_DETAILS. REFRESH MESSAGE_GUID. APPEND MSG_GUID TO MESSAGE_GUID. CALL FUNCTION 'SXMB_SELECT_MESSAGES' EXPORTING IM_MSGGUID_TAB = MESSAGE_GUID IMPORTING EX_MSGTAB = MSG_DETAILS. CLEAR MSG_GUID. LOOP AT MSG_DETAILS INTO WA_MSG_DETAILS. * Find message ID on outbound side MOVE WA_MSG_DETAILS-EO_REFVL_O TO MSG_GUID. ENDLOOP. CLEAR PROCESSES. * Get process ID on BPE CALL FUNCTION 'SWF_XI_MESSAGE_PROCESSES_GET' EXPORTING IM_MSGGUID = MSG_GUID IMPORTING EX_PROCESS = PROCESSES. LOOP AT PROCESSES INTO WA_PROCESS. ROOTPROCESS = WA_PROCESS-WI_ID. ********************************************************************************** PUT ROOT PROCESS ON TOP ********************************************************************************* PERFORM APPEND_WI_NODE TABLES HIER USING ORIG_MSG_GUID " Parent WA_PROCESS-WI_ID " Work Item ID WA_PROCESS-WI_TYPE " Work Item Type WA_PROCESS-WI_TEXT " Text '1' " Level WA_PROCESS-WI_STAT " Status . ********************************************************************************** Find child processes ********************************************************************************* REFRESH DEPENDENT_PROCESSES. * Get child processes CALL FUNCTION 'SWI_GET_DEPENDENT_WORKITEMS' EXPORTING WI_ID = WA_PROCESS-WI_ID TABLES DEPENDENT_WIS = DEPENDENT_PROCESSES. SORT DEPENDENT_PROCESSES. LOOP AT DEPENDENT_PROCESSES. * If child process has a task assignment, get task text * otherwise put workitem text on output IF DEPENDENT_PROCESSES-WI_RH_TASK EQ SPACE. NODETEXT = DEPENDENT_PROCESSES-WI_TEXT. ELSE. SELECT SINGLE WFD_TEXT INTO NODETEXT FROM SWDSTEXT WHERE WFD_ID = DEPENDENT_PROCESSES-DEF_GUID+14(10) AND VERSION = DEPENDENT_PROCESSES-DEF_GUID+24(4) AND

© 2006 SAP AG 16

Page 17: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

LANGUAGE = DEPENDENT_PROCESSES-DEF_GUID+28(1) AND NODEID = DEPENDENT_PROCESSES-DEF_GUID+29(10) AND EXETYP = DEPENDENT_PROCESSES-DEF_GUID+39(1) . IF SY-SUBRC NE 0. NODETEXT = DEPENDENT_PROCESSES-WI_TEXT. ENDIF. ENDIF. PERFORM APPEND_WI_NODE TABLES HIER USING DEPENDENT_PROCESSES-PARENT_WI " Parent DEPENDENT_PROCESSES-WI_ID " Work Item ID DEPENDENT_PROCESSES-WI_TYPE " Work Item Type NODETEXT " Text '4' " Level DEPENDENT_PROCESSES-WI_STAT " Status . ********************************************************************************** Get XML Message ********************************************************************************* MOVE DEPENDENT_PROCESSES-WI_ID TO WORKITEM_ID. REFRESH MSG_PER_WI. DATA: RETCODE LIKE SY-SUBRC, XML1 TYPE XSTRING, XML2 TYPE XSTRING, SIMPCONT LIKE SWR_CONT OCCURS 0, MSGLINES LIKE SWR_MESSAG OCCURS 0, MSGSTRUCT LIKE SWR_MSTRUC OCCURS 0, BOROBJECTS LIKE SWR_CONT OCCURS 0 . CALL FUNCTION 'SAP_WAPI_READ_CONTAINER' EXPORTING WORKITEM_ID = WORKITEM_ID LANGUAGE = SY-LANGU USER = SY-UNAME IMPORTING RETURN_CODE = RETCODE IFS_XML_CONTAINER = XML1 IFS_XML_CONTAINER_SCHEMA = XML2 TABLES SIMPLE_CONTAINER = SIMPCONT MESSAGE_LINES = MSGLINES MESSAGE_STRUCT = MSGSTRUCT SUBCONTAINER_BOR_OBJECTS = BOROBJECTS SUBCONTAINER_ALL_OBJECTS = MSG_PER_WI . LOOP AT MSG_PER_WI WHERE ELEMENT = 'MESSAGE_SENT'. * Check if message processed in CENTRAL pipeline SELECT SINGLE * FROM SXMSPMAST WHERE MSGGUID = MSG_PER_WI-VALUE AND PID = 'CENTRAL'. IF SY-SUBRC EQ 0. SELECT IDOCNUMBER CREDATE CRETIME IDOCTYP RCVPRN SNDPRN FROM IDXRCVPOR INTO TABLE IDOC_TAB WHERE GUID = MSG_PER_WI-VALUE. PERFORM APPEND_XML_NODE TABLES HIER USING DEPENDENT_PROCESSES-WI_ID " Parent MSG_PER_WI-VALUE " Child MSG_PER_WI-VALUE " Text '5' " Level . LOOP AT IDOC_TAB INTO WA_IDOC. PERFORM APPEND_IDOC_NODE TABLES HIER USING MSG_PER_WI-VALUE " Parent WA_IDOC-IDOCNUMBER " IDoc Number

© 2006 SAP AG 17

Page 18: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

WA_IDOC-IDOCTYP " IDoc Type '6' " Level WA_IDOC-RCVPRN " Receiver WA_IDOC-SNDPRN " Sender . ENDLOOP. ENDIF. ENDLOOP. ENDLOOP. ENDLOOP. ENDFUNCTION.

We used forms in an Include to make code understandable. Basically, APPEND_WI_NODE appends a node of work item to the tree, APPEND_IDOC_NODE appends a node of IDoc to the tree and APPEND_XML_NODE appends an XML message node to the tree. You can double click on the form name which is after PERFORM command to create them.

*&---------------------------------------------------------------------* *& Form APPEND_WI_NODE *&---------------------------------------------------------------------* FORM APPEND_WI_NODE TABLES TREE TYPE TVIEW2 USING PARENT WI_ID WI_TYPE TEXT LEVEL WI_STATUS . DATA: NODE TYPE LINE OF TVIEW2. NODE-TREEID = 'Root_Process'. NODE-PARENTID = PARENT. NODE-CHILDID = WI_ID. NODE-TEXT = TEXT. NODE-TLEVEL = LEVEL. NODE-STATUS = 'OPEN'. NODE-TOOLTIP = WI_STATUS. SELECT SINGLE I~ID INTO NODE-IMG FROM ICON AS I INNER JOIN SWWSTATUS AS S ON S~ICON = I~NAME WHERE S~WI_STATUS = WI_STATUS. * If the process is wait step and status is waiting then display proceed link IF WI_TYPE EQ 'E' AND WI_STATUS EQ 'WAITING'. NODE-CLICK = WI_ID. NODE-TOOLTIP = 'Click to cancel WAITING and proceed'. ENDIF. APPEND NODE TO TREE. ENDFORM. " APPEND_WI_NODE *&---------------------------------------------------------------------* *& Form APPEND_IDOC_NODE *&---------------------------------------------------------------------* FORM APPEND_IDOC_NODE TABLES TREE TYPE TVIEW2 USING PARENT IDOC_NUM

© 2006 SAP AG 18

Page 19: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

IDOC_TYPE LEVEL RECEIVER SENDER . DATA: NODE TYPE LINE OF TVIEW2. DATA: REMOTE_IDOCNUM TYPE EDI_DOCNUM, REMOTE_IDOCSTAT TYPE EDI_STATUS, REMOTE_IDOCTEXT TYPE IDOC_MSG. NODE-TREEID = 'Root_Process'. NODE-PARENTID = PARENT. NODE-CHILDID = IDOC_NUM. NODE-TLEVEL = LEVEL. NODE-LINK = ''. NODE-TOOLTIP = ''. NODE-STATUS = 'OPEN'. CALL FUNCTION 'ZGET_IDOCSTATUS' DESTINATION RECEIVER EXPORTING DOCNUM_S = IDOC_NUM LOGSYS_S = SENDER IMPORTING DOCNUM_R = REMOTE_IDOCNUM STATUS = REMOTE_IDOCSTAT IDOC_MESSAGE = REMOTE_IDOCTEXT STALIGHT = NODE-IMG . CONCATENATE '(' IDOC_TYPE '-' REMOTE_IDOCSTAT '-' REMOTE_IDOCNUM ')' REMOTE_IDOCTEXT INTO NODE-TEXT SEPARATED BY SPACE. APPEND NODE TO TREE. ENDFORM. " APPEND_IDOC_NODE *&---------------------------------------------------------------------* *& Form APPEND_XML_NODE *&---------------------------------------------------------------------* FORM APPEND_XML_NODE TABLES TREE TYPE TVIEW2 USING PARENT CHILD MSG_GUID LEVEL . DATA: NODE TYPE LINE OF TVIEW2. NODE-TREEID = 'Root_Process'. NODE-PARENTID = PARENT. NODE-CHILDID = CHILD. NODE-TEXT = MSG_GUID. NODE-TLEVEL = LEVEL. NODE-STATUS = 'OPEN'. NODE-TOOLTIP = 'Click to see message'. SELECT SINGLE I~ICON_ID INTO NODE-IMG FROM SXMSMSTAT AS I INNER JOIN SXMSPMAST AS S ON S~MSGSTATE = I~MSGSTATE WHERE S~MSGGUID = MSG_GUID. MOVE MSG_GUID TO NODE-LINK. CONCATENATE '/sap/bc/gui/sap/its/webgui/!?~transaction=SXI_SHOW_MESSAGE&MSGGUID=' MSG_GUID '&PID=CENTRAL&~okcode=DISP'

© 2006 SAP AG 19

Page 20: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

'&target=_new' INTO NODE-LINK. APPEND NODE TO TREE. ENDFORM. " APPEND_XML_NODE

Finally, we need to implement OnInputProcessing event handler to be able to skip waiting steps manually. This feature is asked by the customer. Assuming that you have many wait steps in your process (for example waititng for IDoc to be processed, or waiting after an alert for correction) you may need to let end user who monitors the process skip wait by clicking on the step name:

OnInputProcessing: IF event_id = CL_HTMLB_MANAGER=>EVENT_ID. * Read event from manager. DATA: event_data TYPE REF TO IF_HTMLB_DATA. DATA: WORKITEM_ID TYPE SWW_WIID. event_data = CL_HTMLB_MANAGER=>get_event_ex( request ). DATA inputfield_event TYPE REF TO CL_HTMLB_INPUTFIELD. IF event_data IS NOT INITIAL. IF event_data->event_id = 'Root_Process'. " Cancel waiting and proceed MOVE event_data->event_server_name TO WORKITEM_ID. CALL FUNCTION 'SWW_WI_ADMIN_STOP_WAITING' EXPORTING WI_ID = WORKITEM_ID DO_COMMIT = 'X' AUTHORIZATION_CHECKED = 'X' PRECONDITIONS_CHECKED = 'X' EXCEPTIONS OTHERS = 5 . ENDIF. ENDIF. ENDIF.

© 2006 SAP AG 20

Page 21: PAYLOAD MONITOR FOR SAP XI 3 · Purpose of This Document This document introduces a custom developed message monitor based on SAP XI 3.0. Simply, content of a field, from payload

Disclaimer & Liability Notice

This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

Related Content

1. Super Message Monitor for SAP XI

© 2006 SAP AG 21