Logical unit of work (LUW) in SAP:
The objective of this document is aimed at explaining the
concept of logical unit of work in SAP. I assume that this
will be a good read for my fellow readers.
Why logical units of work?
The main purpose of the logical unit of work is to ensure
data consistency in the R/3 systems. Let us consider that
there is a complex R/3 transaction that involves a series
of dialog steps; during the execution of one such dialog
step at the middle of the transaction the data involved will
lack completeness & will therefore be inconsistent. When
talking about of logical unit of work we must note the
following points initially.
1. Database LUW also known as DB LUW, each dialog step
has its own DB LUW that is used to ensure data
consistency.
2. SAP LUW consists of several dialog steps and all the
changes to database are written in a single DB LUW. We
must note that the database changes are always written
in the final database LUW.
3. Therefore to summarize a complex R/3 transaction may
span across several dialog steps each having its own DB
LUW, however all the changes are written to the database
in the final DB LUW of the SAP LUW after a commit work is
executed by the system or rolled back with no changes
written to the database due to errors.
What is a database LUW?
A database LUW is work unit consisting of database
operations (INSERT, UPDATE, MODIFY & DELETE) that it
used to make the database changes. The final database
LUW of a SAP LUW is used to make the changes to the
database, the changes to the database is not made until
after the database commit. The database LUW is executed
in a special kind of work process called the update work
process.
What is a SAP LUW?
A SAP LUW is a logical unit work that spans over several
dialog steps. Let us consider a complex R/3 transaction of
n screens; where each screen has its own DB LUW
involving database operations and are logically related to
each other. It is important that the changes to the
database for this complex transaction must be made all at
once or it must be rolled back all for the data consistency;
that is where the SAP LUW becomes critical in
maintaining a logical relationship between several DB
LUWs (dialog phases) & making all the changes to the
database in the final DB LUW. SAP LUW uses the bundling
technique to achieve the same. There are several
possibilities of bundling technique and one of them is
bundling the database changes using a function module
call in the UPDATE TASK.
Bundling in SAP LUW:
A CALL FUNCTIONIN UPDATE TASK is one of the
bundling techniques to achieve all the database changes
in the last DB LUW of the SAP LUW. The open SQL
statements for database changes are placed in the
function module instead of placing them in the code, using
the addition UPDATE TASK ensures that the function
module is not executed until COMMIT WORK is found in
the program. At COMMIT WORK the function module calls
with UPDATE TASK are executed in a special work
process called update work process and the changes to
the database is executed in the final DB LUW of the SAP
LUW.
R/3 transactions using update function modules.
Let us consider there is one R/3 transaction calling
another R/3 transaction and as well as calling some
update function module. There is some typical behavior
that can be noted for this particular scenario.
(a) The called transaction begins in a new SAP LUW in
comparison to the calling transaction. It implies that there
are two different SAP LUWs now.
(b) A new update key is generated for the new SAP LUW
that is used to identify all the update function modules.
(c) If the called R/3 transaction does not have a COMMIT
WORK then the update function modules will not be
executed i.e. both the calling transaction & the called
transaction must have their own COMMIT WORK.
(d) The update function modules are called only after the
system has executed a COMMIT WORK.
(e) Let us consider there is an importing parameter IM_X for the update function module; now the same
function module is called at several places in the program
like shown below
DATA: gv_x TYPE i.
gv_x = 1.
CALL FUNCTION UPD_FUNC IN UPDATE TASK
EXPORTING
IM_X = gv_x.
gv_x = 2.
CALL FUNCTION UPD_FUNC IN UPDATE TASK
EXPORTING
IM_X = gv_x.
gv_x = 3.
COMMIT WORK.
What will be the value of gv_x at the COMMIT WORK?
No, the value of gv_x will not be 3; when commit is
executed by the system the value of gv_x that will be
passed is dependent at the point of function call therefore
during the first call the value of gv_x will be 1 & during the
second call the value of gv_x will be 2.
Database Logical Unit of Work (LUW)
From the point of view of database programming, a
database LUW is an inseparable sequence of database
operations that ends with a database commit. The
database LUW is either fully executed by the database
system or not at all. Once a database LUW has been
successfully executed, the database will be in a
consistent state. If an error occurs within a database
LUW, all of the database changes since the beginning of
the database LUW are reversed. This leaves the database
in the state it was in before the transaction started.
The database changes that occur within a database LUW
are not actually written to the database until after the
database commit. Until this happens, you can use a
database rollback to reverse the changes. In the SAP
System, database commits and rollbacks can be triggered
either implicitly or using explicit commands.
Implicit Database Commits
A work process can only execute a single database LUW.
The consequence of this is that a work process must
always end a database LUW when it finishes its work for a
user or an external call. Work processes trigger an implicit
database commit in the following situations:
When a dialog step is completed
Control changes from the work process back to the SAP
GUI.
When a function module is called in another work
process (RFC).
Control passes to the other work process.
When the called function module (RFC) in the other
work process ends.
Control returns to the calling work process.
When a WAIT statement interrupts the work process.
Control passes to another work process.
Error dialogs (information, warning, or error messages)
in dialog steps.
Control passes from the work process to the SAP GUI.
Explicit Database Commits
There are two ways to trigger an explicit database commit
in your application programs:
Call the function module DB_COMMIT
The sole task of this function module is to start a
database commit.
Use the ABAP statement COMMIT WORK
This statement starts a database commit, but also
performs other tasks (refer to the keyword
documentation for COMMIT WORK).
Implicit Database Rollbacks
The following cases lead to an implicit database rollback:
Runtime error in an application program
This occurs whenever an application program has to
terminate because of an unforeseen situation (for
example, trying to divide by zero).
Termination message
Termination messages are generated using the ABAP
statement MESSAGE with the message type A or X. In
certain cases (updates), they are also generated with
message types I, W, and E. These messages end the
current application program.
Explicit Database Rollbacks
You can trigger a database rollback explicitly using the
ABAP statement ROLLBACK WORK. This statement
starts a database rollback, but also performs other
tasks (refer to the keyword documentation
for ROLLBACK WORK).
From the above, we can draw up the following list of
points at which database LUWs begin and end.
A Database LUW Begins
Each time a dialog step starts (when the dialog step is
sent to the work process).
Whenever the previous database LUW ends in a
database commit.
Whenever the previous database LUW ends in a
database rollback.
A Database LUW Ends
Each time a database commit occurs. This writes all of
the changes to the database.
Each time a database rollback occurs. This reverses all
of the changes made during the LUW.
Database LUWs and Database Locks
As well as the database changes made within it, a
database LUW also consists of database locks. The
database system uses locks to ensure that two or more
users cannot change the same data simultaneously, since
this could lead to inconsistent data being written to the
database. A database lock can only be active for the
duration of a database LUW. They are automatically
released when the database LUW ends. In order to
program SAP LUWs, we need a lock mechanism within the
R/3 System that allows us to create locks with a longer
lifetime (refer to The SAP Locking Concept).
ABAP PROXY : Developments on Application System &
Integration System
USE of This Blog :
Sometimes, we are facing problem when developing ABAP
proxies.
As SAP-PI consultant who does not know ABAP, cant
work on ABAP Coding and Proxy Generation part. An ABAP
Consultant who does not know SAP-PI, cant work on SAPPI design part.
At that time understanding of both side developments is
required, this Blog explaining Development work on SAPPI System (Integration System) & SAP-ECC System
(Application System).
This blog will be helpful for Consultant who knows only
SAP-PI OR SAP-ABAP. Consultant can identify the scope of
work on SAP-PI OR SAP-ABAP part with the help of this
blog.
INTRODUCTION : ABAP proxies are used when ABAP
applications needs to send and receive data.
Communication : Transport Protocol : HTTP
RFC Destinations
ABAP System)
: Type H (HTTP Connections to
Development on SAP-PI
Enterprises Service Repository :
Create Data Type
Create Message Type
Create Service Interface
Development on SAP-ECC
In proxies, it will generate 3 objects at Application System
:
ABAP Class.
Structure for Message Type.
Structure of Data Type.
Inbound Proxy:
T-code : SPROXY
Open the node for your Service (Inbound / Outbound) &
Right click
Click on CREATE PROXY.
This Development is for Inbound Proxy.
Give Package Name & Prifix : Click on Continue .
After Completing this creation process, this screen will
be there.
SAVE & Activate. Double click on Provider Class, this
screen will be there :
Double click on Method.
This screen will be there, you have to write your code
here in this method.
Header Structure and Item Structures will be in INPUT
Parameter :
Write code as below :
(Inbound Proxy)
Post the data in Table
Post the data using Function Module
Inbound Proxy is Complete.
Outbound Proxy:
T-code : SPROXY
Open the node for your Service (Inbound / Outbound) &
Right click
Click on CREATE PROXY.
This Development is for Outbound Proxy.
In this Case, choose Outbound Service Interface for
Creation of Proxy.
After Completing this creation process, this screen will
be there.
For Outbound Proxy, an executable code in ABAP will be
written to call that proxy.
In this Example, we are writing that code in Executable
program in SE38.
First Pick data from Table.
Fill Proxy Structure & send to Integration System.
For this example, Data Declaration part will be as below
:
For this example, code for filling & Sending Proxy data
Subroutine will be as below :
Now, Inbound & Outbound Proxy Development
is complete.
SECOND BLOG
ABAP Proxy is one of the easiest way to communicate
with SAP/Non-SAP application for an ABAPer. As it gives
control directly to you in the form of classes and
methods. Proxies will allow you to expose application
functionality via web interfaces.
ABAP Proxy can be used to provide SAP data to outside
world or to consume outside data into SAP. Proxies can be
written in any SAP application system viz. ECC, SRM, CRM
etc. You can use transaction SE80 or SPROXY to generate
proxies. Mostly used for communication with PI system or
for web service consumption.
Type and direction of ABAP Proxy w.r.t. ECC
A proxy will have the same attributes as that of service
interface Inbound/Outbound
and Synchronous/Asynchronous.
Asynchronous This is a one way transfer, you send
the data to or from ECC.
Synchronous There is a request and a response
message, you send the data and wait for response.
Outbound/Client Data being sent out of SAP ECC.
Inbound/Server Data coming into SAP ECC.
Example 1 Outbound synchronous means that SAP has
sent the data to PI and is waiting for response to complete
the process.
Example 2 Inbound Asynchronous means data has come
to SAP system from PI and would be processed in SAP. No
need to send any response.
Prerequisites
Service Interface (Message Interface) has been created
in Enterprise Service Repository in PI system
ABAP Proxy is configured in the corresponding SAP
system. How to configure ABAP Proxy?
Business system for the corresponding SAP system has
been created in SLD in PI System. You can check with
PI folks to confirm the same.
Steps to generate ABAP Proxy
Generating a proxy is same for client/server. Follow
the below steps:
Select the namespace and find the service interface.
Example below:
Namespace
urn:companyname.com:proxy_to_file_nested
Interface RecordsetOut
Enter the package, prefix and transport number and
follow the wizard.
Save and activate the proxy created from toolbar.
The Status will changed to green as shown below:
Client / Outbound ABAP Proxy
You will create a Client / Outbound Proxy
When you are required to send data from SAP
system to PI system.
Double click on Class name generated in above step.
Find the method name it would be of same name
as that of PI interface
Data can be sent from a report program / RFC / BAPI
/ BADI or any executable object which can call a
method like below:
CALL METHOD detail>RECORDSET_OUT Outbound PI interface
EXPORTING
output = req.
commit work.
* req is the internal table, which should be filled
to populate the output table.
Simply execute the report / RFC to send the data out
of SAP system to PI system.
Server / Inbound ABAP Proxy
You need to implement the method of proxy class
When you are required to receive the data from PI
system to SAP system.
Dobule click on Class
Data would be received by implementing the method
Write the code, exception handling inside this
method.
When the data will be triggered from SAP PI, it will
automatically received by SAP system.
ABAP Proxy Communication Scenario (Client Proxy)
This document is focused to give a better understanding on
ABAP client proxies.
From WAS 6.20 onwards, proxy generation feature enables
application systems to communicate with XI using proxies.
Proxy
objects
implement
message
interfaces
from
Integration Repository. Proxy generation converts nonlanguage-specific interface descriptions in WSDL into
executable interfaces in the application system. Proxies
separate Business Application logic from the integration
logic of the Exchange infrastructure.
There are 2 types of proxies available.
1. Java Proxies
2. ABAP Proxies.
1. Java Proxies: - Java proxies are used when JAVA
applications needs to send or receive messages with other
applications. JAVA proxies are generated from the WSDL
description of the interface in the Integration Repository,
and the result is a .jar file containing generated java
classes corresponding to the integration objects.
2. ABAP Proxies: - ABAP proxies are used when ABAP
applications needs to send or receive messages. ABAP
proxies are generated on the Application server with
transaction SPROXY, based on the WSDL representation of
the message interface.
The type of the message interface determines what type of
proxy is generated. The counterparts to outbound message
interface in application systems are client proxies, these
are called to send a message to inbound interface. And the
counterparts of inbound message interface in application
systems are server proxies.
Advantages of ABAP Proxies.
1. Proxy communication always by passes the Adapter
Engine and will directly interact with the application
system and Integration engine. So it will give us better
performance.
2. Proxies communicate with the XI server by means of
native SOAP calls over HTTP.
3. Easy to handle messages with ABAP programming.
4. Proxy is good for large volumes of data. we can catch
and persist the errors ( both system & application fault
) which was generated by Proxy setting
The rest of the document gives you pre-requisites and steps
that are necessary for generating and executing ABAP
client proxies.
Also Read ABAP Proxy Communication (Server Proxy)
Pre-requisites
1. The business systems should be based on SAP Web AS
6.20 and SAP Web AS 6.20 kernel patch level above
1253
2. You have installed the XI Add-On in each of these
business systems as described in the Installation
Guide SAP Exchange Infrastructure 3.0
3. The business systems and your central Integration
Server are maintained in the System Landscape
Directory (SLD).
Steps required for developing ABAP Proxies
Establish the connection between WAS and
Integration Builder, this allows the application system
to retrieve WSDL description of the interface as the
basis of proxy generation.
Create a source data type and a target data type.
Create Message types for the source and target data
types.
Create Message Interfaces includes Inbound Message
interface and Outbound Message interface.
Create message mapping between the source and
target message types.
Create Interface mapping.
Create ABAP proxies using the transaction SPROXY in
the application system.
Create Collaboration agreements and Collaboration
profiles in Integration directory.
Write a program in the application system for creating
the client proxy request.
Scenario demonstrating ABAP Client Proxies.
Take a business scenario where in business (Source
System) sends an Employee details to their Payroll
system for calculating the monthly salaries of their
employees. But here the source business is running on
SAP R/3 and corresponding Payroll system is not on SAP,
hence
the
different.
interpretation
Because
of
data/communication
source system
sends
is
employee
information through proxy communication and the target
Payroll system is not aware of these proxy call, so in
order to provide a communication between these two we
need some interface mechanism which accepts proxy
request and converts it into the format understandable
by the target payroll system and vice versa.
Objects needed to be developed in IR
For this scenario we need to create the corresponding
Data types, Message types and Message interfaces for
source and target messages. Once the source Message
interface is created we can generate the interface in
source R/3 system using SPROXY transaction.
In this demo scenario, there is slight variance in source
and target messages. From the source we will get First
name and last name where as target will accommodate
only one full name and also source will send the annual
salary whereas target will have the field Monthly salary.
Hence required mapping should be done.
Save it.
Now activate all the objects that are developed in IR.
Before starting the configurations in the Integration
directory, let us complete the creation of client proxies
in source R/3 system.
Creating ABAP Proxies in Application system
Go to SPROXY transaction in R/3 system.
Here we can see all the Integration Repository objects.
Select the outbound interface for which we want to create
the proxy. Right click on the interface and select create
option.
ABAP proxy will generate the following objects.
We can observe the Structures resembling outbound data
types, message types get created in the system. As the
source structure can send multiple records of Employee,
observe
that
Table
type
of
ZTDT_EMPDET_OB_EMPLOYEE_TAB getting created. This
can be transferred to FTP.
Activate the generated proxy.
For creating ABAP client proxy request we need to call
the execute_asynchronous method of this class. This
method will take the input as of type ZTMT_EMPDET_OB.
To fill the employee details we need to create the structure
of type ZTDT_EMPDET_OB_EMPLOYEE and table of type
ZTDT_EMPDET_OB_EMPLOYEE_TAB.
After filling the internal table finally we need to move this
to
ZTMT_EMPDET_OB- MT_EMPDET_OB-EMPLOYEE
Objects that need to be developed in ID
First we need to create communication channels for
sender and receiver. Here it is not required to create
sender communication channel as we are using proxies
in the sender side for communication. We need to create
Receiver communication channel to place the file with
employee details in the FTP server.
The next step in the Integration directory is we need to
create Sender agreement, receiver agreement, interface
determination and Receiver determination. But in our
scenario it is not required to create sender agreement.
Testing the Scenario.
In order to test the scenario we need to develop an ABAP
Report to trigger a client proxy. The following report is
executed in the SE38 Editor for triggering an ABAP Proxy.
*&---------------------------------------------------------------------*
*& Report Z_SEND_EMP_DETAILS
*&
*&---------------------------------------------------------------------*
*& Published at SAPTechnical.com
*&
*&---------------------------------------------------------------------*
REPORT Z_SEND_EMP_DETAILS.
TABLES:
PA0001.
DATA:
PRXY TYPE REF TO ZTCO_MI_EMPDET_OB,
FS_EMPLOYEE TYPE ZTDT_EMPDET_OB_EMPLOYEE,
T_EMPLOYEE TYPE ZTDT_EMPDET_OB_EMPLOYEE_TAB,
FS_EMPLOYEE_MT TYPE ZTMT_EMPDET_OB.
DATA:
BEGIN OF I_PA0000 OCCURS 0,
PERNR LIKE PA0000-PERNR,
MASSN LIKE PA0000-MASSN,
END OF I_PA0000,
BEGIN OF I_PA0001 OCCURS 0,
PERNR LIKE PA0000-PERNR,
WERKS LIKE PA0001-WERKS,
PERSG LIKE PA0001-PERSG,
PERSK LIKE PA0001-PERSK,
BTRTL LIKE PA0001-BTRTL,
ABKRS LIKE PA0001-ABKRS,
KOSTL LIKE PA0001-KOSTL,
ORGEH LIKE PA0001-ORGEH,
PLANS LIKE PA0001-PLANS,
END OF I_PA0001,
BEGIN OF I_PA0002 OCCURS 0,
PERNR LIKE PA0000-PERNR,
NACHN LIKE PA0002-NACHN,
VORNA LIKE PA0002-VORNA,
GESCH LIKE PA0002-GESCH,
GBDAT LIKE PA0002-GBDAT,
END OF I_PA0002,
BEGIN OF I_PA0007 OCCURS 0,
PERNR LIKE PA0000-PERNR,
SCHKZ LIKE PA0007-SCHKZ,
ARBST LIKE PA0007-ARBST,
END OF I_PA0007,
BEGIN OF I_PA0008 OCCURS 0,
PERNR LIKE PA0000-PERNR,
TRFAR LIKE PA0008-TRFAR,
TRFGB LIKE PA0008-TRFGB,
TRFGR LIKE PA0008-TRFGR,
TRFST LIKE PA0008-TRFST,
STVOR LIKE PA0008-STVOR,
" Personnel Area
" Employee Group
" Employee Subgroup
" Personnel Subarea
" Payroll Area
" Cost Center
" Organizational Unit
" Position
" Last Name
" First Name
" Gender Key
" Date of Birth
" Work Schedule Rule
" Daily Working Hours
" Pay scale type
" Pay Scale Area
" Pay Scale Group
" Pay Scale Level
" Date of Next Increase
WAERS LIKE PA0008-WAERS,
" Currency Key
ANSAL LIKE PA0008-ANSAL,
" Annual salary
LGA01 LIKE PA0008-LGA01,
" Wage Type
BET01 LIKE PA0008-BET01,
" Wage Type Amount
for Payments
ANZ01 LIKE PA0008-ANZ01,
" Number
LGA02 LIKE PA0008-LGA02,
" Wage Type
BET02 LIKE PA0008-BET02,
" Wage Type Amount
for Payments
ANZ02 LIKE PA0008-ANZ02,
" Number
LGA03 LIKE PA0008-LGA03,
" Wage Type
BET03 LIKE PA0008-BET03,
" Wage Type Amount
for Payments
ANZ03 LIKE PA0008-ANZ03,
" Number
END OF I_PA0008,
BEGIN OF I_PA0009 OCCURS 0,
PERNR LIKE PA0000-PERNR,
ZLSCH LIKE PA0009-ZLSCH,
" Payment Method
BANKS LIKE PA0009-BANKS,
" Bank country key
BANKL LIKE PA0009-BANKL,
" Bank Keys
BANKN LIKE PA0009-BANKN,
" Bank account
number
BKONT LIKE PA0009-BKONT,
" Bank Control Key
END OF I_PA0009.
TRY.
CREATE OBJECT PRXY.
ENDTRY.
SELECT-OPTIONS:
S_PERNR FOR PA0001-PERNR.
START-OF-SELECTION.
SELECT PERNR
" Personnel number
MASSN
FROM PA0000
INTO TABLE I_PA0000
WHERE PERNR IN S_PERNR
AND ENDDA GE SY-DATUM
AND BEGDA LE SY-DATUM
AND STAT2 EQ '3'.
SELECT PERNR
" Personnel number
WERKS
" Personnel Area
PERSG
" Employee Group
PERSK
" Employee Subgroup
BTRTL
" Personnel Subarea
ABKRS
" Payroll Area
KOSTL
" Cost Center
ORGEH
" Organizational Unit
PLANS
" Position
FROM PA0001
INTO TABLE I_PA0001
WHERE PERNR IN S_PERNR
AND ENDDA GE SY-DATUM
AND BEGDA LE SY-DATUM.
SELECT PERNR
" Personnel number
NACHN
" Last Name
VORNA
" First Name
GESCH
" Gender Key
GBDAT
" Date of Birth
FROM PA0002
INTO TABLE I_PA0002
WHERE PERNR IN S_PERNR
AND ENDDA GE SY-DATUM
AND BEGDA LE SY-DATUM.
SELECT PERNR
" Personnel number
SCHKZ
" Work Schedule Rule
ARBST
" Daily Working Hours
FROM PA0007
INTO TABLE I_PA0007
WHERE PERNR IN S_PERNR
AND ENDDA GE SY-DATUM
AND BEGDA LE SY-DATUM.
SELECT PERNR
" Personnel number
TRFAR
" Pay scale type
TRFGB
" Pay Scale Area
TRFGR
" Pay Scale Group
TRFST
" Pay Scale Level
STVOR
" Date of Next Increase
WAERS
" Currency Key
ANSAL
" Annual salary
LGA01
" Wage Type
BET01
" Wage Type Amount for Payments
ANZ01
" Number
LGA02
" Wage Type
BET02
" Wage Type Amount for Payments
ANZ02
" Number
LGA03
" Wage Type
BET03
" Wage Type Amount for Payments
ANZ03
" Number
FROM PA0008
INTO TABLE I_PA0008
WHERE PERNR IN S_PERNR
AND ENDDA GE SY-DATUM
AND BEGDA LE SY-DATUM.
SELECT PERNR
" Personnel number
ZLSCH
" Payment Method
BANKS
" Bank country key
BANKL
" Bank Keys
BANKN
" Bank account number
BKONT
" Bank Control Key
FROM PA0009
INTO TABLE I_PA0009
WHERE PERNR IN S_PERNR
AND ENDDA GE SY-DATUM
AND BEGDA LE SY-DATUM.
SORT: I_PA0000 BY PERNR,
I_PA0001 BY PERNR,
I_PA0002 BY PERNR,
I_PA0007 BY PERNR,
I_PA0008 BY PERNR.
REFRESH T_EMPLOYEE.
LOOP AT I_PA0000.
CLEAR FS_EMPLOYEE.
FS_EMPLOYEE-PERSONNEL_NUMBER
=
I_PA0000PERNR.
FS_EMPLOYEE-ACTION_TYPE = I_PA0000-MASSN.
READ TABLE I_PA0001 WITH KEY PERNR = I_PA0000PERNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
FS_EMPLOYEE-EMP_GROUP = I_PA0001-PERSG.
FS_EMPLOYEE-EMP_SUBGROUP = I_PA0001-PERSK.
FS_EMPLOYEE-PERSONNEL_SUBAREA
=
I_PA0001BTRTL.
FS_EMPLOYEE-PAYROLL_AREA = I_PA0001-ABKRS.
FS_EMPLOYEE-COST_CENTER = I_PA0001-KOSTL.
FS_EMPLOYEE-ORGANIZATIONAL_UNIT = I_PA0001ORGEH.
FS_EMPLOYEE-POSITION = I_PA0001-PLANS.
ENDIF.
READ TABLE I_PA0002 WITH KEY PERNR = I_PA0000PERNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
FS_EMPLOYEE-LASTNAME = I_PA0002-NACHN.
FS_EMPLOYEE-FIRST_NAME = I_PA0002-VORNA.
FS_EMPLOYEE-GENDER = I_PA0002-GESCH.
FS_EMPLOYEE-DOB = I_PA0002-GBDAT.
ENDIF.
READ TABLE I_PA0007 WITH KEY PERNR = I_PA0000PERNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
FS_EMPLOYEE-WORK_SCHEDULE_RULE = I_PA0007SCHKZ.
FS_EMPLOYEE-DAILY_WORKING_HOURS = I_PA0007ARBST.
ENDIF.
READ TABLE I_PA0008 WITH KEY PERNR = I_PA0000PERNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
FS_EMPLOYEE-PAY_SCALE_TYPE = I_PA0008-TRFAR.
FS_EMPLOYEE-PAY_SCALE_AREA = I_PA0008-TRFGB.
FS_EMPLOYEE-PAY_SCALE_GROUP = I_PA0008-TRFGR.
FS_EMPLOYEE-PAY_SCALE_LEVEL = I_PA0008-TRFST.
FS_EMPLOYEE-INCREASE_DATE = I_PA0008-STVOR.
FS_EMPLOYEE-CURRENCY = I_PA0008-WAERS.
FS_EMPLOYEE-ANNUAL_SALARY = I_PA0008-ANSAL.
FS_EMPLOYEE-WAGE_TYPE1 = I_PA0008-LGA01.
FS_EMPLOYEE-AMOUNT1 = I_PA0008-BET01.
FS_EMPLOYEE-NUMBER1 = I_PA0008-ANZ01.
FS_EMPLOYEE-WAGE_TYPE2 = I_PA0008-LGA02.
FS_EMPLOYEE-AMOUNT2 = I_PA0008-BET02.
FS_EMPLOYEE-NUMBER2 = I_PA0008-ANZ02.
FS_EMPLOYEE-WAGE_TYPE3 = I_PA0008-LGA03.
FS_EMPLOYEE-AMOUNT3 = I_PA0008-BET03.
FS_EMPLOYEE-NUMBER3 = I_PA0008-ANZ03.
ENDIF.
READ TABLE I_PA0009 WITH KEY PERNR = I_PA0000PERNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
FS_EMPLOYEE-PAYMENT_METHOD = I_PA0009-ZLSCH.
FS_EMPLOYEE-BANK_COUNTRY = I_PA0009-BANKS.
FS_EMPLOYEE-BANK_KEYS = I_PA0009-BANKL.
FS_EMPLOYEE-BANK_ACCOUNT_NUMBER = I_PA0009BANKN.
FS_EMPLOYEE-BANK_CONTROL_KEY
=
I_PA0009BKONT.
ENDIF.
APPEND FS_EMPLOYEE TO T_EMPLOYEE.
ENDLOOP.
TRY.
FS_EMPLOYEE_MT-MT_EMPDET_OB-EMPLOYEE
=
T_EMPLOYEE.
CALL METHOD PRXY->EXECUTE_ASYNCHRONOUS
EXPORTING
OUTPUT = FS_EMPLOYEE_MT.
COMMIT WORK
.
CATCH CX_AI_SYSTEM_FAULT .
DATA FAULT TYPE REF TO CX_AI_SYSTEM_FAULT .
CREATE OBJECT FAULT.
WRITE :/ FAULT->ERRORTEXT.
ENDTRY.
When this report is executed, we can see the file in the FTP
server
with the employee details.
<?xml version="1.0" encoding="UTF-8" ?>
<ns0:MT_Empdet_ib
xmlns:ns0="http://yashclientproxies">
- <Employee>
<Personnel_number>00001002</Personnel_number>
<Action_Type>52</Action_Type>
<Emp_Group>1</Emp_Group>
<Emp_Subgroup>DT</Emp_Subgroup>
<Personnel_Subarea />
<Payroll_Area>D2</Payroll_Area>
<Cost_Center>0000002100</Cost_Center>
<Organizational_Unit>50000563</Organizational_Unit>
<Position>50000083</Position>
<Name>Ulrike Zaucker</Name>
<Gender>2</Gender>
<DOB>19600905</DOB>
<Work_Schedule_Rule>FLEX</Work_Schedule_Rule>
<Daily_Working_Hours>7.50</Daily_Working_Hours>
<Pay_scale_type>40</Pay_scale_type>
<Pay_Scale_Area>02</Pay_Scale_Area>
<Pay_Scale_Group>AT</Pay_Scale_Group>
<Pay_Scale_Level />
<Increase_date>00000000</Increase_date>
<Currency>EUR</Currency>
<Monthly_salary>0</Monthly_salary>
<Wage_Type1>MA90</Wage_Type1>
<Amount1>4601.63</Amount1>
<Number1>0.00</Number1>
<Wage_Type2 />
<Amount2>0.00</Amount2>
<Number2>0.00</Number2>
<Wage_Type3 />
<Amount3>0.00</Amount3>
<Number3>0.00</Number3>
<Payment_Method>U</Payment_Method>
<Bank_country>DE</Bank_country>
<Bank_Keys>23984899</Bank_Keys>
<Bank_account_number>253571587</Bank_account_numb
er>
<Bank_Control_Key />
</Employee>
</ns0:MT_Empdet_ib>
Understanding and working with ABAP Mapping
This document gives you clear understanding of ABAP
Mapping, how to enable the option to use ABAP Mapping
class in XI Interface Mappings, how to parse and read the
input XML source structure and build the output XML target
structure.
Below are different ways of achieving this conversion in XI:
1. Message Mapping (Graphical Mapping using Mapping
Editor in XI)
2. Java Mapping
3. ABAP Mapping
4. XSLT Mapping
The rest of the document gives you pre-requisites and steps
that are necessary for making use of ABAP Mapping class.
Pre-requisites and Steps required for developing ABAP
Mapping Classes
Pre-requisites: Enable ABAP Mapping:
Add additional mapping types in your exchange profile
Open
http://<host>:<port>/exchangeProfile/index.html
Choose
IntegrationBuilder
>IntegrationBuilder.Repository
->
com.sap.aii.repository.mapping.additionaltypes
Maintain
the
Entry
R3_ABAP|Abapclass;R3_XSLT|XSL
(ABAPEngine)
Check whether the data has been successfully read from
the exchange profile:
Open
http://<host>:<port>/rep/support/admin/index.html
Choose Administration of Properties -> All
Properties . If the value associated to parameter
com.sap.aii.repository.mapping.additionaltypes
is not correct, Choose at the top of the page and
refresh.
Steps to create an ABAP Mapping Class:
1. Create a new ABAP class in transaction SE24 of ABAP
Stack of XI,
2. The ABAP Class has to implement the interface
IF_MAPPING
3. The method EXECUTE of this interface needs to be
developed, this method will be called from during
mapping, the method has the following parameters:
The SOURCE parameter contains the input XML
structure in XSTRING format.
The mapping program needs to construct the
RESULT
xstring,
which
will
be
used
for
the
construction of output XML structure.
4. The explanation of the ABAP Mapping is provided later
in the document in the section Steps to be followed in
the ABAP Mapping Class.
Scenario Demonstrating the usage of ABAP Mapping
The scenario here involves the conversion of a
customer format xml file containing the information of
the employees in one specific format to another
format. The source file is available on the FTP and the
Sender file adapter picks it. This file is deleted and
archived on a different directory on the FTP. The
source XML file is converted into target XML file by the
ABAP mapping program and this target file is placed
on the FTP again on a different directory.
Here
structure:
is
the
source
XML
Here
is
the
target
XML
structure:
OBJECTS DEVELOPED FOR THE SCENARIO
The following are the object details that are
developed for this scenario:
Objects developed in the Integration Repository
o
DATA TYPES
DT_Emp_Det
DT_Employees
MESSAGE TYPE
MT_Emp_Det
MT_Employees
MESSAGE INTERFACES
MI_Emp_Det_OB
MI_Employees_IB
MESSAGE MAPPING
No Message Mapping is required as we
could directly specify the mapping object as
ABAP Mapping class in the Interface mapping
object.
INTERFACE MAPPING
IM_MI_Emp_Det_OB_MI_Employees_IB
Objects created in the Integration Directory
o
Business Service YASH_FTP (the same
business service is used as Sender and Receiver
)
Communication Channels
CC_XML_Sender_FIle
CC_XML_Receiver_FIle
Receiver
Agreement
Sender
Agreement
Interface
Determination
Receiver
Determination
Steps to be followed in ABAP Mapping classes
Any ABAP Mapping Class will basically consist of three
steps:
To parse the input xstring SOURCE
Traverse through the nodes of the input XML and read
the values of those nodes and copy that data to ABAP
internal tables and work areas.
Construct the output XML Stream from the internal
tables and work areas, which contain the collected
XML, input data.
To parse the input xstring SOURCE
The first step is to parse the input XML document,
for this we need to create a new parser instance and
implement the DOM generating interface to the
created parser instance.
The below are the interfaces and their methods used in
creating the parser instance.
Parse input document
* Initialize Input Document
data: idocument type ref to if_ixml_document.
* creates a new Document instance and returns an
interface pointer to this instance.
idocument = ixml_factory->create_document( ).
data: iparser type ref to if_ixml_parser.
* creates a new Parser instance and returns an interface
pointer to this instance.
iparser
=
ixml_factory->create_parser(
stream_factory = stream_factory
istream
= istream
document
= idocument ).
* implements the DOM-generating interface to the parser
iparser->parse( ).
From the above we understand that the pre-requisites
to create a new parser instance are a Stream factory,
an XML Input stream to parse and a document instance
into which the XML input stream is to be parsed.
To create a stream factory, first step is to create a
Main factory, i.e. instance of IXML class using the
method create of the class if_ixml.
* Create Main Factory
data: ixml_factory type ref to if_ixml.
* creates an instance of the iXML class and
returns an interface pointer to the instance.
ixml_factory = cl_ixml=>create( ).
* Next Create Stream Factory
* creates a new StreamFactory instance and
returns an interface pointer to this instance
data: stream_factory type ref to
if_ixml_stream_factory.
stream_factory
>create_stream_factory( ).
ixml_factory-
To create Input stream we need the above Stream
Factory instance created
* Create Input Stream
data: istream type ref to if_ixml_istream.
* creates a new XML input stream for the given
ABAP xstring
istream
=
stream_factory>create_istream_xstring( SOURCE ).
Where SOURCE is the input XML string.
Now the second step, Traverse through the nodes of the
input XML
Now we need to traverse through the nodes of the
input XML string and get the values of each node and
store them in ABAP work areas or internal tables
which will later be used in constructing the target XML
structure
For this we use Node interfaces like
o
if_ixml_node
if_ixml_node_list
The iXMLNode object is the primary
datatype for the entire Document Object
Model. It represents a single node in the
document tree.
The iXMLNodeList interface provides the
abstraction of an ordered collection of nodes,
without defining or constraining how this
collection is implemented.
if_ixml_node_collection
Objects implementing the
iXMLNodeCollection interface are used to
represent collections of nodes that can be
accessed by index rather than name.
if_ixml_node_iterator
An iterator allows the nodes of a data
structure to be returned sequentially. When
an iterator is first created, calling getNext ()
returns the first node. When no more nodes
are present, getNext () returns null.
Here our source XML structure will contain a
number of nodes in multiple hierarchical structure but
we know the parent node and so we should start
traversing from the parent node.
Get the collection of the parent node as below:
Our parent node in the demo scenario is EMPLOYEE,
* Returns an iXMLNodeCollection of all the elements
with a given tag name
* in the order in which they would be encountered in a
preorder
* traversal of the document tree.
emp_node_collection =
IDOCUMENT->GET_ELEMENTS_BY_TAG_NAME(
NAME = 'EMPLOYEE' ).
Where
emp_node_collection
type IF_IXML_NODE_COLLECTION
is
of
Next step is we need to create a node iterator as
below, which will traverse the above Node collection
from left to right
emp_node_iterator
=
>CREATE_ITERATOR( ).
emp_node_collection-
WHERE emp_node_iterator
IF_IXML_NODE_ITERATOR
is of
type
Loop thorugh each node and get the name of the
structure node
emp_node = emp_node_iterator->GET_NEXT( ).
WHERE emp_node is of type IF_IXML_NODE
Create a NODE LIST instance to traverse through
the child nodes under this node, use the following
method
emp_node_list = emp_node->GET_CHILDREN( ).
WHERE emp_node_list is of type ref to
IF_IXML_NODE_LIST
Now get the number of nodes in the above NODE
LIST structure as below:
emp_node_list_length
>GET_LENGTH( ).
emp_node_list
WHERE emp_node_list_length is of type I
Now to traverse to each node inside the above node
list collection and get the name and value of each node
the following methods need to be used, since there
areemp_node_list_length number of child node we
need to loop foremp_node_list_length times
* Loop through as many child nodes as there are
for the structure
DO emp_node_list_length TIMES.
*Here we get access to the subnodes i.e.
PERSONAL and JOB, and so as explained
earlier we need to again collect the node list
of each of these nodes, get their children
nodes list and finally get access to the
element nodes present in these children
nodes.
emp_subnode = emp_node_list_iterator->get_next(
).
emp_subnode_name = emp_subnode->get_name( ).
emp_subnode_list = emp_subnode->get_children(
).
emp_subnode_list_length
>get_length().
emp_subnode_list-
DO emp_subnode_list_length TIMES.
w_index = sy-index - 1.
w_node = emp_subnode_list->get_item(
w_index ).
w_node_name = w_node->get_name( ).
w_node_value = w_node->get_value( ).
* Check the name of the node and move the
value into the corresponding ABAP work
area.
ENDDO.
ENDDO.
As described above we could traverse through the
nodes and get those values, once the values are moved
to our ABAP work areas, we need to construct the
target XML string
The third step is to Construct the output XML Stream.
Create an output document
* Build up Output Document
* Create Output Document
data: odocument type ref to if_ixml_document.
* creates a new Document instance and returns
an interface pointer to this instance.
odocument = ixml_factory->create_document( ).
Now to create an element in the above created
output document instance , use the following method:
Create element 'EMPLOYEES' and add it to the document
data: PARENTNODE type ref to if_ixml_element.
Creates a simple element with the given name (and
namespace) and the specified value as text content. Note
that the instance returned implements the iXMLElement
interface, so attributes can be specified directly on the
returned object.
PARENTNODE
=
odocument->create_simple_element(
name = 'EMPLOYEES' parent = odocument ).
Now to create a child node for the above
PARENTNODE
CALL
METHOD
ODOCUMENT>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME
=
"Name
of
the
Element"
PARENT = "Give the Parent Element, here
PARENTNODE"
VALUE = "Value of the node, type string "
RECEIVING
RVAL
=
"Returns
the
created
Element"
.
The PARENT and RVAL of type IF_IXML_ELEMENT
As above we could continue adding elements with
desired names and values and hierarchy by looping
through the internal tables that we collected by
parsing the input document.
Once the ODOCUMENT is constructed, we need to
create the output stream and render the document
* render document
* create output stream
data: ostream type ref to if_ixml_ostream.
ostream
=
stream_factory>create_ostream_xstring( result ).
WHERE result is the output XML string
Create renderer
*
create
renderer
data:
renderer
type
ref
to
if_ixml_renderer.
renderer = ixml_factory->create_renderer( ostream =
ostream
document
=
odocument
).
renderer->render( ).
This would complete the mapping.
ABAP Class Code
Here is the ABAP Mapping Class Code i.e. developed for
reference:
*********************************************************
*************
method IF_MAPPING~EXECUTE.
data:
emp_node_collection type ref to if_ixml_node_collection,
emp_node_length
type i,
emp_node_iterator type ref to if_ixml_node_iterator,
emp_node
type ref to if_ixml_node,
emp_node_list
type ref to if_ixml_node_list,
emp_node_list_length type i,
emp_node_list_iterator type ref to if_ixml_node_iterator,
emp_subnode
type ref to if_ixml_node,
emp_subnode_list
type ref to if_ixml_node_list,
emp_subnode_list_length type i,
emp_subnode_name
type string,
w_node_name
type string,
w_node_value
type string,
w_fieldname
type string,
w_tablename
type string,
w_index
type i,
w_node
type ref to if_ixml_node.
data:
odocument
type ref to if_ixml_document,
fs_output
type string,
employee_node type ref to if_ixml_node,
personal_node type ref to if_ixml_node,
job_node
type ref to if_ixml_node,
rnode
type ref to if_ixml_node.
data:
begin of fs_job,
empid
type string,
company
type string,
department type string,
designation type string,
begindate type string,
enddate
type string,
salary
type string,
end of fs_job,
begin of fs_personal,
empid
type string,
firstname type string,
middlename type string,
lastname type string,
age
type i,
gender type string,
end of fs_personal,
t_personal like standard table of fs_personal,
t_job
like standard table of fs_job.
field-symbols:
<fs> type any,
<fs_table> type table.
* Initialize iXML
type-pools ixml.
class cl_ixml definition load.
* create main factory
data: ixml_factory type ref to if_ixml.
ixml_factory = cl_ixml=>create( ).
* create stream factory
data: stream_factory type ref to if_ixml_stream_factory.
stream_factory = ixml_factory->create_stream_factory( ).
* create input stream
data: istream type ref to if_ixml_istream.
istream = stream_factory->create_istream_xstring( source
).
* create input document
data : idocument type ref to if_ixml_document.
* initialize parser
idocument = ixml_factory->create_document( ).
* Parse the input document
data iparser type ref to if_ixml_parser.
iparser = ixml_factory->create_parser( stream_factory =
stream_factory
istream = istream
document = idocument ).
* Implements the DOM generating interface to the parser
iparser->parse( ).
emp_node_collection
=
idocument>get_elements_by_tag_name_ns( name = 'EMPLOYEE' ).
emp_node_length = emp_node_collection->get_length( ).
emp_node_iterator
=
emp_node_collection>create_iterator( ).
DO emp_node_length times.
emp_node = emp_node_iterator->get_next( ).
emp_node_list = emp_node->get_children( ).
emp_node_list_length = emp_node_list->get_length( ).
emp_node_list_iterator = emp_node_list->create_iterator(
).
DO emp_node_list_length TIMES.
emp_subnode = emp_node_list_iterator->get_next( ).
emp_subnode_name = emp_subnode->get_name( ).
emp_subnode_list = emp_subnode->get_children( ).
emp_subnode_list_length
=
emp_subnode_list>get_length( ).
DO emp_subnode_list_length TIMES.
w_index = sy-index - 1.
w_node = emp_subnode_list->get_item( w_index ).
w_node_name = w_node->get_name( ).
w_node_value = w_node->get_value( ).
concatenate 'fs_' emp_subnode_name '-' w_node_name
into w_fieldname.
assign (w_fieldname) to <fs>.
if sy-subrc eq 0.
move w_node_value to <fs>.
endif.
ENDDO.
concatenate 'fs_' emp_subnode_name into w_fieldname.
assign (w_fieldname) to <fs>.
check sy-subrc eq 0.
concatenate 't_' emp_subnode_name into w_tablename.
assign (w_tablename) to <fs_table>.
if sy-subrc eq 0.
move fs_personal-empid to fs_job-empid.
append <fs> to <fs_table>.
endif.
ENDDO.
ENDDO.
odocument = ixml_factory->create_document( ).
CALL
METHOD
ODOCUMENT>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'EMPLOYEES'
PARENT = ODOCUMENT
*
PREFIX = ''
*
*
URI = ''
VALUE = ''
RECEIVING
RVAL = EMPLOYEE_NODE
.
loop at t_personal into fs_personal.
clear fs_output.
CALL
METHOD
>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'PERSONAL'
PARENT = EMPLOYEE_NODE
*
PREFIX = ''
*
URI = ''
VALUE = fs_output
RECEIVING
RVAL = PERSONAL_NODE
.
concatenate fs_personal-firstname
fs_personal-middlename
fs_personal-lastname
into fs_output.
CALL
METHOD
>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'FULLNAME'
PARENT = personal_node
*
PREFIX = ''
*
URI = ''
VALUE = fs_output
RECEIVING
RVAL = RNODE
.
move fs_personal-age to fs_output.
ODOCUMENT-
ODOCUMENT-
CALL
METHOD
ODOCUMENT>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'AGE'
PARENT = personal_node
*
PREFIX = ''
*
URI = ''
VALUE = fs_output
RECEIVING
RVAL = RNODE
.
CALL
METHOD
ODOCUMENT>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'GENDER'
PARENT = personal_node
*
PREFIX = ''
*
URI = ''
VALUE = fs_personal-gender
RECEIVING
RVAL = RNODE.
loop at t_job into fs_job where empid = fs_personalempid.
AT NEW EMPID.
CALL
METHOD
ODOCUMENT>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'JOB'
PARENT = EMPLOYEE_NODE
*
PREFIX = ''
*
URI = ''
*
VALUE = ''
RECEIVING
RVAL = JOB_NODE.
ENDAT.
concatenate fs_job-company
fs_job-department
fs_job-designation
fs_job-begindate
fs_job-enddate
fs_job-salary
into fs_output
separated by '*'.
CALL
METHOD
ODOCUMENT>CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'COMPANYDATA'
PARENT = JOB_NODE
*
PREFIX = ''
*
URI = ''
VALUE = fs_output
RECEIVING
RVAL = RNODE.
endloop.
endloop.
* create output stream
data ostream type ref to if_ixml_ostream.
ostream = stream_factory->create_ostream_xstring( result
).
* create renderer
data renderer type ref to if_ixml_renderer.
renderer = ixml_factory->create_renderer( ostream =
ostream
document = odocument ).
* implements DOM based interface to the renderer.
renderer->render( ).
endmethod.
Testing of ABAP Mapping Class
The above-created Mapping program could be tested by
using the transaction XI_MAPPING_TEST.
This transaction requires the Sender details i.e. Sender
Service/Party Name, Sender Interface Namespace, Sender
Interface; the Receiver details i.e. Receiver Service/Party
Name, Receiver Interface Namespace, Receiver Interface
And Input XML source file.
Source Input XML File:
Source Input XML File:
<?xml version="1.0" encoding="UTF-8" ?>
<ns0:MT_Emp_Det
xmlns:ns0="http://yash.com/YH203/file2file_abapmapping"
>
- <EMPLOYEE>
- <PERSONAL>
<EMPID>001</EMPID>
<FIRSTNAME>Santosh</FIRSTNAME>
<MIDDLENAME>Kumar</MIDDLENAME>
<LASTNAME>K</LASTNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANY>XYZ</COMPANY>
<DEPARTMENT>SAP</DEPARTMENT>
<DESIGNATION>Consultant</DESIGNATION>
<BEGINDATE>20050606</BEGINDATE>
<ENDDATE />
<SALARY>600000</SALARY>
</JOB>
- <PERSONAL>
<EMPID>002</EMPID>
<FIRSTNAME>Bala</FIRSTNAME>
<MIDDLENAME>Krishna</MIDDLENAME>
<LASTNAME>Reddy</LASTNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANY>XYZ</COMPANY>
<DEPARTMENT>SAP</DEPARTMENT>
<DESIGNATION>Consultant</DESIGNATION>
<BEGINDATE>20050606</BEGINDATE>
<ENDDATE>20061206</ENDDATE>
<SALARY>600000</SALARY>
</JOB>
- <JOB>
<COMPANY>XYZ</COMPANY>
<DEPARTMENT>SAP</DEPARTMENT>
<DESIGNATION>Consultant</DESIGNATION>
<BEGINDATE>20070106</BEGINDATE>
<ENDDATE />
<SALARY>800000</SALARY>
</JOB>
</EMPLOYEE>
</ns0:MT_Emp_Det>
Target output XML File generated:
<?xml version="1.0" ?>
- <EMPLOYEES>
- <PERSONAL>
<FULLNAME>SantoshKumarK</FULLNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANYDATA>XYZ*SAP*Consultant*20050606**60000
0</COMPANYDATA>
</JOB>
- <PERSONAL>
<FULLNAME>BalaKrishnaReddy</FULLNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANYDATA>XYZ*SAP*Consultant*20050606*200612
06*600000</COMPANYDATA>
<COMPANYDATA>XYZ*SAP*Consultant*20070106**80000
0</COMPANYDATA>
</JOB>
</EMPLOYEES>
ABAP Proxy communication (Server Proxy)
Proxy
objects
implement
message
interfaces
from
Integration Repository. Proxies are executable interfaces,
which
converts
non-language-specific
interface
descriptions into WSDL. i.e., you use proxies to implement
the actual message exchange that is described in the
Integration Builder.
Types of Proxy objects: You can use message interfaces to
create the following proxy objects:
ABAP Proxy objects
JAVA Proxy objects
During the process of ABAP proxy generation, it gets WSDL
(Web
Service
Description
Language)
description
of
message interfaces from the Integration Repository by
using HTTP communication.
Proxy Generation:
As part of SAP Web AS 6.40
The
ABAP proxy generation enables you to generate
proxies to communicate by using the Web service
infrastructure
and
by
using
SAP
Exchange
Infrastructure
ABAP proxies that were generated from message
interfaces in the Integration Repository (IR) can be
used in both infrastructures.
This means that if none of the Integration Server
services
are
available
for
a
proxy-to-proxy
communication scenario in ABAP, you can use a pointto-point
connection
using
the
Web
service
infrastructure instead.
prerequisites
to
configure
ABAP
Proxy
include:
(landscape dependent)
1. The business systems should be based on SAP Web AS
6.20 and SAP Web AS 6.20 kernel patch level above
1253
2. You have installed the XI Add-On in each of these
business systems as described in the Installation
Guide SAP Exchange Infrastructure 3.0
3. The business systems and your central Integration
Server are maintained in the System Landscape
Directory (SLD).
Configuration required on the Business System:
1.
Create a HTTP connection in the business system
using transaction SM59
Technical Setting:
Connection Type: H
Target Host: System name
Service Number: HTTP Port name
Path Prefix: /sap/XI/engine/?type=entry
Logon Security
On the Logon/Security tab page, enter the following logon
data:
User: XIAPPLUSER (for example); this user should
represent the sending business system (see also the
SAP XI Security Guide under Service Users for
Message Exchange).
Password: the password you have specified for
this user
Client: SAP XI Integration server
Language: Language required
2.
Configuration Business system as local Integration
Engine.
1.
Go to Transaction SXMB_ADM
2.
Choose Edit --> Change Global Configuration Data.
3.
Select Role of Business System: Application system
4.
Corresponding Integration server:
dest://<HTTPDESTINATION>.
Here
<HTTPDESTINATION> XI_XIR_CONNECTION created
in step 1. Dest://XI_XIR_CONNECTION.
5.
Under Specific Configuration Data you can specify
additional configuration data
Select the relevant category under Specific
Configuration Data.
Choose Change Specific Configuration Data.
For
ABAP
Proxies,
Add
the
following
configuration:
1.Category
RUNTIME
2.Parameters:
IS_URL
3.Current
Value:
dest://XI_XIR_CONNECTION
3.
Connection between Business System and System
Landscape Directory
4.
Create RFC destination (TCP/IP) LCRSAPRFC and
SAPSLDAPI for the SLD connection.
To create RFC Destination: LCRSAPRFC
o Connection Type: T
o Choose the Technical settings tab page and do
the
following:
In the Program ID field under Registered Server
Program,
enter
LCRSAPRFC
This program ID must correspond to a program ID
specified in the RFC engine settings of the SAP
J2EE Engine on the Integration Server host.
Repeat the above step for RFC destination for
SAPSLDAPI
Maintaining the SAP J2EE Connection Parameters for
LCRSAPRFC
5.
and
SAPSLDAPI
in
SAP
J2EE
engine
Goto J2EE Engine
Choose Cluster --> Server --> Services. JCo RFC
provider
Under RFC destination specify the following:
Program
ID:
LCRSAPRFC
Gateway
Host:
<Integration
Server
host>
Gateway Service: <Integration Server gateway
service>
Number of process: 3
Under Repository specify the following: Application
Server: <Integration Server host>
Maintain SLD access details in Transaction
SLDAPICUST
If there is an HTTP error during connection, check the error
using the transaction SLDCHECK in the Business system.
Also ensure that HTTP connection is working fine.
In XI Adapter use HTTP connection rather than giving R/3
input details, as this is easier to transport and for
maintenance. One receiver adapter can be used for all
Interfaces connecting to a Business system.
Demo Scenario
This document describes Time bound file processing
scenario where in, a file containing the employee personal
details is picked from a FTP server system (Sender/Source)
and sent to SAP System (Receiver/Target) via Exchange
Infrastructure. Server ABAP proxy is configured to post the
data to an application on target SAP System which will save
the records into database.
Let us have design in Integration repository. The following
screen illustrates the outbound message structure in which
employee data type is encapsulated.
In this example a small difference is maintained between
the source message structure and target structure to show
the need of mapping. Find below the mapping where in Full
name is constructed after concatenating the Last name and
First name.
Finally
we
encapsulate
require
the
a message
message
interface, which
mapping
between
will
source
structure and target structure.
Before
completing
the
configuration
in
Integration
Directory, let us create a ABAP proxy object in Target SAP
system.
Go to Transaction: SPROXY where in you get to see all the
objects designed in Integration Repository. As Proxies
implement message interfaces in Integration Repository,
navigate to the required inbound message interface, as we
are creating a Server proxy. Right click to create the Proxy
as shown in the below screenshot.
You can observe a Proxy-interface getting created in Target
system with Properties, Generation, Structure and Type
Mappings.
You observe that Structures resembling inbound data
types, message types get created in the system. As the
target structure can get multiple records of Employee
personal details in this scenario, observe that a Table type
of ZEMPLOYEE_IB_EMPLOYEE_TAB getting created. This
can be transferred to required application in SAP for
successful processing of the records, ultimately saving
them into database.
You can observe the compatible equivalent elements of
inbound data type created.
Finally you need to implement the Proxy. For this double
click Implementing Class on Properties tab to lead you to
method
EXECUTE_ASYNCHRONOUS.
This
is
default
method that gets created with Implementing Class where
in you need to code as per the business logic. Find below
the screenshot of the sample code that reads the data from
Employee internal table and inserts the data into database.
Now it is the time for configuration. Logon to XI
integration directory to start creating the collaborative
profiles and agreements to route the message from source
system and then placing a proxy call to server proxy to
post the data to target SAP System.
First we need a Sender Communication channel, which will
be able to pick up the file from source FTP server. Find
below the attributes of the communication channel, which
is of type File.
Then create a receiver communication channel to place a
proxy call. Though we use XI Adapter for placing the proxy
call, we will call this communication as Adapter less
communication. The reason is, usually an adapter is used
to specify transport protocol where in this is used to define
the mode of communication and message protocol where
in this is used to convert the message format from XML to
native format and other wise.
As XI adapter is defined with HTTP as transport protocol
and XI as message protocol, both are default protocols of
XI environment,
communication.
hence
we
say
it
is
adapter
less
To complete the configuration we have to define
collaborative profiles and agreements, which include
Sender Agreement, Receiver Agreement, Interface
Determination and Receiver Agreement. Find below the
screenshots explaining the same.
Now prepare the file with Employee personal details
resembling outbound message type as shown below:
This file is placed on FTP server to wait for the XI server to
pick of the file at regular intervals, hence we can call the
scenario to be Time bound file processing.
After the defined periodicity as per Sender communication
channel, the file is picked for processing and can be found
through ABAP stack of XI through the transaction code
SXI_MONITOR. This is explained in the screenshot below:
Shortly you will notice that the message got successfully
processed and data is posted in the database.
The record that got posted is related to SSN 999 that can
be viewed in the database.