Skip to Content

Usage of Mapping Runtime Constants

APPLIES TO :

SAP Process Integration 7.1 and Above Versions.

Accessing Mapping Runtime Constants through SAP PI graphical maps.

SYNOPSIS :

In many of the SAP PI scenarios it is required to send certain SAP PI Runtime Constant to the target system. These are mainly Mapping Runtime Constants those are present in the XI Message Header. These parameters and their values can be accessed by mapping programs. The mapping runtime saves the fields as key-value pairs. Some Mapping API’s provide string constants to access mapping runtime constants.

Author: Shreya Sen Gupta

Company: IBM Global Business Services, India.

Created on: 22nd May 2013

Shreya Sen Gupta is a SAP Technical Consultant in IBM Global Business Services. She is working with IBM since 2010 and presently involves with pharma- based project, which is one of the biggest implementation projects in IBM. Her technical expertise includes SAP Process Integration,JAVA/J2EE and MDM. She has experience of working in diverse SAP Landscapes and with different integrations.

TABLE OF CONTENTS :

1 INTRODUCTION………………………………………………………………………………….. 3

2 ACCESSING CONTAINER OBJECTS…………………………………………………………. 3

3 KEY – VALUE PAIRS………………………………………………………………………………. 4

4 SCENARIO DESCRIPTION……………………………………………………………………… 5

5 STEP BY STEP PROCESS……………………………………………………………………….. 6

6 TESTING THE SCENARIO………………………………………………………………………. 9

7 SUMMARY………………………………………………………………………………………… 11

INTRODUCTION :

Sometimes it may be necessary to access fields in message header (mapping runtime constants) into mapping programs.  This is required either to populate the value to the target field or just to change the value at runtime. Mapping runtime constants can be used to get access to those values. The mapping constants are saved as key-value pairs.  The message header of an XI message contains values for a particular attributes that can be used to write additional information or changed at runtime.

This article describes one way of using mapping runtime constants “TimeSent” and usage of Dynamic Configuration. This scenario will populate file name with timestamp dynamically in the message header for one interface, along with that populating a target field with the same filename with timestamp in a different mapping for other interface.

ACCESSING CONTAINER OBJECTS

When using the container object, one do not just temporarily save values for a user-defined function, one can also access the following objects as well:

           MappingTrace object to write messages to the trace. 

           GlobalContainer object to exchange values between different user-    defined functions.

           Map object to access mapping runtime constants.

The following figure shows how the GlobalContainer and Container objects access mapping runtime constants.

                                Capture.PNG

                              

KEY/VALUE PAIRS :

In XI Message Header, Runtime Constants are stored as key-value pairs. Examples of Key-Value Pairs in the Map for Runtime Constants

Key

Value

MessageClass

ApplicationMessage

ProcessingMode

synchronous

ReceiverNamespace

http://com.sap/xi/example

The keys are derived from the field names of the fields in the message header. To be able to read the fields of the message header at runtime, one must access the map for the runtime constants. However, if one has to access the map by using the keys specified above and one of the keys were to change, the program code would be rendered invalid. For this reason, the mapping API provides string constants that can be used to access the map in place of the keys.

SCENARIO DESCRIPTION :

Simple example is taken for demonstration of accessing mapping values.

Two Message mappings in two different Operation Mapping will be triggered at the same time, first is a SOAP to File scenario and the second is SOAP to Idoc scenario.

First mapping will populate the file name (at a particular timestamp, specifically at the time the message is sent) in Runtime at message header via Dynamic Configuration.

Second mapping, will populate the same file name (at a particular timestamp, specifically at the time the message is sent) in a target field of Idoc.

Diagrammatic Representation:

                                                                        Capture.PNG

STEP BY STEP PROCESS :

Message Mapping 1                                                                    Capture.PNG

Accessing mapping constants in message mapping is done by “Container” object (“getTransformationParameters” method).

This UDF will populate the file name with a timestamp (when the message is sent by the sender) at the Message Header during runtime.

Code for UDF : dyncon_filename

public String dyncon_filename(Container container) throws StreamTransformationException{

try {

String filename    = “”;

//String timestamp = “”;

DynamicConfiguration conf1 = (DynamicConfiguration) container

    .getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key1 = DynamicConfigurationKey.create( “http:/”+”/sap.com/xi/XI/System/File”,”FileName”);

String  time;

// get runtime constant map

  1. java.util.Map map;

map = container.getTransformationParameters();

// get value of header field by using variable key

time = (String) map.get(“TimeSent”);

time=time.replaceAll(“-“,””);

time=time.replaceAll(“:”,””);

time=time.replaceAll(“T”,””);

time=time.replaceAll(“Z”,””);

filename=”spotqoute_”+time+”.txt”;

conf1.put(key1,filename);

//filename1 = filename;

return “”;

}

catch(Exception e)

{

     String exception = e.toString();

      return exception;

}

}


Message Mapping 2

                                                                              Capture.PNG

In the second mapping populating a target field from a UDF, containing the file name with the exact time stamp (when the message is sent by the sender).

Code for UDF : Populate_FileName

public String Populate_FileName(Container container) throws StreamTransformationException{

try {

String  time;

// get runtime constant map

  1. java.util.Map map;

map = container.getTransformationParameters();

// get value of header field by using variable key

time = (String) map.get(“TimeSent”);

time=time.replaceAll(“-“,””);

time=time.replaceAll(“:”,””);

time=time.replaceAll(“T”,””);

time=time.replaceAll(“Z”,””);

String filename=”spotqoute_”+time+”.txt”;

return filename;

}

catch(Exception e)

{

     String exception = e.toString();

      return exception;

}

}

TESTING THE SCENARIO :

Message is triggered from RWB.

Integration Engine Monitor:

                                                                                 Capture.PNG

As per requirement, interface will branch to two separate messages for two different receiver interfaces.

First one is SOAP to File scenario, populating file name dynamically.

File name: spotqoute_20130427190415.txt

Execution after First operation Mapping:


                                                                    Capture.PNG

Second one is SOAP to Idoc scenario, populating file name at the particular time in a target field.

File name: spotqoute_20130427190415.txt

Execution after Second operation Mapping:

                                                 Capture.PNG

SUMMARY :

In this scenario I have tried to explain the usage of mapping runtime constant those are available in the XI Message Header. Here I have used runtime constant TimeSent to achieve the business requirement. This parameter returns the time stamp specifying the message was sent by the sender. The format of the time stamp is as follows : YYYY-MM-DDTHH:MM:SSZ. The letter ‘T’ separates the Time from the Date.


In our code we have removed the characters ‘-’, ‘:’, ‘T’ and ‘Z’ because we do not require them in our file name.

There are other runtime constant available as well which can be use for different requirements.

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply