Bit460 en Col95 FV Part A4 Notes
Bit460 en Col95 FV Part A4 Notes
PI Message Mapping
SAP NetWeaver Process Integration
Date
Training Center
Instructors
Education Website
Participant Handbook
Course Version: 95
Course Duration: 2 Day(s)
Material Number: 50102743
No part of this publication may be reproduced or transmitted in any form or for any purpose
without the express permission of SAP AG. The information contained herein may be changed
without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software
components of other software vendors.
Trademarks
• Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are
registered trademarks of Microsoft Corporation.
• IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®, MVS/ESA®, RS/6000®, AIX®,
S/390®, AS/400®, OS/390®, and OS/400® are registered trademarks of IBM Corporation.
• ORACLE® is a registered trademark of ORACLE Corporation.
• INFORMIX®-OnLine for SAP and INFORMIX® Dynamic ServerTM are registered
trademarks of Informix Software Incorporated.
• UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of the Open Group.
• Citrix®, the Citrix logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®,
VideoFrame®, MultiWin® and other Citrix product names referenced herein are trademarks
of Citrix Systems, Inc.
• HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World
Wide Web Consortium, Massachusetts Institute of Technology.
• JAVA® is a registered trademark of Sun Microsystems, Inc.
• JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for
technology invented and implemented by Netscape.
• SAP, SAP Logo, R/2, RIVA, R/3, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP
EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP.com Logo and mySAP.com
are trademarks or registered trademarks of SAP AG in Germany and in several other countries
all over the world. All other products mentioned are trademarks or registered trademarks of
their respective companies.
Disclaimer
THESE MATERIALS ARE PROVIDED BY SAP ON AN "AS IS" BASIS, AND SAP EXPRESSLY
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR APPLIED, INCLUDING
WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE, WITH RESPECT TO THESE MATERIALS AND THE SERVICE,
INFORMATION, TEXT, GRAPHICS, LINKS, OR ANY OTHER MATERIALS AND PRODUCTS
CONTAINED HEREIN. IN NO EVENT SHALL SAP BE LIABLE FOR ANY DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES OF ANY
KIND WHATSOEVER, INCLUDING WITHOUT LIMITATION LOST REVENUES OR LOST
PROFITS, WHICH MAY RESULT FROM THE USE OF THESE MATERIALS OR INCLUDED
SOFTWARE COMPONENTS.
g2011421568
About This Handbook
This handbook is intended to complement the instructor-led presentation of this
course, and serve as a source of reference. It is not suitable for self-study.
Typographic Conventions
American English is the standard used in this handbook. The following
typographic conventions are also used.
Example text Screen output. This includes file and directory names
and their paths, messages, names of variables and
parameters, and passages of the source text of a
program.
Example text Exact user entry. These are words and characters that
you enter in the system exactly as they appear in the
documentation.
<Example text> Variable user entry. Pointed brackets indicate that you
replace these words and characters with appropriate
entries.
Icon Meaning
Exception or caution
Procedures
Course Prerequisites
Required Knowledge
• BIT400 (SAP NetWeaver Process Integration)
Recommended Knowledge
• JA100 (SAP J2SE Fundamentals)
Course Goals
This course will prepare you to:
Course Objectives
After completing this course, you will be able to:
Unit Overview
This short introductory unit introduces general mapping tasks and discusses
operation mappings.
Unit Objectives
After completing this unit, you will be able to:
• Create an Operation Mapping
• Check the inbound and outbound service interfaces
• List the available mapping program types for PI
Unit Contents
Lesson: Creating an Operation Mapping .......................................2
Exercise 1: Create an Operation Mapping .................................9
Lesson Overview
This lesson shows you how to create an operation mapping to connect operations
from service interfaces with one another. The lesson also introduces general
mapping tasks, and provides an overview of mapping program types.
Lesson Objectives
After completing this lesson, you will be able to:
• Create an Operation Mapping
• Check the inbound and outbound service interfaces
• List the available mapping program types for PI
Business Example
You are responsible for creating Operation Mappings and need to understand
the types of mapping programs that can be used in an Operation Mapping in SAP
NetWeaver Process Integration (PI).
About PI Mapping
SAP NetWeaver Process Integration mediates the message transfer between sender
and receiver systems, and in most cases these systems use different interfaces.
Thus, PI has to perform a mapping between the outbound interface of the sender
and the inbound interface of the receiver interface (or interfaces). Concepts to be
applied in mapping are:
• Structure mapping
You must define mapping rules to assign fields that are semantically identical.
• Value mapping
You must define conversion rules to transfer the field content to the target
format.
The figure Concepts Implemented in Mapping details both of these concepts.
Firstly, the source message and the target message each have their own individual
structures. These differing structures require a structure mapping. Secondly, the
value business of the source field class has to be transformed into the value 2 in
the Class target field, using a value mapping.
Operation Mapping
You use an operation mapping to relate an operation of an outbound service
interface with an operation of an inbound service interface. Operation mapping is
configured to reference mapping programs, which mediate between the different
message types of two operations (from service interfaces), as illustrated in the
following figure. Various mapping programs can be used as required to mediate
between the output, input, and fault message types.
Mapping-Program Types
The figure Mapping Objects provides an overview of the mapping program
types in Enterprise Services Repository, and the use of operation mappings in the
Integration Directory.
Mapping programs used to map message types can be realized in the following
different ways:
• Message mapping
You create a Message Mapping graphically using the mapping editor in the
Enterprise Services Builder.
• Java mapping class
You create a Java Mapping Class in a Java IDE, and import it into Enterprise
Services Repository
• XSL transformation
You create an XSL transformation “externally” and import it into Enterprise
Services Repository.
• ABAP-XSL transformation
You create an ABAP-XSL transformation on the Integration Server (in the
ABAP stack) and reference it from within an operation mapping.
• ABAP mapping class
You create an ABAP mapping class on the Integration Server (in the ABAP
stack) and reference it from within an operation mapping.
• The first mapping program must have the appropriate source message.
• The output of each mapping program must match the input of the subsequent
mapping program.
• The last mapping program must have the appropriate target message.
• Identical or different mapping types are possible.
• The sequence in which mapping programs are to be executed is specified.
Hint: Not every mapping has to have the same source and target messages.
When you use the F4 help to select message mappings, you must not use any
search criteria for the source and target messages. Otherwise only those message
mappings that exactly match the expected source and target messages will be
displayed.
Hint: You cannot use the Enhanced Receiver Determination on the AEX
(Advanced Adapter Engine Extended) because the AEX is configured
with an Integrated Configuration, which does not support Enhanced
Receiver Determination.
Business Example
Part of your daily responsibilities requires that you create and manage operation
mappings.
• XSL
• ABAP Class
• ABAP XSL
Lesson Summary
You should now be able to:
• Create an Operation Mapping
• Check the inbound and outbound service interfaces
• List the available mapping program types for PI
Unit Summary
You should now be able to:
• Create an Operation Mapping
• Check the inbound and outbound service interfaces
• List the available mapping program types for PI
Unit Overview
Introduction to message mapping.
Unit Objectives
After completing this unit, you will be able to:
Unit Contents
Lesson: Creating a Message Mapping........................................ 18
Exercise 2: Create a Message Mapping ................................. 27
Lesson: Testing a Message Mapping ......................................... 32
Exercise 3: Test a Message Mapping..................................... 39
Exercise 4: Create the Configuration ..................................... 41
Lesson: Using Message-Mapping Functions................................. 50
Exercise 5: Use Standard Message-Mapping Functions............... 57
Lesson Overview
This lesson introduces the basic concepts of the mapping editor and shows you
how to use the mapping editor to create a message mapping.
Lesson Objectives
After completing this lesson, you will be able to:
• Create a message mapping
• Use the mapping editor and explain how it works
Business Example
You are responsible for the development of mappings in SAP NetWeaver Process
Integration and must be able to create, modify, and manage mappings that are
developed. For this reason, you need to know:
• How the mapping editor works
• How to modify the message-mapping structure
• How to make use of variables and advanced functions in the mapping editor
The data flow editor can contain multiple target fields with identical (or at least
similar) target-field mappings. This feature not only simplifies the mapping
procedure, it also enables you to execute complex functions once and assign the
resulting value to multiple target fields. For performance reasons, we highly
recommend that you use this feature.
Hint: To create a variable, use the context menu for a field in the target
structure that possesses additional subelements and choose Add Variable.
The mapping editor inserts the variable as the first subnode of the field.
This variable is visible for all nodes at the same hierarchy level and all
subnodes.
You can use the Var variable as a target field, too, or define a target-field mapping
for Var in the data flow editor. In the target-field mapping, you can also use values
from variables that appear before Var in the structure flow.
To use a variable as a source field in a target-field mapping, drag the variable
to the data flow editor.
Business Example
You are responsible for mapping one message structure (type) to another. For this
reason, you want to create a message mapping and use it in an operation mapping.
Task 1:
Create a message mapping to map message types MtCustomerName and MtName.
1. Create the new message mapping MM_CustomerNameMerge.
In software component version SC_BIT_MAP, 1.0, in your
namespace http://educationsap.com/pi/mapping##, create the
message mapping MM_CustomerNameMerge to map the
message types MtCustomerName (SWCV SC_BIT_MAP,
1.0, namespace http://educationsap.com/pi/mapping##) and
MtName (SWCV SC_BIT_BASE_COMP, 1.0, namespace
urn:educationsap.com:bit:mapping) to one another.
Map the two fields Surname and Name from the source structure so that they
are separated by a blank in MtName.
The sequence must be: first name, then surname.
Task 2:
Reference the message mapping in the operation mapping OM_CustomerIn-
foMap.
1. Reference the message mapping MM_CustomerNameMerge in the operation
mapping OM_CustomerInfoMap.
Task 2:
Reference the message mapping in the operation mapping OM_CustomerIn-
foMap.
1. Reference the message mapping MM_CustomerNameMerge in the operation
mapping OM_CustomerInfoMap.
a) Display the operation mapping.
In your namespace http://educationsap.com/pi/mapping##, navigate
to the Operation Mappings node and open the operation mapping
OM_CustomerInfoMap by double-clicking it.
b) Maintain the message mapping.
Switch to change mode and use the input help on tab Request in the
section below Mapping Program to select your message mapping
MM_CustomerNameMerge.
c) Save and activate the operation mapping.
Lesson Summary
You should now be able to:
• Create a message mapping
• Use the mapping editor and explain how it works
Lesson Overview
This unit explains how message mappings function and what options you have for
testing. You will also learn how to create and test a configuration.
Lesson Objectives
After completing this lesson, you will be able to:
• Test a message mapping
• Use trace information to help debug issues that arise during the testing
process
• Create and test a configuration scenario
Business Example
You are responsible for the development of mappings in SAP NetWeaver Process
Integration and need to know how message mappings function. You also need an
overview of the tools the mapping editor provides to enable you to test message
mappings.
To help you understand the reasons for unexpected mapping results or why
exceptions occur at runtime, note the following points, which explain how
message mappings are processed at runtime:
1. Source Fields:
Source fields are read into queues by the message mappings. This procedure
improves performance and enables large messages to be processed, since
the entire message does not actually have to be stored in the memory as
a tree structure.
2. Queues:
Queues are processed by the functions of the target-field mappings.
Additional functions can be allocated to the result queues if multiple
functions are called in succession.
3. Target Fields:
Values from the result queues are used to fill the target fields. As part of
the process, the values are compared to the attributes for occurrence (the
number of times a field appears in one or more hierarchy structures) in the
following way:
• Upper Occurrence Limit:
If the upper limit for the number of occurrences of a target field is
exceeded, additional result values from the result queue are ignored.
• Lower Occurrence Limit:
If the lower limit for the number of occurrences of a field is not reached,
an exception is triggered.
Message-Mapping Queues
A message-mapping queue consists of all the values of a field in the data flow
editor. This applies to source fields, target fields, and any fields created by
mapping steps. These queues serve as important tools for testing since you can
display them in the message mapping as soon as test data is available. This applies
not only to source fields, but to every processing step in the message mapping
process.
The message-mapping process makes use of the following queues:
• Inbound queue
Data from fields in the source message
• Processing queue
Data from inbound queues, which is being processed by the message-mapping
template
• Result queue
Data for entry in fields in the target message
Hint: You can debug the individual steps in the message-mapping process
by displaying the queue for each function in the message mapping. This is
explained in more detail in the Queues and Context lesson.
Trace Messages
During runtime testing, it is possible to write information about the current status
of the message-mapping process to a trace file. You can view the tracing data in
the trace area for the message in the message monitor (SOAP Header → Trace).
However, you can only view the trace data the earliest after the message mapping
successfully completes, that is, after the processing step Request Message
Mapping. You can also view the trace data when testing message mappings in
Enterprise Services Repository, assuming the trace level there is set accordingly.
You can assign trace messages any trace level, regardless of their level of
importance (priority). The following trace levels are possible:
• 1 (Information)
• 2 (Warning)
• 3 (Debug)
Pipeline processing is also specified a trace level. You can only see a trace
message in the monitor if its priority has at least the same trace level as the
pipeline processing. If the trace level of the pipeline, for example, is level 1,
debug messages, which are level 3, are not displayed.
Hint: You specify the trace level of the pipeline in the configuration for
the Integration Engine. Call transaction SXMB_ADM, choose Integration
Engine Configuration and, under Specific Configuration Data, choose
RUNTIME as the category and TRACE_LEVEL as the parameter.
After you load an XML file or create an empty XML structure, you can set the
values and attributes in either the graphical editor or the text-based editor. In the
graphical editor, you can use the options in the context menu to duplicate subtrees,
delete nodes, and add elements or attributes. In the text-based editor, you have
to perform each of the add, delete, and duplicate steps manually. However, the
text-based editor enables you to create test cases for PI scenarios quickly and
easily by using the copy-and-paste feature.
You can also use header parameters when testing. Header parameters are not
business fields in the payload; header parameters are meta information such as
the sender interface - parameters that are available as runtime constants in the
PI-SOAP message header at runtime.
When you start the mapping process for testing purposes, you can observe the test
results in the structure overview for the target fields.
Business Example
You want to check whether a message mapping you created functions correctly,
without having to apply it at runtime.
Task:
Test your message mapping MM_CustomerNameMerge.
1. Open your message mapping MM_CustomerNameMerge.
2. Maintain your test data and perform a test.
3. Create a test case.
Business Example
You want to test your mapping at runtime using a configured scenario.
Task:
Configure a scenario between the sender BC_CI_Requestor_## and the
receiver Training with the interfaces CustomerInformation_Request
and CustomerInformation_Provide using your operation mapping
OM_CustomerInfoMap.
1. Create a new configuration scenario CS_BIT_CustomerInfo_##.
2. Create a new business component BC_CI_Requestor_## and add it to
your configuration scenario CS_BIT_CustomerInfo_##.
3. Maintain the sender interface for the Business Component.
Maintain the sender interface CustomerInformation_Request from your
namespace http://educationsap.com/pi/mapping## for your business
component BC_CI_Requestor_##.
4. Create a communication channel BC_CI_Req_##_HTTP_Sender for
sender BC_CI_Requestor_##.
Adapter Type shall be HTTP, Sender.
5. Create a sender agreement for sender BC_CI_Requestor_##, interface Cus-
tomerInformation_Request and channel BC_CI_Req_##_HTTP_Sender.
6. Create a receiver determination for sender BC_CI_Requestor_## and
the sender interface CustomerInformation_Request from the namespace
http://educationsap.com/pi/mapping## and maintain the business system
Training as the receiver.
7. Create an interface determination for this receiver determination.
Specify CustomerInformation_Provide as the receiver interface in the
namespace urn:educationsap.com:bit:mapping. Reference your operation
mapping OM_CustomerInfoMap as the mapping.
8. Create a receiver agreement for the parameters mentioned above, by
referencing the existing communication channel Training_Proxy_In.
Start the HTTP client and send a suitable request. Test the result in the HTTP
client and in the message monitor of the Integration Server.
a) Open the HTTP client.
Open the HTTP client from the file share. Your instructor will tell you
where to find the file.
b) Start the HTTP client.
This simulates an application that generates an XML document and
then sends it to the SAP PI pipeline by using the HTTP adapter. If
necessary, correct the details for the sender service so that they match
those for your scenario configuration.
c) Transfer the document to the pipeline; choose Send.
Since this involves synchronous communication (quality of service is
BE for “Best Effort”), a response appears in the form under Result
in the last text area.
d) Check the status of the test message.
Call transaction SXI_MONITOR on the Integration Server and check
the processing of your messages in the message monitor.
e) Display trace information.
Navigate to the detail view of your message and open the trace (under
SOAP Header → Trace) in the processing step Request Message
Mapping in either one of the windows.
f) Locate the trace messages relating to message-mapping and operation
mapping.
At the bottom of the trace area, you can find the message indicating
which operation mapping and mapping program were executed:
<Trace level="1" type="T">
Operation Mapping http://educationsap.com/pi/mapping##
OM_CustomerInfoMap</Trace>
<Trace level="2" type="T">Mode 0</Trace>
<Trace level="2" type="T">
...
Call method execute of the application Java mapping
com.sap.xi.tf._MM_CustomerNameMerge_</Trace>
<Trace level="2" type="T">
Java mapping com/sap/xi/tf/_MM_CustomerNameMerge_
completed.
executeStep() of com.sap.xi.tf._MM_CustomerNameMerge_
</Trace>
Lesson Summary
You should now be able to:
• Test a message mapping
• Use trace information to help debug issues that arise during the testing
process
• Create and test a configuration scenario
Lesson Overview
This lesson explains how to use standard functions in message mapping
and provides examples of how some of the more common functions can be
implemented. You will also learn how to create and make use of user-defined
functions in message mapping.
Lesson Objectives
After completing this lesson, you will be able to:
• Implement standard functions in your own message mappings
• Create and implement user-defined functions in message mappings
Business Example
You are responsible for the development of mappings in SAP NetWeaver Process
Integration and require an overview of the purpose and use of standard functions
for message mapping in the mapping editor. You also need to understand how to
create user-defined functions in message mapping.
Note: Input values and returned output values are mandatory for all
functions except generating functions. For example, a constant function
does not require input values.
For some functions, you must set parameters. For example, the separator property
in the concat function must be defined. You can enter values for parameters by
double-clicking the function used in the data-flow editor. A function handles all
source and target fields as strings. For none string input parameters (for example,
integers), the contents of that parameter undergo a data-type conversion (casting).
If the values cannot be converted successfully, the mapping runtime triggers
a Java exception.
The following figure illustrates how to use the standard text function substring.
Note that parameters must be set for this function.
The dateTrans function has some enhanced settings. For example, in addition to
date formats, the numbering for weekdays and calendar weeks is country-specific.
You define the necessary conventions for this in the function properties.
• First Weekday
This parameter defines which day of the week is the first day of the week.
For example, in the USA it is Sunday, but in France it is Monday. The
numbering starts at 1.
• Minimum Number of Days Required in the First Week
This parameter defines how many days the first week of a year must have for
it to be counted as the first calendar week.
• Calendar Is Lenient
This checkbox enables you to control whether invalid dates trigger an
exception or not.
Hint:
The user-defined function is included in the Java coding that is generated for the
message mapping as a Java method. The new (user-defined) function is visible
in the data flow editor in the function category that you assigned to the function
in the function properties. You can insert user-defined functions in the data flow
editor in the same way as you insert a standard message-mapping function.
Function Action
Category
Constant Generate a value for a target field rather than take the value
functions: from a source field, for example: Constant and CopyValue.
Function Action
Category
Statistical Designed for source fields that occur more than once in the
functions: message-mapping source structure (maxOccurs = i > 1),
for example: sum (sum of values in a context), average
(average of values in a context), and count (number of
fields in a context).
Business Example
A specific mapping task requires you to use standard functions in a graphical
mapping.
Task:
You want to create a graphical mapping between the message types Contact1 and
Customer1 by using standard functions.
1. Create a message mapping called ContactToCustomer1.
Reference the message type Contact1 as the source structure and the message
type Customer1 as the target structure. Both message types are in SWCV
SC_BIT_MAP, 1.0 in namespace urn:educationsap.com:bit:mapping (under
Basis Objects).
Hint: To select the source and target structures, select the message
type from the navigation tree and drag it to the relevant field using
drag and drop.
Hint: To select the source and target structures, select the message
type from the navigation tree and drag it to the relevant field using
drag and drop.
Create a graphical mapping between the source field contactID and the target
field birthday. The last six digits of the source field are for the birthday date.
It should be stored in the format yyyy/dd/MM.
a) Select the fields to connect.
Drag the birthday target field to the data flow editor by using drag and
drop. Drag the contactID source field to the data flow editor by using
drag and drop.
b) Select the function to use in the connection.
In the lower screen area of the data flow editor, choose Text Functions.
Select the substring function and drag it to the data flow editor by using
drag and drop.
c) Select the function to use in the connection.
In the lower screen area of the data flow editor, choose Date Functions.
Select the DateTrans function and drag it to the data flow editor by
using drag and drop.
d) Connect the fields in the data flow editor as follows:
birthday = DateTrans(Substring(contactID))
Use 11..17 as parameters in the substring function by double-clicking
the substring function and setting the Starting Position to 11 and the
Number of Characters to 6.
Use ddMMyy as the source format and yyyy/dd/MM as the target format
in the DateTrans function by double-clicking the DateTrans function
and entering ddMMyy as the inbound data format and yyyy/dd/MM as
the outbound data format.
5. Connect source and target fields.
Create an identical graphical mapping between the source fields firstname
and custname, and the target fields fullname and surname.
a) Drag the firstname target field to the firstname source field by using
drag and drop.
b) Drag the surname target field to the custname source field by using drag
and drop. Then save your mapping.
6. Test the mapping.
Use the mapping editor to test function. The field contactID should now
have the value 0123456789-181170.
a) Create a new XML instance.
To create a new XML instance, choose the Test tab page and then
Create Instance. Expand the nodes in the XML instance and populate
the fields with test values.
b) Start the message-mapping test.
Execute the mapping by choosing Execute Mapping.
Lesson Summary
You should now be able to:
• Implement standard functions in your own message mappings
• Create and implement user-defined functions in message mappings
Unit Summary
You should now be able to:
• Create a message mapping
• Use the mapping editor and explain how it works
• Test a message mapping
• Use trace information to help debug issues that arise during the testing
process
• Create and test a configuration scenario
• Implement standard functions in your own message mappings
• Create and implement user-defined functions in message mappings
Unit Overview
Unit Objectives
After completing this unit, you will be able to:
• Create a message mapping that makes use of contexts
• Set and delete the message-mapping context
• Use advanced options to help debug the message-mapping process
• Create user-defined functions and use them in the mapping editor
• Define and use both local and global user-defined functions
• Create function libraries and include them in a message mapping
• Change queues and contexts using standard and user-defined functions
• Work with mapping objects
• Output messages in the trace log
Unit Contents
Lesson: Using Contexts in Message Mapping ............................... 66
Exercise 6: Create a Message Mapping with Context Handling ...... 83
Lesson: Working with User-Defined Functions .............................. 88
Exercise 7: Create and Use Local User-Defined Functions ..........103
Exercise 8: Create and Use a Function Library ........................ 113
Exercise 9: Work with Local and Global User-Defined Functions ... 117
Exercise 10: Use variables in user-defined functions .................129
Lesson Overview
In this lesson, you learn how to use queues, contexts, and advanced options to help
improve the message-mapping process.
Lesson Objectives
After completing this lesson, you will be able to:
• Create a message mapping that makes use of contexts
• Set and delete the message-mapping context
• Use advanced options to help debug the message-mapping process
Business Example
You are responsible for the development of mappings in SAP NetWeaver Process
Integration and require an overview of the advanced message-mapping options
that queues and contexts provide.
Hint: Even if elements can occur more than once in the XML instance
according to XML schema definition, they are only displayed once in the
structure overview. In the test area, you can use the context menu to copy
individual fields or entire subtrees, which allows you to create and test
them with any desired number of occurrences.
An icon precedes every field in the structure overview. These icons indicate the
status of a field, as illustrated in the following table:
Elements
Elements with maxOccurs > 1
Nodes
The information displayed in Status of Fields, Attributes, and Nodes tells us the
following about the status of fields and nodes:
• Contactln node:
Contains an attribute with the name Type. Both icons are green, which
indicates that an assignment was already made.
• Name node:
Contains the two elements, Firstname and Surname. The red icon for both
elements indicates that they are mandatory fields, and that values still need to
be entered for them. This means the mapping is not yet complete.
• Surname field:
The field must be created and filled only once.
• Firstname field:
The field can be created and filled more than once.
• Occurrences column:
Indicates that all the target structure elements mentioned above must be
created and filled at least or exactly once.
• Address node
The Address node and its subelements Street, CityCode, City, Phone, and
Email can be created in the target structure, since the minimum number of
occurrences is 0.
Hint: The icons preceding the Address fields are white indicating
that they do not have to be created in the target structure.
The following table summarizes the meaning associated with the icon color, for
example, green, red, or white.
Hint: The colors are only displayed in the target structure because the
mapping is a target-field mapping, responsible for creating a valid target
structure. Whether the source structure is valid can be checked with XML
validation as a pipeline step (not inside mapping).
Message-Mapping Queues
Message mapping is performed at runtime using queues. A queue contains all
values relating to a field in the message mapping. There is a queue for each XML
hierarchy level. If you have created an XML instance in the test environment
editor, you can display the various queues in the data flow editor. The following
queues can exist at message-mapping runtime:
• Source Structure:
A queue exists for each field in the source structure.
• Input and Result Queues:
Standard and user-defined functions process the input queues and write the
result of a calculation to a result queue; the result queue of one function can
also serve as the input queue for another function.
• Target Fields:
A queue exists for the target field; the limitations of the target fields determine
which values from the target-field queue are written in the target structure.
Hint: Each field is determined by the field name and the structure
hierarchy in which it exists. If two fields have the same name but occur on
different levels (“paths”) then two separate queues are created.
The queue concept enables large XML messages to be processed quickly, since the
entire XML tree does not need to be built each time, only the values of a hierarchy
level. This can be done using a SAX parser; a DOM parser (which builds the entire
XML tree for an XML file) would use both too much memory and CPU time.
The input queues for the concat function in the following example have a different
number of values in the related contexts. If, for this reason, an input value from
a queue is missing for a function, the message mapping runtime simply uses the
last value that was read from the queue:
Hint: In both figures, the queues are read from right to left, which means
the values 1 and a are processed first.
The same also applies to generating functions (such as constants) that only
generate one value when they are linked to a function. If an additional input queue
has more than one value in a context, the mapping runtime simply reuses the last
value returned by the generating function.
Message-Mapping Contexts
The context of a field can also be understood as a type of association, that is,
as a description of the structure or hierarchy in which the field occurs. A field
can contain multiple contexts if the field exists in a series of structure levels
in a hierarchical manner. If a field is part of a structure that can have multiple
occurrences (occurrences > 1), this is referred to as a context change for the field.
Hint: If a field occurs more than once (occurrence > 1) within one
structure, this does not constitute a context change, since the field occurs
more than once within the same structure (that is, the same context).
If there is a context change within the hierarchy, this is shown in the relevant
queue. This concept is illustrated in detail in the figure Context Changes in XML
Files. For the item element, for example, there are two context changes, since the
item element occurs in the context of three nodes with the name A. This results in
two context changes for the queue on the hierarchy level of the item element.
Context changes can be created and deleted with both standard functions and
user-defined functions. This enables a direct influence on the hierarchy levels
in the source message. User-defined functions are explained in more detail in
subsequent lessons.
Hint: Values can only be filled in open contexts; otherwise values are lost.
Open contexts are generated when the parent node is created.
changes located under this level are deleted. This method provides an elegant way
of solving the task of context selection for source fields, and enables users to avoid
multiple use of the standard function RemoveContexts() in the message mapping.
However, the function RemoveContexts() still has its advantages, since it proves
useful in target-field mappings comprised of function chains.
You use the exists() standard function to determine whether a particular source
field exists in the XML instance being processed. If it does, exists() returns true;
if it does not, it returns false. This is useful, for example, if you want to map an
optional source field to an obligatory target field because you can check whether
the field (not the contents) actually exists and if necessary, transfer a constant
instead.
The last standard function discussed here is copyValue(). For a field with
an occurrence of > 0, this function enables you to copy the individual values
separately to multiple target fields. If a source structure contains a field with the
name addrDat and the field has three values, you can map these three values to
the street, city, and zipcode target fields by using copyValue() (and specifying
an index):
/ns0:MT_B/street=CopyValue(/ns0:MT_A/addrDat, nnumber=0)
/ns0:MT_B/city=CopyValue(/ns0:MT_A/addrDat, nnumber=1)
/ns0:MT_B/zipcode=CopyValue(/ns0:MT_A/addrDat, nnumber=2)
A simple mapping example should clarify the issues described above. The
following figure shows the source and target structures and the corresponding
mapping.
To show more clearly how the target structure is created, an actual message from a
sender system is used here as a basis for creating the target fields.
Hint: The attribute setting minOccurs > 0 for a field does not necessarily
mean that the field will be existing in the target message. Assuming that
the field is part of a structure node with minOccurs = 0, and if no mapping
is assigned to that structure, neither the structure nor the subordinate fields
are created. In the example, this applies to node B and field item.
The number of occurrences for the item target field is between 1 and unbounded.
In practice, however, this field cannot be created an infinite number of times. How
often the mapping program creates this field in this case ultimately depends on the
corresponding source fields, how often they occur, and the relevant target-field
mapping.
Hint: Note that the term context menu refers to the menu that you navigate
to by right-clicking. The term context has two different meanings here.
The message mapping in the figure Message Mapping for the Target Field
Description illustrates an example of a more complex message mapping for the
target field Description.
First of all, the source field LANGKEY is compared with the constant EN. If this
comparison is successful, the contents of the source field TEXT are copied to
the target field Description. The figure Debugging View of the Target-Field
Mapping Description illustrates the contents of the corresponding queue. Based
on the contents of the queue equalsS the value [true] is only determined in the
second case. This means that the content toothpaste is copied from the middle
field TEXT to the target field Description. This result is represented in the queue
for the IfWithoutElse element.
Business Example
A specific mapping task requires you to use queues and contexts to check a
message mapping.
Task:
Map a source message containing material data, a material number, and
descriptions in various languages to a target message containing the material
number and the description of the material in English.
1. Create a message mapping with the name MaterialToProductDef-
inition for software component version SC_BIT_MAP 1.0 in your
namespace http://educationsap.com/pi/mapping##.
The message mapping must reference the message type MATERIAL as
the source structure and the message type ProductDefinition as the target
structure.
2. Transfer the source field to the target field.
The message mapping requires that you first transfer the source field MATNO
to the target field RefNo. You then need to check the source field LANGKEY
for EN and copy the corresponding contents of the source field TEXT to
the target field Description.
3. Test the new message mapping.
Use the mapping editor test function to test the message mapping. For the
purposes of the test, create at least three different entries for the MATTEXT
node, and give each of them different values for the LANGKEY field, one of
which must be EN. Display the resulting queues.
4. Change the language for the Langtext of the material and test the mapping
again.
The message mapping requires that you first transfer the source field MATNO
to the target field RefNo. You then need to check the source field LANGKEY
for EN and copy the corresponding contents of the source field TEXT to
the target field Description.
a) Map source and target fields.
Create an identical mapping between the source field MATNO and the
target field RefNo. Drag the RefNo target field to the MATNO source
field by using drag and drop.
b) Load the mapped fields into the data flow editor.
Load the Description target field into the data flow editor by
double-clicking it. Drag the TEXT and LANGKEY source fields to the
data flow editor by using drag and drop.
c) Set the mapping context.
Set the context for the source fields TEXT and LANGKEY to Material
by choosing Context → MATERIAL in the context menu.
d) Select the Text and Boolean message-mapping functions.
From the Text function category, choose the equalsS function, and from
the Boolean Functions area, choose the IfWithoutElse function, and
drag them to the data flow editor using drag and drop.
e) Select the Constant message-mapping function.
Select the Constant function from the Constant Functions area and drag
it to the data-flow editor by using drag and drop.
f) Connect source and target message-mapping fields.
Connect the fields in the data flow editor as follows:
Description = IfWithoutElse(equalsS(LANGKEY, Constant), TEXT)
Choose EN as the parameter for the Constant function by
double-clicking the Constant function and entering EN as the parameter.
Save your mapping.
3. Test the new message mapping.
Use the mapping editor test function to test the message mapping. For the
purposes of the test, create at least three different entries for the MATTEXT
node, and give each of them different values for the LANGKEY field, one of
which must be EN. Display the resulting queues.
a) Create a new XML instance.
Choose the Test tab page and create a new XML instance by choosing
Generate Instance. Create at least three different entries for the
MATTEXT node by clicking Duplicate Subtree with the secondary
mouse button. Expand the nodes in the XML instance and populate
the fields with test values.
b) Start the message mapping.
Start the mapping by choosing Execute Mapping. Choose Design and
double-click the target field Description. Call the context menu for the
functions displayed in the data-flow editor and choose Display Queue.
Track the contents of the queue for the entire message mapping.
4. Change the language for the Langtext of the material and test the mapping
again.
a) Confirm the message-mapping mode.
Make sure that the message mapping is in change mode.
b) Display the message mapping for the target field.
Open the existing mapping for the target field Description by
double-clicking the field to load it into the data flow editor.
c) Edit the Constant function.
Open the editor for the Constant function by double-clicking the field,
change the displayed value from EN to (for example) FR, and close
the editor.
d) Start the message mapping.
Repeat the message-mapping test as outlined in the previous step.
Lesson Summary
You should now be able to:
• Create a message mapping that makes use of contexts
• Set and delete the message-mapping context
• Use advanced options to help debug the message-mapping process
Lesson Overview
This lesson shows how to use the mapping editor to employ user-defined
functions in message mappings. The lesson illustrates the difference between
local user-defined functions and global user-defined functions, which are created
in function libraries. The lesson also describes how you can use user-defined
functions to change queues and contexts.
Lesson Objectives
After completing this lesson, you will be able to:
• Create user-defined functions and use them in the mapping editor
• Define and use both local and global user-defined functions
• Create function libraries and include them in a message mapping
• Change queues and contexts using standard and user-defined functions
• Work with mapping objects
• Output messages in the trace log
Business Example
You are responsible for the development of mappings in SAP NetWeaver Process
Integration. You need to understand how to use advanced message-mapping
options to map field contents, including those for source and target structures with
different numbers of occurrences. You also need to know how to enhance standard
message-mapping functions with your own user-defined functions (and various
objects) to automate particular aspects of the message-mapping process.
The parameters of a user-defined function such as the name, title, description, and
execution type are important.
• Function name:
The technical name (the name of the Java method)
• Function title:
The name of the function in the data flow editor
• Execution type:
Controls how the function behaves during message mapping
You create user-defined functions in the Functions tab of the message mapping.
You can define the number, names, and types of function transfer arguments in the
Signature Variables area. Once you have created a user-defined function, you can
use it in the Design tab (in the data flow editor) in the same way you would use
a standard function. The only difference is that the new user-defined function is
displayed in the User-Defined area in the list of standard functions.
window. You can use these parameters in the Java code by entering the names
specified in the interface (Name string, Surname string, ...). In this example, the
result must be returned as a string via return (depending on the Execution Type.
The figure above provides a simple example of the source code for a user-defined
function. The three input parameters are typed as String, are merged into one
string, and then returned by the function via return.
After you create a function, it is displayed in the Functions selection in the data
flow editor. You can delete or edit functions at any time, either in the Functions
tab, or in the Design tab, in the data flow editor.
Testing the message mapping (menu Message Mapping - Check or F7) will check
the java source code
Functions Libraries
A function library is a separate object type in Enterprise Services Repository
and can therefore be created via the context menu of, for example, a namespace
or software component version, for example: Context menu → New → Mapping
Objects → Function Library. You must assign a name to the function library and
then assign the function library to a software component version and one of the
namespaces contained therein.
Hint: You must ensure that the function library is located in the same
software component version as the message mappings you want to use
or an underlying version.
After you create global user-defined functions in a function library, you can use
them in a message mapping. You can include function libraries in your message
mapping by making an entry in Used Function Libraries and using the input help
to select the function library required. The selected function library appears in the
Functions list in the mapping editor. When you select the function library from
the list, all the functions defined there appear in the mapping editor as pushbuttons
and can be used for the individual target-field mappings.
The following figure illustrates the concept of execution types using an inbound
queue as an example. The example shows how many times the function was called
internally for each of the execution types.
Hint: Note that when large messages are processed, much cache memory
is required at runtime to save the entire queue. In such cases, it is better to
work with contexts.
The name of the Execution Type parameter has changed over the last few
releases. The table below shows the names used in the individual releases of
SAP NetWeaver Process Integration:
The outbound queue is set up using the addValue method of the result object,
which simply attaches the transferred single value to the outbound queue (string
array). The mapping task requires all values in the outbound queue to be separated
by a context change. You do this using the addContextChange method of the
result object.
When the inbound queue is transferred to a function, the first and last context
changes are suppressed, that is, the string array always starts and ends with an
entry for the relevant field. This also applies for the outbound queues to be created;
the first and last entries in the result string array must not be context changes.
Hint: In the mapping editor, context changes are indicated by dark gray
bars in the queues. However, the values of the previous entries are also
displayed in these bars, which may cause confusion at first.
• Container:
The Container object can be used to create an AbstractTrace object as well
as a Map object.
• AbstractTrace:
Hint: Similar goals can be achieved with the Java Sections, so the
GlobalContainer will not be discussed in detail.
Container Object
The Container object belongs to the interface of user-defined functions, which
means you use the object to make available additional objects and user-defined
parameters.
The methods for the Container object are outlined in the following table.
Trace Objects
In user-defined functions, you can use the AbstractTrace object to transfer
messages to the mapping trace. To create an AbstractTrace object, call the
getTrace() method for the container object.
...
AbstractTrace at = container.getTrace();
at.addInfo( "This is an information" );
at.addWarning( "This is a warning!" );
at.addDebugMessage( "This is a debug message" );
...
You can display the messages that you write to the trace with these methods in the
test environment, for example. You can also set a trace level for each pipeline so
that the trace messages are written to the trace header of the message at runtime.
The trace levels 0 to 3 are associated with the trace levels info, warning, and
debug as follows:
Map Objects
A map object enables you to access message-mapping runtime constants. Some
mapping programs need to access fields in the message header. To facilitate this,
the mapping runtime stores the values of the fields as key-value pairs.
To read the fields of the message header at runtime, you must access the map for
the runtime constants. However, accessing the map using the key literals listed
above would render the program code invalid if a key is changed at some point
in the future. As an alternative, the mapping API provides string constants that
you can use instead of key literals to access the map.
You can use the map object to access runtime constants in user-defined constants.
The map object is created using either the Container object or a GlobalContainer
as illustrated in the following code example:
String headerField;
java.util.Map map;
map = container.getTransformationParameters();
AbstractTrace at = container.getTrace();
at.addInfo(headerField);
return a;
Java Sections
When you create a local user-defined function in a message mapping, the system
creates a Java class in the background. You can define attributes in this Java class
that can then be used in all user-defined functions for this message mapping.
When this class is created, two methods are also created automatically: init and
cleanUp. When the mapping is run, these two methods are called automatically:
init is called prior to the message mapping and cleanUp is called afterwards, for
example, to remove data from the memory that is no longer required once the
message mapping is complete. Initially, neither method contains source code, but
you can program this yourself.
The Java sections can be found in the message mapping on the Functions tab
page. Here you can define, for example, the interface of the init method and the
source code.
Java sections do not exist only in (local) user-defined functions; every function
library has its own Java sections. If you use multiple function libraries in one
message mapping, there are multiple areas in which attributes and methods are
defined, as well as multiple init and cleanUp methods. This source code is run
either at the start or end of the mapping runtime based on the order in which you
have entered the relevant function libraries in the table that defines library usage.
After Java classes have been imported in this way, you can use them in the message
mapping by entering the relevant imported archive in the message mapping in
the Archives Used area on the Functions tab page. You then have to specify the
relevant class and package name in the Import Instructions area. You can then use
all the methods of this class in the user-defined methods for the message mapping.
In the following example, the addCounter method of the imported class myClass
is to be used in the user-defined function addCounter. First, go to the Archives
Used area and enter the imported archive IA_MyPackage mentioned above.
Then go to the Import Instructions area and enter the package and class name
myPackage.myClass.
Business Example
A specific mapping task requires you to use queues, contexts, and user-defined
functions in message mapping.
Task:
The source message contains purchase order information. It can contain multiple
purchase orders. Each purchase order has header information and several ordered
objects. The target message is a table containing the same number of rows as there
are ordered objects. Each row contains the relevant header information for the
corresponding purchase order.
This kind of mapping program is very useful for processing IDocs in tables. Here,
too, the header information has to be added for each IDoc entry in the row.
There are numerous ways to handle this mapping task. The solution described here
is just one of these many possibilities.
1. Create a new message mapping.
Create a message mapping with the name PurchaseOrderToResultset
in software component version SC_BIT_MAP, 1.0 in your namespace
http://educationsap.com/pi/mapping##. In the message mapping, reference
the message type PurchaseOrder as the source structure and the message
type resultset as the target structure.
2. Map the message fields.
Create an identical mapping between the source and target fields Material,
Units, and Price.
3. Remove context of source object item.
To create exactly the same number of rows row as objects item, you have
to move the source field item from its context in the message mapping and
connect it to the target field row.
4. Create a user-defined function with the name copyPerValue.
To make sure that the header entries of the individual source objects are
copied enough times, you can create a user-defined function with the name
copyPerValue. You use that function to copy any source field to an array,
as specified by the number of item source fields.
5. Define the user function.
Combine the copyPerValue function with the source fields Name and Address
and the SplitByValue function so that the correct number of target fields
name and address are created in the target structure.
6. Test the mapping by using the mapping editor test function.
7. Additional Task I:
Create another user-defined function and name it copyPerValueWithQueue.
In this function, do not use the SplitByValue function as you did in Step 6,
but enter the relevant code to handle the context changes in the source text.
8. Additional Task II:
Instead of your user-defined function copyPerValue, use the standard
function useOneAsMany for the Name target-field mapping.
Create an identical mapping between the source and target fields Material,
Units, and Price.
a) Drag the material target field to the Material source field by using
drag and drop.
b) Drag the units target field to the Units source field by using drag and
drop.
c) Drag the price target field to the Price source field by using drag and
drop.
3. Remove context of source object item.
To create exactly the same number of rows row as objects item, you have
to move the source field item from its context in the message mapping and
connect it to the target field row.
a) Load the source and target fields.
Load the row target field into the data-flow editor by double-clicking
it. Drag the item source field to the data-flow editor by using drag and
drop.
b) Locate the removeContexts function.
In the lower screen area of the data-flow editor, choose Node Functions.
Select the removeContexts function and drag it to the data-flow editor
by using drag and drop.
c) Include the removeContexts function.
Connect the fields in the data-flow editor as follows:
row = removeContexts(item)
4. Create a user-defined function with the name copyPerValue.
To make sure that the header entries of the individual source objects are
copied enough times, you can create a user-defined function with the name
copyPerValue. You use that function to copy any source field to an array,
as specified by the number of item source fields.
a) Create the user-defined function copyPerValue.
Create a user-defined function by selecting the relevant icon in the
toolbar at the bottom of the data-flow editor. Enter copyPerValue as the
name and copyPerValue as the title to appear in the data-flow editor.
Fill the Description field and set the Execution Type field to All Values
of Context. Using the first icon, insert a second argument var2 of type
string after argument var1. Choose Create Function.
b) Define the user function copyPerValue.
Enter the following source code in the new user-defined function :
for (int i=0; i<var1.length; i++) {
result.addValue(var2[0]);
}
Combine the copyPerValue function with the source fields Name and Address
and the SplitByValue function so that the correct number of target fields
name and address are created in the target structure.
a) Specify source and target fields.
Load the name target field into the data-flow editor by double-clicking
it. Drag the source fields Name and item to the data-flow editor by
using drag and drop.
b) Specify a user-defined function.
In the lower screen area of the data-flow editor, choose User-Defined
Functions. Select the copyPerValue function and drag it to the data-flow
editor by using drag and drop.
c) Specify a node function.
In the lower screen area of the data-flow editor, choose Node Functions.
Select the SplitByValue function and drag it to the data-flow editor by
using drag and drop.
d) Define the function usage.
Connect the fields in the data-flow editor as follows:
name = SplitByValue(copyPerValue(item, Name))
e) Specify source and target fields.
Load the address target field into the data-flow editor by double-clicking
it. Drag the source fields Address and item to the data-flow editor by
using drag and drop.
f) Specify a user-defined function.
In the lower screen area of the data-flow editor, choose User-Defined
Functions. Select the copyPerValue function and drag it to the data-flow
editor by using drag and drop.
g) Specify a node function.
In the lower screen area of the data-flow editor, choose Node Functions.
Select the SplitByValue function and drag it to the data-flow editor by
using drag and drop.
h) Define the function usage.
Connect the fields in the data-flow editor as follows:
address = SplitByValue(copyPerValue(item, Address))
Save your mapping.
Load the target field into the data-flow editor by double-clicking it,
remove the connecting arrow from the address target field, and remove
the source fields by choosing Delete Floating Objects on the left-hand
side of the data flow editor.
e) Select the source fields to map.
Drag the source fields Address and item to the data-flow editor by using
drag and drop.
f) Select the user-defined function.
In the lower screen area of the data-flow editor, choose User-Defined
Functions. Select copyPerValueWithQueue and drag the function to the
data-flow editor by using drag and drop.
g) Assign the user function.
Connect the fields in the data-flow editor as follows:
address = copyPerValueWithQueue(item, Address)
h) Save the message mapping.
i) Test the message mapping.
Choose the Test tab page and use the test case already created to test
your change by choosing Start Transformation.
8. Additional Task II:
Business Example
In your company, you are responsible for mapping and have to process mappings
for different scenarios. When doing so, you realize that you sometimes need to use
the same user-defined functions in different message mappings.
Task:
For the message mapping in this task, you need a copy of the local
user-defined function copyPerValue that was defined in the message mapping
PurchaseOrderToResultset in the previous exercise. You need to create a function
library containing the new global copyPerValue function. You must include your
new function library in the message mapping PurchaseOrderToResultset and
replace the local user-defined function copyPerValue with the global user-defined
function of the same name.
1. Create a function library.
Create function library FL_## in your namespace http://education-
sap.com/pi/mapping##.
2. Create a global function.
In your function library FL_## (namespace http://educationsap.com/pi/map-
ping##), create a global function called copyPerValue that has the same
interface, properties, and code as the local function copyPerValue from your
PurchaseOrderToResultset message mapping.
3. Include the new global function in the message mapping.
In your PurchaseOrderToResultset message mapping, replace the local
user-defined function copyPerValue with the corresponding global function
from your function library FL_##.
4. Test your message mapping PurchaseOrderToResultset.
Navigate to the target-field mapping for the name target field and
replace the local user-defined function copyPerValue with the global
function copyPerValue from your function library FL_##.
1. In the Functions field of the mapping editor, select FL_## and
double-click copyPerValue so that the global function is displayed
in the target-field mapping for the name field.
2. Remove all connections for the local function copyPerValue and
connect it to the relevant box of the global function copyPerValue.
3. Delete the floating objects by choosing the relevant pushbutton on
the right-hand side of the mapping editor.
d) Include a new (global) function in a target field.
Navigate to the target-field mapping for the Address target field and
replace the local user-defined function copyPerValue with the global
function copyPerValue from your function library FL_##.
1. In the Functions field of the mapping editor, select FL_## and
double-click copyPerValue so that the global function is displayed
in the target-field mapping for the Address field. .
2. Remove all connections for the local function copyPerValue and
connect it to the relevant box of the global function copyPerValue.
3. Delete the floating objects by choosing the relevant pushbutton on
the right-hand side of the mapping editor.
e) Remove the reference to the unused local function.
In the Functions field of the mapping editor, select User-Defined and
delete your local function copyPerValue by opening the selection menu
for the copyPerValue button and choosing Delete Function.
f) Save your message mapping.
4. Test your message mapping PurchaseOrderToResultset.
a) Choose the Test tab page and use the test data from the previous exercise
to test your message mapping by choosing Start Transformation
(bottom left).
Business Example
A specific mapping task requires you to use local and global user-defined functions
in graphical mapping.
Task:
The source message contains purchase order information. This contains header
information and multiple detailed purchase orders. Each of these detailed purchase
orders contains a supplier name. Each supplier can have multiple purchase
orders, and the exact number of suppliers in the source message is unknown. In
addition, the purchase orders are not sorted according to supplier. The target
message contains a purchase order for each supplier. Each entry for a supplier is to
contain the header information from the source message and the corresponding
purchase orders.
There are numerous ways to handle this mapping task. The solution described here
is just one of these many possibilities.
1. Create a message mapping with the name OrderToSortedOrder.
2. Specify the source and target message type.
3. Determine the number of suppliers; this establishes the required number of
target fields Orders.
Create a user-defined function with the name getSuppliers with the
input parameter supplier (and Execution Type = All Values of Context). This
function tests all Supplier source fields and returns each supplier only once.
4. Assign the header information to each Orders purchase order in the target
structure:
The global function copyPerValue from the function library FL_## created in
the last exercise is to be used later in this step. For this reason, you should
include this function library in your message mapping now.
5. Determine the number of target fields Items for each supplier.
Hint: Use the explicit context change for POCombined for all source
fields under the Detail source node (Supplier, ProductID, Quantity,
Price), so that all source fields are available in the main context.
8. Test the mapping by using the mapping editor test function. For test
purposes, use a header and four details with two different Suppliers.
The global function copyPerValue from the function library FL_## created in
the last exercise is to be used later in this step. For this reason, you should
include this function library in your message mapping now.
a) List the currently used function libraries.
Choose Show Used Function Libraries (top left pushbutton in the
mapping editor) and insert a new line in the Function Libraries Used
area that is currently open by choosing Insert Line Below Selection.
b) Insert the new function library.
Use the input help for the Function Library field to fill the new line
with the function library FL_## that you created in the last exercise.
5. Determine the number of target fields Items for each supplier.
7. Execute the message mapping for the individual target fields; to complete the
mapping program, you need eight graphical mappings.
Hint: Use the explicit context change for POCombined for all source
fields under the Detail source node (Supplier, ProductID, Quantity,
Price), so that all source fields are available in the main context.
a) Connect the target field Orders and the source field Supplier:
1. Drag the target field Orders and the source field Supplier to the
data-flow editor by using drag and drop.
2. In the lower part of the data flow editor, choose the User-Defined
function category, then the getSuppliers function, and drag this to
the data flow editor by using drag and drop.
3. Connect the fields in the data-flow editor as follows: Orders =
getSuppliers (Supplier).
4. Make sure that the context for the Supplier field is set to
POCombined.
b) Connect the target field Header and the source field Supplier:
1. Drag the target field Header and the source field Supplier to the
data flow editor by using drag and drop.
2. In the lower part of the data flow editor, choose the User-Defined
function category, then the getSuppliers function, and drag this to
the data flow editor by using drag and drop.
3. Select the SplitByValue function from the Node Functions area
and drag it to the data flow editor by using drag and drop.
4. Connect the fields in the data flow editor as follows: Header =
SplitByValue(getSuppliers(Supplier)).
5. Make sure that the context for the Supplier field is set to
POCombined.
c) Connect the target field toCompany and the source field Supplier:
1. Drag the target field toCompany and the source field Supplier to
the data-flow editor by using drag and drop.
2. Choose the getSuppliers function from the User-Defined function
category and the SplitByValue function from the Node Functions
area and drag them to the data-flow editor by using drag and drop.
3. Connect the fields in the data-flow editor as follows: toCompany
= SplitByValue(getSuppliers(Supplier)).
4. Make sure that the context for the Supplier field is set to
POCombined.
d) Connect the target field custName and the source fields Supplier and
Name:
1. Drag the target field custName and the source fields Supplier and
Name to the data-flow editor by using drag and drop.
2. Under the User-Defined function category, select the getSuppliers
function and drag it to the data-flow editor by using drag and drop.
3. Under the FL_## function category, select the global function
copyPerValue from your function library and drag it to the
data-flow editor by using drag and drop.
4. Select the SplitByValue function from the Node Functions area
and drag it to the data-flow editor by using drag and drop.
5. Connect the fields in the data-flow editor as follows: CustName =
SplitByValue(copyPerValue(getSuppliers(Supplier), Name)).
6. Make sure that the context for the Supplier field is set to
POCombined.
e) Connect the target field custAddress and the source fields Supplier and
Address:
1. Drag the target field custAddress and the source fields Supplier
and Address to the data-flow editor by using drag and drop.
2. Under the User-Defined function category, select the getSuppliers
function and drag it to the data-flow editor by using drag and drop.
3. Under the FL_## function category, select the global function
copyPerValue from your function library and drag it to the
data-flow editor by using drag and drop.
4. Select the SplitByValue function from the Node Functions area
and drag it to the data-flow editor by using drag and drop.
5. Connect the fields in the data-flow editor as follows: “custAddress
= SplitByValue(copyPerValue(getSuppliers(Supplier), Address))”.
6. Make sure that the context for the Supplier field is set to
POCombined.
f) Connect the target field items and the source field Supplier:
1. Drag the target field items and the source field Supplier to the
data-flow editor by using drag and drop.
2. Choose the User-Defined function category at the bottom of
the screen, select the assignItems function, and drag this to the
data-flow editor by using drag and drop.
3. Connect the fields in the data-flow editor as follows: items =
assignItems(Supplier).
4. Make sure that the context for the Supplier field is set to
POCombined.
g) Connect the target field productNo and the source fields Supplier and
ProductID.
Drag the target field productNo and the source fields Supplier and
ProductID to the data-flow editor by using drag and drop.
h) Specify the functions to use in the message mapping:
1. Choose the assignSuppliers function from the User-Defined
function category and the SplitByValue function from the Node
Functions area and drag them to the data-flow editor by using
drag and drop.
2. Connect the fields in the data-flow editor as follows: productNo
= SplitByValue(assignSuppliers(Supplier,
ProductID)).
3. Make sure that the context for the Supplier and ProductId fields
is set to POCombined.
i) Connect the target field quantity and the source fields Supplier and
Quantity.
Drag the target field quantity and the source fields Supplier and
Quantity to the data-flow editor by using drag and drop.
j) Specify the functions to use in the message mapping:
1. Choose the assignSuppliers function from the User-Defined
function category and the SplitByValue function from the Node
Functions area and drag them to the data-flow editor by using
drag and drop.
2. Connect the fields in the data-flow editor as follows: quantity =
SplitByValue(assignSuppliers(Supplier, Quantity)).
3. Make sure that the context for the Supplier and Quantity fields
is set to POCombined.
k) Connect the target field price and the source fields Supplier and Price.
Drag the target field price and the source fields Supplier, and Price to
the data-flow editor by using drag and drop.
l) Specify the functions to use in the message mapping:
1. Choose the assignSuppliers function from the User-Defined
function category and the SplitByValue function from the Node
Functions area and drag them to the data-flow editor by using
drag and drop.
Business Example
You have to share data between different user-defined functions and need an easy
concept for this.
Task:
Define an attribute that can be used in all user-defined functions in a message
mapping.
Increment the value with each call of one of the user-defined functions, and write
the value to the trace.
1. Copy the message mapping OrderToSortedOrder to OrderToSorte-
dOrder_ext.
2. Define an attribute of type integer named counter.
3. Extend the existing user-defined functions so that each function call increases
the counter and writes the counter value as information to the trace.
4. Test the message mapping to check the counter values in the trace.
3. Extend the existing user-defined functions so that each function call increases
the counter and writes the counter value as information to the trace.
a) Select the function getSuppliers to see the source code.
b) Increase the counter and write information to the trace.
Scroll down in the source code and add the following lines on the
bottom:
++counter;
AbstractTrace trace = container.getTrace();
trace.addInfo(counter + ". call (getSuppliers)");
c) Repeat steps a) and b) for the other user-defined functions.
Open the functions assignItems, and assignSupplier (one
after another). Enter the similar source code as above, just replace the
name of the function in bracket getSuppliers) with the respective
function name.
d) Save the message mapping.
e) Check the message mapping: choose F7.
4. Test the message mapping to check the counter values in the trace.
a) Select the Test tab.
b) Use the existing test data from the copied message mapping
OrderToSortedOrder
c) Ensure that the Trace Level is set to Info (at minimum).
d) Execute the test by choosing the Start the Transformationicon at the
bottom of the screen on the left.
The number of entries in the trace depends on your test data.
Lesson Summary
You should now be able to:
• Create user-defined functions and use them in the mapping editor
• Define and use both local and global user-defined functions
• Create function libraries and include them in a message mapping
• Change queues and contexts using standard and user-defined functions
• Work with mapping objects
• Output messages in the trace log
Unit Summary
You should now be able to:
• Create a message mapping that makes use of contexts
• Set and delete the message-mapping context
• Use advanced options to help debug the message-mapping process
• Create user-defined functions and use them in the mapping editor
• Define and use both local and global user-defined functions
• Create function libraries and include them in a message mapping
• Change queues and contexts using standard and user-defined functions
• Work with mapping objects
• Output messages in the trace log
Unit Overview
Unit Objectives
After completing this unit, you will be able to:
• Define parameters for a mapping program
• Assign parameters to a mapping program at configuration time
• Use the term value mapping and therefore make use of advanced
message-mapping options
• Map multiple source and target messages
• Describe the procedure to use a multi-mapping in an interface determination
• Create mapping templates
• Use mapping templates in message mappings
Unit Contents
Lesson: Using Parameters in Mapping Programs ..........................136
Exercise 11: Create and Use Parameters in a Message Mapping...141
Lesson: Working with Value Mapping functions ............................147
Exercise 12: Use Value Mapping in a message mapping.............157
Exercise 13: Use RFC Lookup function .................................165
Lesson: Mapping Multiple Messages ........................................173
Lesson: Creating a Message-Mapping Template...........................178
Exercise 14: Create and Use a Mapping Template ....................181
Lesson Overview
This lesson explains how to assign parameters to mapping programs at
configuration time so that you can enable more applications to be used in a
mapping program.
Lesson Objectives
After completing this lesson, you will be able to:
• Define parameters for a mapping program
• Assign parameters to a mapping program at configuration time
Business Example
You have to define a graphical RFC lookup in a message mapping. So you need
to know how to define parameters in a message mapping, bind the message
mapping parameters to the operation mapping parameters, and set up the relevant
communication channel in the interface determination.
Message-Mapping Parameters
You can use parameters in mapping programs (for example, message mappings
and operation mappings). Using parameters in mapping programs means that you
do not have to specify values to be used in the mapping until configuration time.
Using parameters in a mapping program also improves reusability by enabling
the mapping program to be used in different operation mappings with different
parameter values.
In the mapping program, you define an interface that you can use to copy values to
(and query values from) the functions of a mapping program. The values may be
payload information transferred to the containers of an integration process. You
can use parameters to transfer the following values:
• Simple parameter values:
Simple values such as a separator for a concatenation function
• Dynamic parameter values:
Adapters for lookup functions to a mapping program.
After you have defined parameters for your mapping program (MMP_1 and
MMP_2 in figure above), the mapping program is referenced in an operation
mapping. In the operation mapping, you also have to define relevant parameters
(OMP_1 and OMP_2 in the figure above) that you connect to the mapping-program
parameters using a binding. You must also set up a communication channel by
entering the operation mapping in an interface determination, for example, in
the Integration Directory. In the interface determination, you assign values to
the operation mapping parameters, which are then transferred to the mapping
program at runtime.
You can use parameters in the following mapping programs:
• Message Mappings
• Java Mapping
• XSLT Mapping
Note: Parameterized Mapping Programs cannot be used on the AEX
because it is not possible to specify parameters for the mapping program
in a Integrated Configuration, and an Interface Determination cannot
be used on AEX.
The parameters are defined on the Signature tab page of the message mapping.
Here, you name your parameters, specify whether they are simple type parameters
or adapters, and type the parameters. Once you have defined your parameters,
you can use them in your target-field mappings in the mapping editor. In the
example, the parameter MMP_Delimiter specifies the separator for the standard
function concat.
At the end of the parameter-definition process, you have to enter values for the
mapping parameters, for example, in an interface determination in the Integration
Directory in which the operation mapping is used.
Hint: If the parameters are not displayed in the lower screen area of
the interface determination for a parameterized operation mapping,
double-click the name of the operation mapping. The parameters are
then displayed.
Business Example
You want to use an existing message mapping in a different context. However, this
context requires different values to be set for certain constants. For this reason,
you decide to use parameters in the message mapping so that you can set the
relevant constants in the Integration Directory according to the context.
Task:
You need to define a parameter for the existing message mapping MM_Cus-
tomerNameMerge in your namespace http://educationsap.com/pi/mapping## to
control which separator is set between the first and last names in the standard
function concat.
1. Open your message mapping.
In Enterprise Services Repository, navigate to your namespace
http://educationsap.com/pi/mapping## in software component version
SC_BIT_MAP, 1.0. Open your message mapping MM_CustomerNameMerge.
2. Create a message-mapping parameter.
Define an import parameter entitled MMP_Delimiter of type string. The
parameter should be of a simple type.
3. Define the operation-mapping parameter.
Display the operation mapping OM_CustomerInfoMap and create an import
parameter entitled OMP_Delimiter of type string. The parameter should
be of a simple type. Then bind the message mapping parameter to the
operation mapping parameter you just created.
4. Activate the interface-determination object.
Switch to the Integration Directory and choose your interface determination
object BC_CI_Requestor_## | CustomerInformation_Request | |Training.
Leave the parameter of the operation mapping OMP_Delimiter blank.
Activate your interface determination object.
5. Start the HTTP client and send a suitable request.
Lesson Summary
You should now be able to:
• Define parameters for a mapping program
• Assign parameters to a mapping program at configuration time
Lesson Overview
This lesson introduces the standard functions for value mapping.
Lesson Objectives
After completing this lesson, you will be able to:
• Use the term value mapping and therefore make use of advanced
message-mapping options
Business Example
You are responsible for the development of mappings in SAP NetWeaver Process
Integration and require an overview of the advanced message-mapping options
that value mappings provide.
FixValues
Value-mapping tables are maintained in the ES Repository
Value mapping
Value-mapping tables are maintained in the Integration Directory
Mapping lookups
Value-mapping tables are maintained in a back-end system
The standard function FixValues contains fixed value pairs in Enterprise Services
Repository, while the standard function Value mapping references value pairs
from the configuration. The mapping lookup accesses another system to request
the required values for the value mapping. This is explained in more detail in the
remainder of the lesson.
In the example, the source field CUSTTYPE is mapped to the target field
CUSTTYPE. The default value for the target field is “business”. However, if
the source field contains the values “B”, then the target field is given the value
“business_XX”. In a similar way, a source value “P” will be mapped to target
value “private_XX” .
Advantages and disadvantages of the standard function FixValues:
+ Easy to use
+ Possible to changes entries manually
+ Good runtime performance
- No mass upload of values
- Configuration values are in design
- Values only used in respective message mapping
The actual values are referenced with the key fields Agency and Scheme. These
key fields must be reused in the configuration.
Figure 46: Value Mapping Using the Standard Function Value Mapping
You can enter any strings for Agency and Scheme for the sender and receiver. It is
also possible to save a placeholder for the Agency field for the runtime constant
SenderParty or SenderService (and likewise for the receiver), which is replaced by
the current value during execution. The standard function Value mapping can be
used in different message mappings with the same key fields, thus referencing the
same “mapping table”.
Hint: If the mapping of the standard function Value mapping was not
executed, the message trace of the converted message contains the
following entry: Key mapping from ... has not been
performed. Check the key fields Agency and Scheme.
Mapping Lookups
Mapping lookups access values (tables) in a back-end system during mapping
runtime. The lookup can be executed using the standard functions RFC Lookup or
JDBC Lookup (see below), or using the lookup API from java coding.
The lookup API provides methods for generic access to application systems using
the RFC, JDBC, and SOAP adapter. There is also a special API for the JDBC
adapter that simplifies access.
The Java program transfers a payload stream to the API, which the Adapter
Engine uses to send synchronously to the target system (but not a complete PI
message with message header). To deliver to the target system, a communication
channel must have been set up in the Integration Directory. The response to this
synchronous request is received as a stream by the Java program and must be
parsed. For more information about these APIs, see the SAP Developer Network
at https://www.sdn.sap.com/irj/sdn/javadocs (you will need an SDN user).
If the configuration is complete and runtime is active, you can test lookups as part
of a mapping program by using the test environment of an operation mapping.
The mapping editor includes standard functions RFC Lookup and JDBC Lookup
that you can use to graphically define a mapping lookup using either the RFC
adapter or the JDBC adapter.
RFC Lookup takes into account the request, response, and fault parts of an
imported RFC-Signature. To be able to model the lookup graphically, the structure
of the RFC interface must be known. To use this structure in the mapping editor,
you have to import the RFC-Signature into Enterprise Services Repository. In the
figure below, an RFC lookup is used in a target-field mapping to obtain additional
information about the number of available seats on a flight from an SAP system
at runtime. Function module Z_BIT_MAP_GET_FREE_SEATS is used for this
purpose. This uses the input parameters (aircraft type and number of occupied
seats) to return the number of available seats.
Business Example
Your company uses different values to represent customer types. You want a
conversion to take place in the PI mapping you have created. To do this, you use
the standard function Value Mapping.
Hint: To avoid conflicts while editing the value mapping groups, the
schema were set group-specific so that every participant can work
on group specific objects.
Hint: To avoid conflicts while editing the value mapping groups, the
schema were set group-specific so that every participant can work
on group specific objects.
Value-Mapping-Group VMG_business_customer_##
Agency Scheme Value
BC_CI_Re- CustType_## business_##
questor_##
Training S_CUSTTYPE_## B
Hint: For the Agency, you may use the drop-down menu to
select Business System and then select the system from the list
of available systems.
Value-Mapping-Group VMG_private_customer_##
Agency Scheme Value
BC_CI_Re- CustType_## private_##
questor_##
Training S_CUSTTYPE_## P
Hint: Since the values for the Schema are the same as for the
first value mapping group, you may now use the input help for
Scheme for the values to be listed .
Business Example
In a message mapping, you want to use a value-mapping-table located in an
ABAP back-end system.
5. Set the name for the communication channel to Training_RFC_In for the in-
terface determination BC_CI_Requestor_## | CustomerInformation_Request
| | Training.
6. Save and activate the interface determination BC_CI_Requestor_## |
CustomerInformation_Request | | Training.
3. Add the standard function RFC Lookup to the target field mapping of
CUSTTYPE.
a) Open the Definition tab.
b) Open the field mapping for the target field CUSTTYPE.
Double-click the field CUSTTYPE from the target structure
MtCustomerInfo.
c) Add the standard function RFC Lookup
Select the functions category Conversions and drag the function RFC
Lookup to the flow editor.
5. Set the name for the communication channel to Training_RFC_In for the in-
terface determination BC_CI_Requestor_## | CustomerInformation_Request
| | Training.
a) Open the Integration Directory.
b) Open the interface determination BC_CI_Requestor_## |
CustomerInformation_Request | | Training.
c) Switch to edit mode.
d) Click the line with the operation mapping OM_CustomerInfoMap
for the parameters to be displayed.
e) Below, click the question mark below Value and open the input
help. Select the communication channel Training_RFC_In for
Communication Component Training. Click Apply to close the
Communication Channel selection window.
6. Save and activate the interface determination BC_CI_Requestor_## |
CustomerInformation_Request | | Training.
a) Save the interface determination.
b) Activate the interface determination using the menu Interface
Determination / Activate.
Lesson Summary
You should now be able to:
• Use the term value mapping and therefore make use of advanced
message-mapping options
Lesson Overview
This lesson explains the concept of multi-mapping by showing how to map
multiple source and target messages. The lesson also shows how to reference
multi-mapping for the purposes of a receiver determination or an interface
determination.
Lesson Objectives
After completing this lesson, you will be able to:
• Map multiple source and target messages
• Describe the procedure to use a multi-mapping in an interface determination
Business Example
You are responsible for the development of mappings in SAP NetWeaver Process
Integration and need to understand how to use the advanced message mapping
options that multi-mapping provide.
Multi-Mapping Configurations
Traditionally, mapping programs were used to create 1:1 mappings between
source and target messages. However, there are scenarios in which it is necessary
to process multiple messages. For example, an integration process (ccBPM) might
be designed to wait for multiple messages to arrive before processing all messages
and sending them to a receiver.
The actual multi-mapping is created in the mapping editor.
Hint: Provided the required schemas are available, you can also create
a multi-mapping in Java mappings, for example, by exporting the data
from Enterprise Services Repository.
• n:1 mapping:
Multiple messages are combined into one message (for example, multiple
purchase orders are combined to make just single purchase order).
• 1:n mapping:
One large message is split into multiple individual messages (for example,
one large purchase order is divided into the individual purchase order items).
• n:m mapping:
n source messages are transformed into m target messages.
The mapping program creates the values of the target message types Order and
OrderInfo from the values of the message types OrderHeader and OrderItem. In
this case, only an n:2 multi-mapping is executed. On both sides, the message types
are under the root element Messages (the name cannot be changed) and under the
elements Message1 and Message2. The sequence is specified by the configuration
in the message editor.
The figure Configuration of an n:m Multi-Mapping in the Mapping Editor
shows the procedure in the mapping editor.
Depending on the sequence of the inserted message types in the input field on the
Signature tab page, the messages will also be made available in the structure
overview on the Definition tab page. In the next step, you define the mapping
program in the data flow editor.
The following restriction applies for the source and target messages that you
reference from a message mapping: The source and target messages can be in a
different software component version (SWCV) to the message mapping, but they
must both originate from the same SWCV (and, if applicable, underlying SWCV).
For example, if the mapping program contains sub structures (or fields) with an
occurrence of 0 ... unbounded and one message is to be created for each instance,
you can use a multi-mapping to create individual messages. These individual
messages are initially bundled into one bulk message. The bulk message is then
transferred to the Adapter Engine where it is split up into the individual messages
again as illustrated in the following figure.
Both the bulk message and the individual messages have a message header with
a receiver interface that is defined by the mapping, and which may be different
for each individual message.
Hint: For a mapping-based message split, the messages must all be sent
by using the same Adapter Engine. Attachments from the original message
are not transferred to the messages that are created in the message split.
Lesson Summary
You should now be able to:
• Map multiple source and target messages
• Describe the procedure to use a multi-mapping in an interface determination
Lesson Overview
This lesson shows you how to create a message-mapping template and explains
the message-mapping options that a mapping template provides.
Lesson Objectives
After completing this lesson, you will be able to:
• Create mapping templates
• Use mapping templates in message mappings
Business Example
You have repetitive mapping tasks that you want to perform with the aid of a
single mapping, which you can use as required for multiple substructures.
• Data types
• Complex types extracted from IDoc structures and RFC function headers
• Complex types in external definitions
Hint: You can also use a mapping template for an individual field provided
that the field references a simple data type (and not a XSD data type).
The data types referenced by mapping templates can exist in any software
component versions.
The following figure illustrates how you can define a mapping template and how
you can use existing mapping templates.
In a message mapping, you can display which mapping templates have already
been referenced. Furthermore, if structures are selected in the source and target
structures, you can also display or create appropriate mapping templates.
If a mapping template is modified after it has been referenced, the change is not
automatically transferred to the message mapping in which the mapping template
is referenced.
Business Example
A specific mapping task requires you to use mapping templates in a message
mapping.
Task:
You want to use a mapping template in a message mapping that maps the message
types Contact and Customer. The message type Contact comprises the data
types Name and Address; the message type Customer comprises the data types
CustName and CustomerAddress.
1. Start Enterprise Services Repository.
Navigate to your namespace http://educationsap.com/pi/mapping## in
software component version SC_BIT_MAP, 1.0.
2. Create a message-mapping template.
In your http://educationsap.com/pi/mapping## namespace, create a mapping
template with the name NameToCustName. Use the data types Name and
CustName (both from SWCV SC_BIT_MAP, 1.0 under Basis Objects in
namespace urn:educationsap.com:bit:mapping). Assign the Gender target
field to the Title source field. The source fields Firstname and Surname are to
be linked with a blank and transferred to the target field Name.
Note: To select the source or target structure, select the relevant data
type from the navigation tree and link it to the appropriate fields for
the structures by using drag and drop.
Note: To select the source or target structure, select the relevant data
type from the navigation tree and link it to the appropriate fields for
the structures by using drag and drop.
10. Test the mapping by using the mapping editor test function.
a) Choose the Test tab page and create a new XML instance by choosing
Generate Instance.
b) Expand the nodes in the XML instance and populate the fields with
test values.
c) Execute the mapping by choosing Execute Mapping.
Lesson Summary
You should now be able to:
• Create mapping templates
• Use mapping templates in message mappings
Unit Summary
You should now be able to:
• Define parameters for a mapping program
• Assign parameters to a mapping program at configuration time
• Use the term value mapping and therefore make use of advanced
message-mapping options
• Map multiple source and target messages
• Describe the procedure to use a multi-mapping in an interface determination
• Create mapping templates
• Use mapping templates in message mappings
Unit Overview
This course focuses on graphical message mapping. However, it is also relevant to
look at other mapping types that can be combined with message mapping.
Unit Objectives
After completing this unit, you will be able to:
• import and use XSLT mappings
• explain the main steps to create a Java mapping program
• Import and use a Java mapping in an Operation Mapping
Unit Contents
Lesson: Importing and Using XSLT Mapping ...............................190
Exercise 15: Import and Use XSLT Mappings ..........................195
Lesson: Creating a Java Mapping ............................................200
Exercise 16: Create and Use a Java Mapping .........................205
Lesson Overview
This lesson looks at the way XSLT mappings work and how you can use them.
Lesson Objectives
After completing this lesson, you will be able to:
• import and use XSLT mappings
Business Example
You are responsible for the development of mappings in SAP PI and need to
know how to integrate XSLT mappings.
You have the option of using XPath statements in XSLT mappings. Like XSLT,
XPath is an XML specification. You can use XPath to address any elements in an
XML document. XSLT uses XPath to select substructures in XML documents.
The required transformations are executed for these substructures by using
templates defined in XSLT.
You can use the XSLT tags <xsl:include> and <xsl:import> to read
templates for substructures. In this way, you can break down a large XSLT
mapping program into smaller packages, and save them in one or more archives.
Furthermore, you can reuse XSLT templates for data types because they can be
called in other XSLT mappings.
$last)/> executes the call. Javamap selects the namespace defined above, and
merge($first, $last) calls the method merge. The result of
the method is shown in the resulting file.
Runtime Constants
It is possible to use runtime constants that you use to read data that is not known
until runtime.
...
<xsl:param name="SenderService" />
...
<xsl:value-of select="$SenderService"/>
Trace Messages
To define warnings (that either cause processing to terminate or allow it to
continue), use the XSLT statement <xsl:message>.
// Example:
<xsl:message terminate="no">
This is a warning!
</xsl:message>
The XSLT statements in the following example test the current source value of the
test tag and set a corresponding target value. If neither of the two expected values
are found, the result is displayed as a warning, for example: <xsl:choose>
<xsl:when test="test()=0">Mr.</xsl:when>
<xsl:when test="test()=1">Mrs.</xsl:when>
<xsl:otherwise> Mr. or Mrs.
<xsl:message terminate="no">
Gender had neither 0 nor 1!
"Mr. or Mrs." was set as title.
</xsl:message>
</xsl:otherwise>
</xsl:choose<
This particular exception does not cause the mapping to terminate because the
parameter terminate was set to no.
Alternatively, you can define that a Java method is called in XSLT that writes
the messages to the trace log.
Note: Before PI 7.1, XSLT programs were executed using the SAP XML
Toolkit. This became obsolete when version 5 of the Java Development
Kit (JDK) was introduced with PI 7.1.
Compared to the SAP XML Toolkit, the usage of the JDK has the following
advantages:
• XSLT programs are executed more quickly
• Better error handling
• Supports a wider range of functions than the SAP XML Toolkit
You will still be able to use the SAP XML Toolkit with PI 7.3. We recommend
to test existing XSLT programs and adjust them if necessary. So deselect the
option Use SAP XML Toolkit (which refers to the XSLT mapping program) in
the operation mapping.
Business Example
You want to know the procedure for using an external XSLT mapping in an
operation mapping.
Task 1:
Import the XSLT mapping NameMerge.xsl for the mapping between the data types
MtCustomerName and MtPerson. Check that the mapping does not contain any
errors and use it in the operation mapping OM_CustomerInfoMap.
1. Import the NameMergeXSL.zip archive in Enterprise Services Repository
in software component version SC_BIT_MAP 1.0 in your namespace
http://educationsap.com/pi/mapping##.
2. Check that the XSLT mapping and adapt your group number.
3. Use the XSLT mapping in your operation mapping.
Make the necessary changes to your operation mapping
OM_CustomerInfoMap so that it uses your imported XSLT mapping
NameMerge.xsl.
xmlns:ns0="urn:educationsap.com:bit:mapping">
<xsl:output method="xml" version="1.0" indent="yes"/>
</xsl:stylesheet>
...
<xsl:template match="ns:MtCustomerName">
<xsl:call-template name="NameMerge"/>
</xsl:template>
</xsl:stylesheet>
...
<xsl:template name="NameMerge">
<ns0:MtName>
<xsl:value-of select="Name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="Surname"/>
</ns0:MtName>
</xsl:template>
</xsl:stylesheet>
Lesson Summary
You should now be able to:
• import and use XSLT mappings
Lesson Overview
This lesson looks at the way Java mappings have to be developed, and how you
can use them.
Lesson Objectives
After completing this lesson, you will be able to:
• explain the main steps to create a Java mapping program
• Import and use a Java mapping in an Operation Mapping
Business Example
You are responsible for the development of mappings in SAP PI and require an
overview of the options that are provided by Java mappings.
Note: JAXP supports the Document Object Model (DOM) and the Simple
API for XML (SAX). The implementation is not in the focus of this lesson.
The required libraries are shipped with the installation of the AS Java in the
archive com.sap.xpi.ib.mapping.lib.jar (to be found in: usr/sap/<SID>/DVEB-
MGS<nr>/J2EE/cluster/bin/ext/com.sap.xi.mapping.tool.lib/lib).
The Java mapping API has been revised and this new API has to be used
for new Java mapping programs with PI 7.3. It is documented in SDN:
https://www.sdn.sap.com/irj/sdn/javadocs (SDN user required)
The following source code shows the main parts.
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.api.InputHeader;
// ... additional imports
Hint: You can export the required XML schemas from Enterprise
Services Repository.
Accessing Parameters
You can access parameters specified in the Operation Mapping using the method
getInputParameters() of the in parameter, see coding above.
In this example, it is assumed that a parameter named PARAM_1 is specified in
the Operation Mapping.
You define the Java mapping parameters for a Java mapping program when you
create the binding in the operation mapping, and at the same time connect them to
operation mapping parameters. When you access the Java mapping parameters
in the Java mapping program, the mapping runtime checks whether you have
defined the parameters in the operation mapping. If they were not defined, an
exception is raised.
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
...
You can access or set adapter specific message attributes with the
getDynamicConfiguration() method, see coding above.
DynamicConfiguration is a map containing adapter specific message attributes,
associating DynamicConfigurationKeys with string values.
Trace Messages
You can create entries in the mapping trace using the getTrace method of the
class AbstractTransformation:
Additional notes
• Not stateful: Java mappings must not be stateful, that is, nothing can be
written to the database. If a PI message is resent because of an error, this
can lead to database inconsistencies.
• Value Mapping: An API is available for executing value mappings. The
relevant classes are part of the package com.sap.aii.mapping.key.*.
• Lookup API: you can use an API for a Value Mapping Lookup. You
have to import a parameter of type Adapter into your Java mapping
(in.getInputParameters().getChannel("CommunicationChannelName");
).
Business Example
You want to create a Java mapping program to use it in an operation mapping.
Lesson Summary
You should now be able to:
• explain the main steps to create a Java mapping program
• Import and use a Java mapping in an Operation Mapping
Unit Summary
You should now be able to:
• import and use XSLT mappings
• explain the main steps to create a Java mapping program
• Import and use a Java mapping in an Operation Mapping
Course Summary
You should now be able to: