Sunteți pe pagina 1din 25

SAP-to-SAP Integration Using Custom IDOCs

SAP-to-SAP Integration Using Custom IDOCs

Applies to:
ABAP Development, Data Transfer.

Summary
Using IDOCs data can be exchanged between SAP R/3 and Non R/3 systems. The objective of this article is
to show / configure data transmission from one SAP R/3 system to another SAP R/3 system via custom
IDOC.
Author(s): Trupti Zanwar
Company: ArchitectSAP Solutions
Created on: 04 January 2008

Author Bio
Trupti Zanwar works for ArchitectSAP Solutions as an SAP Process Integration Consultant.

This article explains the scenario of transferring data across two SAP R/3 systems using IDOCs. The IDOC
developed is a custom-developed IDOC.

Sender SAP IDOC Receiver SAP


System System

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Table of Contents
Applies to: ........................................................................................................................................ 1
Summary.......................................................................................................................................... 1
Author Bio ........................................................................................................................................ 1
Steps to Develop Outbound IDOC in Sender R/3 system............................................................... 3
Creation of Basic IDOC Type....................................................................................................... 3
Creation of Basic IDOC Type....................................................................................................... 4
Creation & Assignment of Message Type.................................................................................... 7
Creation of RFC connection for Receiver system...................................................................... 10
Creation of Logical system......................................................................................................... 10
Defining Partner Profile .............................................................................................................. 13
Steps to Develop Inbound IDOC in Receiving R/3 system ........................................................... 15
Create Inbound Function Module:.............................................................................................. 15
Maintain Attributes for Function Module .................................................................................... 16
Creating Process code............................................................................................................... 17
Creating Partner profile .............................................................................................................. 19
Testing the Data Transfer using IDOC Processing ....................................................................... 21
Disclaimer and Liability Notice....................................................................................................... 25

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Steps to Develop Outbound IDOC in Sender R/3 system


Creation of Basic IDOC Type
Go to TC: WE31
To Create IDOC Structure: Segments
[Segment defines the format and structure of a data record.]

As shown in below screen shot, add the fields which are required to be sent using IDOC.

After adding the fields, release the segment using menu EDIT-> Release segment.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Creation of Basic IDOC Type


Go to TC: WE30
To Create: Basic IDOC Type.
[Basic IDOC type defines the structure and format of the business document that is to be exchanged.]

IDOC Type has a


Specific name
List of permitted segments
Hierarchy of segments
Mandatory/optional segments
Minimum / maximum range of each segment.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

As shown in below screen shot, assign the segment type to the IDOC type and release it.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Creation & Assignment of Message Type


Go to TC: WE81
Create Message Type
Change the details from Display mode to Change mode.
System will give the message “Caution: The Table is cross-client “. Press Enter.
Click New Entries to create new Message Type
Fill Details. Save it and Go Back

[The business background is established by assigning the IDOC type to one or more messages.]

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Go to TC: WE82
Assign Message Type to IDOC Type
Enter the SAP release.
Use your change request for the basic type definition again when you save the data.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Creation of RFC connection for Receiver system


Go to TC: SM59
To Configure RFC Connection for Receiver System.

Define RFC Destination for Receiver system i.e. R/3 system

Provide all technical settings for receiver system. System name for your R/3 system and its system number.
Move to the logon & security tab to provide logon details like Language, Client, user and password.

Creation of Logical system


Go to TC: BD54
Configure a Logical System as Receiver System.
Change the details from Display mode to Change mode.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

System will give the message “Caution: The Table is cross-client “. Press Enter.
Create New Entries. Give name to your Logical System and Description for the same.
[Logical system name should be similar to partner profile.]

Go to TC: WE21
Configure Port in IDOC Processing for Receiver System.
Choose tRFC as a Port for IDOC Processing and Choose Create New

In a Pop up system will prompt you to choose options from Generate port name or to define your own port
name. You can define port name of your choice.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Defining Partner Profile


Go to TC: WE20
Configure a Partner Profile for your Receiver System.
Select Partner Type LS (Logical System). Choose Create New.
Enter Logical System Name as Partner No. which you have created in previous step i.e. BD54. Partner Type
should be LS.
Fill all mandatory fields as per your system specifications. You can Choose F4 help.
Add a new row in Outbound Parameters and select Message Type which you have created in custom IDOC
as shown below
[The partner profile contains parameters that define the electronic interchange of data with a partner via that
IDOC interface.]

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Steps to Develop Inbound IDOC in Receiving R/3 system

Pre-requisites to process the incoming IDOCs are as follows:

Create segments, IDOC type and release them as described in Section 1& 2
Create Message type and associate Message type with IDOC using Transaction WE82 as described in
section 3.
Define a Function Module to process the data received from receiving system and update the Z Table.

Go to TC: SE11
To store the received data, create Z database table with all the required fields as shown in below screen
shot.

Create Inbound Function Module:

Go to TC: SE37
To populate the data in Database table, we are required to create a function module in which code is written
to map the IDOC segment data with corresponding database table fields and update the table. Sample code
for the same is as below.

FUNCTION CHANGE_IDOC_STAT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS


*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------

Data wa_table type ZPRO_MAT_IDOC1.


LOOP AT idoc_contrl.
* check if the idoc has syntax error
IF NOT idoc_contrl-status IS INITIAL.
SELECT COUNT(*) FROM edids WHERE docnum = idoc_contrl-docnum
AND status = '64' AND UNAME = 'BCUSER'.
IF sy-subrc = 0.
workflow_result = '99999'.

CLEAR idoc_status.
idoc_status-status = '53'.
idoc_status-msgid = 'B1'.
idoc_status-msgty = 'E'.
idoc_status-msgno = '561'.
idoc_status-repid = sy-repid.
idoc_status-docnum = idoc_contrl-docnum.
APPEND idoc_status.
CLEAR return_variables.
return_variables-wf_param = 'Error_IDOCs'.
return_variables-doc_number = idoc_contrl-docnum.
APPEND return_variables.
CONTINUE.
ENDIF.
ENDIF.
ENDLOOP.

LOOP AT idoc_data.
MOVE idoc_data-sdata(10) TO wa_table-MATERIAL_NO.
MOVE idoc_data-sdata+10(40) TO wa_table-M_DESCRIPTION.
MOVE idoc_data-sdata+50(200) TO wa_table-UOM.
INSERT ZPRO_MAT_IDOC1 FROM wa_table.
Endloop.
ENDFUNCTION.

Maintain Attributes for Function Module


Go to TC: BD51
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Maintain function modules for inbound processing.

Go to TC: WE57
Associate Function Module with IDOC.

Creating Process code


Go to TC: WE42
Create a Process Type.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Go to TC: WE21
To create tRFC port for sender system.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Creating Partner profile


Go to TC: WE20
Create partner profile in receiver system.
Associate the Message Type with the Sending System.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Testing the Data Transfer using IDOC Processing


Go to TC: WE19
Test IDOC Creation.

Double click on header:

As shown in below popup fill the values which are required to be transferred using IDOC.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Go to TC: WE02 or WE05


Check outbound as well as inbound IDOCs. Using any of these transactions in receiver system, find the
inbound IDOC.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Double click on IDOC number:

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Go to TC: SE16
To check the data is posted to the database table in receiver system.

In the below screen shot we can see that the entry posted by inbound IDOC in the custom table.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG
SAP-to-SAP Integration Using Custom IDOCs

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces
and therefore is not supported by SAP. Changes made based on this information are not supported and can
be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content
within this document and the materials and services offered by SAP. You agree that you will not hold, or
seek to hold, SAP responsible or liable with respect to the content of this document.

SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

© 2008 SAP AG

S-ar putea să vă placă și