ale&idocs

8
7/29/2019 ale&idocs http://slidepdf.com/reader/full/aleidocs 1/8  Log In Register About Us How to Contribute Store Welcome Guest SDN Community BPX Community Business Analytics University Alliances SAP EcoHub Home Forums Wiki Blogs Arti cles eLearning Downloads Code Exchange Career Cente r Events InnoCentive Idea Place SAP Help Portal Added by jeevitha, last edited by jeevitha on Jul 14, 2008 ALE IDOCS BEGINNER'S GUIDE TO ALE AND IDOCS - A STEP-BY-STEP APPROACH This article will help you understand the basics of ALE and IDocs via a simple do-it-yourself example. We will create a custom IDoc in one SAP system and then post some business data through it to another SAP system. Business data will be picked up from custom data dictionary tables. ALE - Application Link Enabling is a mechanism by which SAP systems communicate with each other and with non-SAP EDI subsystems. Thus it helps integration of distributed systems. It supports fail-safe delivery which implies that sender system does not have to worry about message not reaching the source due to unavoidable situations. ALE can be used for migration and maintenance of master data as well as for exchanging transactional data. The messages that are exchanged are in the form of IDocs or Intermediate Documents. IDocs act like a container or envelope for the application data. An IDOC is created as a result of execution of an Outbound ALE. In an Inbound ALE an IDOC serves as an input to create application document. In the SAP system IDocs are stored in the database tables. They can be used for SAP to SAP and SAP to non-SAP process communication as long as the participating processes can understand the syntax and semantics of the data. Complete documentation on IDOC is obtained by using transaction WE60. Every IDoc has exactly one control record along with a number of data records and status records. Control record has the details of sender/receiver and other control information. Data records contain the actual business data to be exchanged while the status records are attached to IDoc throughout the process as the IDoc moves from one step to other. Now, let us understand the ALE Configuration by means of an example scenario below: The Scenario Data from custom tables (created in customer namespace) is to be formatted into an IDoc and sent from one SAP R/3 system to another using ALE service. We need to have two instances of SAP R/3 systems or we can simulate this on two clients of the same SAP R/3 system. Create three tables as shown below. Creating Custom IDoc type and Message type All the objects created should be present on both source as well as target system(s). 1. Create segments - Transaction WE31 Create a segment ZRZSEG1 Add all fields of table ZCUSTOMERS to it Save the segment Release it using the menu path Edit -> Set Release Similarly create two more segments given below Seg. ZRZSEG2 - to hold all fields of table ZSOHEADERS Seg. ZRZSEG3 - to hold all fields of table ZSOITEMS 2. Create Basic IDoc type - Transaction WE30 Create a Basic type ZRZORDER Add the created segments in the hierarchy shown Maintain attributes for each of the segments Save the object and go back Release the object using the menu path Edit -> Set Release 3. Create/Assign Message type - Transactions WE81/WE82 Go to WE81 Create a new Message type ZRZSO_MT Save the object Go to WE82 and create new entry Assign the message type ZRZSO_MT to the basic type ZRZORDER Also specify the Release Version Save the object Thus we have defined the IDoc structure which will hold the data to be transferred. In the next part of the article we will understand the outbound settings, i.e. the settings to be done in the source system. In the previous article we created an IDoc structure which can carry our data from source system to target system(s). In this part we will understand how to setup the source system to be able to generate and send an outbound IDoc. Outbound Settings Define Logical Systems and Assign Client to Logical System - Transaction SALE Go to Define Logical System (See the figure) Define a new logical system to identify the local system and save it Now, go to Assign Client to Logical System (See the figure) Add a new entry Specify the client, previously created l ogical system and other attributes Save the entry Define a new logical system to identify the partner system and save it Maintain RFC Destinations - Transaction SM59 Create a new RFC destination for R/3 type connection Specify the target host on Technical settings tab Provide the Logon credentials on the Logon/Security tab Save the settings Page 1 of 8 SAP Community Network Wiki - ABAP Development - ALE IDOCS 8-11-2011 http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Transcript of ale&idocs

Page 1: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 1/8

 

Log In Register About Us How to Contribute Store

Welcome Guest

SDN Community BPX Community Business Analytics University Alliances SAP EcoHub

Home Forums Wiki Blogs Arti cles eLearning Downloads Code Exchange Career Cente r Events InnoCentive Idea Place SAP Help Portal

Added by jeevitha, last edited by jeevitha on Jul 14, 2008

ALE IDOCS 

BEGINNER'S GUIDE TO ALE AND IDOCS - A STEP-BY-STEP APPROACH 

This article will help you understand the basics of ALE and IDocs via a simple do-it-yourself example. We will create a custom IDoc in one SAP system and then post some business data through it to

another SAP system. Business data will be picked up from custom data dictionary tables.

ALE - Application Link Enabling is a mechanism by which SAP systems communicate with each other and with non-SAP EDI subsystems. Thus it helps integration of distributed systems. It supports

fail-safe delivery which implies that sender system does not have to worry about message not reaching the source due to unavoidable situations. ALE can be used for migration and maintenance of

master data as well as for exchanging transactional data.

The messages that are exchanged are in the form of IDocs or Intermediate Documents. IDocs act like a container or envelope for the application data. An IDOC is created as a result of execution of

an Outbound ALE. In an Inbound ALE an IDOC serves as an input to create application document. In the SAP system IDocs are stored in the database tables. They can be used for SAP to SAP and

SAP to non-SAP process communication as long as the participating processes can understand the syntax and semantics of the data. Complete documentation on IDOC is obtained by using

transaction WE60.

Every IDoc has exactly one control record along with a number of data records and status records. Control record has the details of sender/receiver and other control information. Data records contain

the actual business data to be exchanged while the status records are attached to IDoc throughout the process as the IDoc moves from one step to other.

Now, let us understand the ALE Configuration by means of an example scenario below:

The Scenario

Data from custom tables (created in customer namespace) is to be formatted into an IDoc and sent from one SAP R/3 system to another using ALE service. We need to have two instances of SAP

R/3 systems or we can simulate this on two clients of the same SAP R/3 system.

Create three tables as shown below.

Creating Custom IDoc type and Message type  

All the objects created should be present on both source as well as target system(s).

1. Create segments - Transaction WE31

Create a segment ZRZSEG1•

Add all fields of table ZCUSTOMERS to it•

Save the segment•

Release it using the menu path Edit -> Set Release•

Similarly create two more segments given below•

Seg. ZRZSEG2 - to hold all fields of table ZSOHEADERS•

Seg. ZRZSEG3 - to hold all fields of table ZSOITEMS•

2. Create Basic IDoc type - Transaction WE30

Create a Basic type ZRZORDER•

Add the created segments in the hierarchy shown•

Maintain attributes for each of the segments•

Save the object and go back•

Release the object using the menu path Edit -> Set Release•

3. Create/Assign Message type - Transactions WE81/WE82

Go to WE81•

Create a new Message type ZRZSO_MT•

Save the object•

Go to WE82 and create new entry•

Assign the message type ZRZSO_MT to the basic type ZRZORDER•

Also specify the Release Version•

Save the object•

Thus we have defined the IDoc structure which will hold the data to be transferred. In the next part of the article we will understand the outbound settings, i.e. the settings to be done in the source

system.

In the previous article we created an IDoc structure which can carry our data from source system to target system(s). In this part we will understand how to setup the source system to be able to

generate and send an outbound IDoc.

Outbound Settings

Define Logical Systems and Assign Client to Logical System - Transaction SALE

Go to Define Logical System (See the figure)•

Define a new logical system to identify the local system and save it•

Now, go to Assign Client to Logical System (See the figure)•

Add a new entry•

Specify the client, previously created l ogical system and other attributes•

Save the entry•

Define a new logical system to identify the partner system and save it•

Maintain RFC Destinations - Transaction SM59

Create a new RFC destination for R/3 type connection•

Specify the target host on Technical settings tab•

Provide the Logon credentials on the Logon/Security tab•

Save the settings•

Page 1 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS

8-11-2011http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Page 2: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 2/8

To verify the settings, Click on Test connection or Remote logon•

Define Ports - Transaction WE21

We need to define a tRFC port for the partner system•

Click on Transactional RFC node•

Create a new port•

Provide a description•

Specify the name of the target RFC destination•

Save the object•

Maintain Distribution Model - Transaction BD64

Click on Change•

Create a new model view•

Provide a Short text and Technical name to the model view•

Add message type•

Specify sender and receiver systems•

Also, specify the message type that we created previously•

Save the Distribution model•

Generate/Create Partner Profile - Transactions BD82/WE20

To generate Partner profiles automatically you may use BD82 or go to BD64 and use the menu path Environment -> Generate partner profiles•

Otherwise, you may use transaction WE20 to create a partner profile◦

On selection screen, specify the model view, target system and execute•

The result log will be displayed on the next screen•

To verify the partner profile go to WE20•

Check the partner profile for the target system•

Distribute Model View - Transaction BD64

Select the Model View•

Go to menu path Edit -> Model View -> Distribute•

Result log will be displayed on the next screen•

Outbound IDoc Generation Program

Create an executable program ZRZ_ORDER_IDOC in SE38. Below, I have described the program logic:

Fetch the data from the DDic tables ZCUSTOMERS, ZSOHEADERS and ZSOITEMS as per the selection criteria•

Fill the control record structure of type EDIDC•

Specify message type, Basic IDoc type, tRFCPort, Partner number and Partner type of the receiver◦

Fill the data records•

Define structures like the IDoc segments◦

Fill the structures with fetched data◦

Pass the segment name and the above structure to the appropriate fields of EDIDD type structure◦

Append the EDIDD structure to the EDIDD type internal table◦

Now, call the function module MASTER_IDOC_DISTRIBUTE and pass the IDoc control record structure and data record table•

Commit work if return code is zero•

Function module returns a table of type EDIDC to provide the details about generated IDoc•

Display appropriate log•

Sample code for above scenario.

Thus we have completed sender side configuration required for ALE. In the next part we will see how to configure the receiving system to be able to receive and post the inbound IDoc.&-------------------

-------------------------------------------------- 

*& Report ZRZ_ORDER_IDOC *

*& *

&--------------------------------------------------------------------- 

REPORT ZRZ_ORDER_IDOC .

***********************************************************************

PURPOSE OF REPORT *

***********************************************************************

Generats an Idoc for Customer Master, Sales Master•

and Sales item table.

***********************************************************************

TABLES : ZCUSTOMERS, "Cutomer Header

ZSOHEADERS, "Sales Header

ZSOITEMS. "Sales Items

DATA : S_CTRL_REC LIKE EDIDC, "Idoc Control Record

S_ZRZSEG1 LIKE ZRZSEG1, "CUSTOMER Header Data

S_ZRZSEG2 LIKE ZRZSEG2, "SALES HEADER Data

S_ZRZSEG3 LIKE ZRZSEG3. "SALES Detail Data

DATA : T_ZCUSTOMERS LIKE ZCUSTOMERS OCCURS 0 WITH HEADER LINE.

DATA : T_ZSOHEADERS LIKE ZSOHEADERS OCCURS 0 WITH HEADER LINE.

DATA : T_ZSOITEMS LIKE ZSOITEMS OCCURS 0 WITH HEADER LINE.

DATA : T_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE."Data Records

DATA : T_COMM_IDOC LIKE EDIDC OCCURS 0 WITH HEADER LINE.

"Generated Communication IDOc

Page 2 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS

8-11-2011http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Page 3: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 3/8

 

CONSTANTS :

C_ZRZSEG1 LIKE EDIDD-SEGNAM VALUE 'ZRZSEG1',

C_ZRZSEG2 LIKE EDIDD-SEGNAM VALUE 'ZRZSEG2',

C_ZRZSEG3 LIKE EDIDD-SEGNAM VALUE 'ZRZSEG3'.

CONSTANTS: C_IDOCTP LIKE EDIDC-IDOCTP VALUE 'ZRZORDER'.

Selection Screen

SELECT-OPTIONS : S_KUNNR FOR ZCUSTOMERS-KUNNR OBLIGATORY,

S_VBELN FOR ZSOHEADERS-VBELN.

PARAMETERS : C_MESTYP LIKE EDIDC-MESTYP DEFAULT 'ZRZSO_MT',

"Message Type

C_RCVPRT LIKE EDIDC-RCVPRT DEFAULT 'LS',

"Partner type of receiver

C_LOGSYS LIKE EDIDC-RCVPRN DEFAULT 'Y901',

C_RCVPOR LIKE EDIDC-RCVPOR DEFAULT 'A000000226',

C_SNDPRN LIKE EDIDC-SNDPRN DEFAULT 'LSSENDS',

C_SNDPRT LIKE EDIDC-SNDPRT DEFAULT 'LS'.

"Destination System

***START-OF-SELECTION

START-OF-SELECTION.

PERFORM GENERATE_DATA_RECORDS.

PERFORM GENERATE_CONTROL_RECORD.PERFORM SEND_IDOC.

***********************************************************************

&--------------------------------------------------------------------- 

*& Form generate_data_records

&--------------------------------------------------------------------- 

FORM GENERATE_DATA_RECORDS .

PERFORM FETCH_ZCUSTOMERS.

PERFORM FETCH_ZSOHEADERS.

PERFORM FETCH_ZSOITEMS.

PERFORM ARRANGE_DATA_RECORDS.

ENDFORM. " generate_data_records

&--------------------------------------------------------------------- 

*& Form fetch_zcustomers

&--------------------------------------------------------------------- 

FORM FETCH_ZCUSTOMERS.

SELECT *

FROM ZCUSTOMERS

INTO TABLE T_ZCUSTOMERS

WHERE KUNNR IN S_KUNNR.

IF SY-SUBRC NE 0.

MESSAGE E398(00) WITH 'No Customers Found'.

ENDIF.

ENDFORM. " fetch_zcustomers

&--------------------------------------------------------------------- 

*& Form fetch_zsoheaders&--------------------------------------------------------------------- 

FORM FETCH_ZSOHEADERS.

SELECT *

FROM ZSOHEADERS

INTO TABLE T_ZSOHEADERS

WHERE VBELN IN S_VBELN

AND KUNNR IN S_KUNNR.

IF SY-SUBRC NE 0.

MESSAGE I398(00) WITH 'No Sales orders found'.

ENDIF.

ENDFORM. " fetch_zsoheaders

&--------------------------------------------------------------------- 

*& Form fetch_zsoitems

&--------------------------------------------------------------------- 

FORM FETCH_ZSOITEMS.

IF NOT T_ZSOHEADERS[] IS INITIAL.

SELECT *

FROM ZSOITEMS

INTO TABLE T_ZSOITEMS

Page 3 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS

8-11-2011http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Page 4: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 4/8

FOR ALL ENTRIES IN T_ZSOHEADERS

WHERE VBELN = T_ZSOHEADERS-VBELN.

IF SY-SUBRC NE 0.

MESSAGE I398(00) WITH 'No Sales order items found'.

ENDIF.

ENDIF.

ENDFORM. " fetch_zsoitems

&--------------------------------------------------------------------- 

*& Form generate_control_record

&--------------------------------------------------------------------- 

FORM GENERATE_CONTROL_RECORD .

S_CTRL_REC-RCVPOR = C_RCVPOR. "Receiver Port

S_CTRL_REC-MESTYP = C_MESTYP. "Message type

S_CTRL_REC-IDOCTP = C_IDOCTP. "Basic IDOC type

S_CTRL_REC-RCVPRT = C_RCVPRT. "Partner type of receiver

S_CTRL_REC-RCVPRN = C_LOGSYS. "Partner number of receiver

S_CTRL_REC-SNDPRT = C_SNDPRT. "Sender Partner type

S_CTRL_REC-SNDPRN = C_SNDPRN. "Sender Partner Number

ENDFORM. " generate_control_record

&--------------------------------------------------------------------- 

*& Form send_idoc

&--------------------------------------------------------------------- FORM SEND_IDOC.

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

MASTER_IDOC_CONTROL = S_CTRL_REC

TABLES

COMMUNICATION_IDOC_CONTROL = T_COMM_IDOC

MASTER_IDOC_DATA = T_EDIDD

EXCEPTIONS

ERROR_IN_IDOC_CONTROL = 1

ERROR_WRITING_IDOC_STATUS = 2

ERROR_IN_IDOC_DATA = 3

SENDING_LOGICAL_SYSTEM_UNKNOWN = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

COMMIT WORK.

LOOP AT T_COMM_IDOC.

WRITE:/ 'IDoc Generated - ', T_COMM_IDOC-DOCNUM.

ENDLOOP.

ENDIF.

ENDFORM. " send_idoc

&--------------------------------------------------------------------- 

*& Form arrange_data_records

&--------------------------------------------------------------------- 

FORM ARRANGE_DATA_RECORDS .

DATA: W_INDEX1 LIKE SY-TABIX,

W_INDEX2 LIKE SY-TABIX.

SORT T_ZCUSTOMERS BY KUNNR.

SORT T_ZSOHEADERS BY KUNNR VBELN.

SORT T_ZSOITEMS BY VBELN POSNR.

LOOP AT T_ZCUSTOMERS.

S_ZRZSEG1-KUNNR = T_ZCUSTOMERS-KUNNR.

S_ZRZSEG1-NAME1 = T_ZCUSTOMERS-NAME1.

S_ZRZSEG1-ORT01 = T_ZCUSTOMERS-ORT01.

S_ZRZSEG1-LAND1 = T_ZCUSTOMERS-LAND1.

T_EDIDD-SEGNAM = C_ZRZSEG1.

T_EDIDD-SDATA = S_ZRZSEG1.

APPEND T_EDIDD.

CLEAR T_EDIDD.

CLEAR W_INDEX1.

READ TABLE T_ZSOHEADERS WITH KEY KUNNR = T_ZCUSTOMERS-KUNNR BINARY SEARCH.

IF SY-SUBRC = 0.

W_INDEX1 = SY-TABIX.

LOOP AT T_ZSOHEADERS FROM W_INDEX1.

IF T_ZSOHEADERS-KUNNR NE T_ZCUSTOMERS-KUNNR.EXIT.

ENDIF.

S_ZRZSEG2-VBELN = T_ZSOHEADERS-VBELN.

S_ZRZSEG2-KUNNR = T_ZSOHEADERS-KUNNR.

Page 4 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS

8-11-2011http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Page 5: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 5/8

T_EDIDD-SEGNAM = C_ZRZSEG2.

T_EDIDD-SDATA = S_ZRZSEG2.

APPEND T_EDIDD.

CLEAR T_EDIDD.

CLEAR W_INDEX2.

READ TABLE T_ZSOITEMS WITH KEY VBELN = T_ZSOHEADERS-VBELN BINARY SEARCH.

IF SY-SUBRC = 0.

W_INDEX2 = SY-TABIX.

LOOP AT T_ZSOITEMS FROM SY-TABIX.

IF T_ZSOITEMS-VBELN NE T_ZSOHEADERS-VBELN.

EXIT.

ENDIF.

S_ZRZSEG3-VBELN = T_ZSOITEMS-VBELN.

S_ZRZSEG3-POSNR = T_ZSOITEMS-POSNR.

S_ZRZSEG3-MATNR = T_ZSOITEMS-MATNR.

S_ZRZSEG3-NETWR = T_ZSOITEMS-NETWR.

S_ZRZSEG3-ZMENG = T_ZSOITEMS-ZMENG.

T_EDIDD-SEGNAM = C_ZRZSEG3.

T_EDIDD-SDATA = S_ZRZSEG3.

APPEND T_EDIDD.

CLEAR T_EDIDD.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDFORM. " arrange_data_records

In the previous parts we learned how to create custom idoc and settings for sending outbound idoc from source system.In this part we will learn how to configure the receiving SAP R/3system to be able to receive and post the inbound IDoc.

Inbound IDoc Posting Function Module

In the receiving system, create a function module Z_IDOC_INPUT_ZRZSO_MT using SE37. Below, I have described the logic for the same.

Add Include MBDCONWF. This include contains predefined ALE constants.

Loop at EDIDC table

Check if the message type is ZRZORDER. Otherwise raise WRONG_FUNCTION_CALLED exception•

Loop at EDIDD table•

Append data from the segments to appropriate internal tables◦

For example: append data from ZRZSEG1 segment to the internal table of type ZCUSTOMERS◦

Update the DDic tables from internal tables•

Depending on the result of the update, fill the IDoc status record (type BDIDOCSTAT) and append it to the corresponding table.•

Status 53 => Success◦

Status 51 => Error◦

Code for function module Z_IDOC_INPUT_ZRZSO_MT . FUNCTION Z_IDOC_INPUT_ZRZSO_MT.

*"----------------------------------------------------------------------

""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

*" 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

*"----------------------------------------------------------------------

Include File containing ALE constants

INCLUDE MBDCONWF.

TABLES : ZCUSTOMERS, "Cutomer Header

ZSOHEADERS, "Sales Header

ZSOITEMS. "Sales Items

***Data

DATA : W_ZRZSEG1 LIKE ZRZSEG1,

W_ZRZSEG2 LIKE ZRZSEG2,

W_ZRZSEG3 LIKE ZRZSEG3.

DATA : T_ZCUSTOMERS LIKE ZCUSTOMERS OCCURS 0 WITH HEADER LINE.

DATA : T_ZSOHEADERS LIKE ZSOHEADERS OCCURS 0 WITH HEADER LINE.

DATA : T_ZSOITEMS LIKE ZSOITEMS OCCURS 0 WITH HEADER LINE.

***********************************************************************

Page 5 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS

8-11-2011http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Page 6: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 6/8

WORKFLOW_RESULT = C_WF_RESULT_OK.

LOOP AT IDOC_CONTRL.

IF IDOC_CONTRL-MESTYP NE 'ZRZSO_MT'.

RAISE WRONG_FUNCTION_CALLED.

ENDIF.

* Before reading a new entry, clear application buffer

LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.

CASE IDOC_DATA-SEGNAM.

WHEN 'ZRZSEG1'.

W_ZRZSEG1 = IDOC_DATA-SDATA.

MOVE-CORRESPONDING W_ZRZSEG1 TO T_ZCUSTOMERS.

INSERT INTO ZCUSTOMERS VALUES T_ZCUSTOMERS.

WHEN 'ZRZSEG2'.

W_ZRZSEG2 = IDOC_DATA-SDATA.

MOVE-CORRESPONDING W_ZRZSEG2 TO T_ZSOHEADERS.

INSERT INTO ZSOHEADERS VALUES T_ZSOHEADERS.

WHEN 'ZRZSEG3'.

W_ZRZSEG3 = IDOC_DATA-SDATA.

MOVE-CORRESPONDING W_ZRZSEG3 TO T_ZSOITEMS.

INSERT INTO ZSOITEMS VALUES T_ZSOITEMS.

ENDCASE.

ENDLOOP.

************************************************************************

CUSTOMER HEADER *

************************************************************************

* SELECT ** FROM zcustomers.

* ENDSELECT.

* IF sy-subrc NE 0.

* INSERT INTO zcustomers VALUES t_zcustomers.

* ELSE.

UPDATE ZCUSTHEAD FROM T_ZCUSTOMERS.

* ENDIF.

IF SY-SUBRC EQ 0.

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '53'.

IDOC_STATUS-MSGTY = 'I'.

IDOC_STATUS-MSGID = 'YM'.

IDOC_STATUS-MSGNO = '004'.

IDOC_STATUS-MSGV1 = T_ZCUSTOMERS-KUNNR.

APPEND IDOC_STATUS.

CLEAR IDOC_STATUS.

ELSE.

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '51'.

IDOC_STATUS-MSGTY = 'E'.

IDOC_STATUS-MSGID = 'YM'.

IDOC_STATUS-MSGNO = '005'.

IDOC_STATUS-MSGV1 = T_ZCUSTOMERS-KUNNR.

APPEND IDOC_STATUS.

CLEAR IDOC_STATUS.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.

RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

APPEND RETURN_VARIABLES.

CLEAR RETURN_VARIABLES.

ENDIF.

************************************************************************

SALES HEADER *

************************************************************************

* SELECT *

* FROM zsoheaders.

* ENDSELECT.

* IF sy-subrc NE 0.

* INSERT INTO zsoheaders VALUES t_zsoheaders.

* ELSE.

UPDATE ZSOHEADERS FROM T_ZSOHEADERS.

* ENDIF.

IF SY-SUBRC EQ 0.

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '53'.

IDOC_STATUS-MSGTY = 'I'.

IDOC_STATUS-MSGID = 'YM'.

IDOC_STATUS-MSGNO = '004'.

IDOC_STATUS-MSGV1 = T_ZSOHEADERS-VBELN.

APPEND IDOC_STATUS.

CLEAR IDOC_STATUS.

ELSE.

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.IDOC_STATUS-STATUS = '51'.

IDOC_STATUS-MSGTY = 'E'.

IDOC_STATUS-MSGID = 'YM'.

IDOC_STATUS-MSGNO = '005'.

Page 6 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS

8-11-2011http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Page 7: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 7/8

IDOC_STATUS-MSGV1 = T_ZSOHEADERS-VBELN.

APPEND IDOC_STATUS.

CLEAR IDOC_STATUS.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.

RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

APPEND RETURN_VARIABLES.

CLEAR RETURN_VARIABLES.

ENDIF.

************************************************************************

SALES ITEM *

************************************************************************

* SELECT *

* FROM zsoitems.

* ENDSELECT.

* IF sy-subrc NE 0.

* INSERT INTO zsoitems VALUES t_zsoitems.

* ELSE.

UPDATE ZSOITEMS FROM T_ZSOITEMS.

* ENDIF.

IF SY-SUBRC EQ 0.

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '53'.

IDOC_STATUS-MSGTY = 'I'.

IDOC_STATUS-MSGID = 'YM'.

IDOC_STATUS-MSGNO = '004'.

IDOC_STATUS-MSGV1 = T_ZSOITEMS-VBELN.

APPEND IDOC_STATUS.

CLEAR IDOC_STATUS.ELSE.

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '51'.

IDOC_STATUS-MSGTY = 'E'.

IDOC_STATUS-MSGID = 'YM'.

IDOC_STATUS-MSGNO = '005'.

IDOC_STATUS-MSGV1 = T_ZSOITEMS-VBELN.

APPEND IDOC_STATUS.

CLEAR IDOC_STATUS.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.

RETURN_VARIABLES-WF_PARAM = 'Error_Idocs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

APPEND RETURN_VARIABLES.

CLEAR RETURN_VARIABLES.

ENDIF.

************************************************************************

ENDLOOP.

ENDFUNCTION.

Inbound Settings

Define Logical Systems - Transaction SALE•

Assign Client to Logical System - Transaction SALE•

Maintain RFC Destinations - Transaction SM59•

Define Ports - Transaction WE21•

Generate/Create Partner Profile - Transactions BD82/WE20•

Assign Function Module to Logical message - Transaction WE57•

Create a new entry◦

Specify name of the Function Module as Z_IDOC_INPUT_ZRZSO_MT◦

Also, specify Type as F, Basic IDoc type as ZRZORDER, Message type as ZRZSO_MT and Direction as 2 (Inbound)◦

Save the entry◦

Define Input method for Inbound Function Module - Transaction BD51•

Create a new entry◦

Provide Function Module name as Z_IDOC_INPUT_ZRZSO_MT◦

Specify the Input method as 2◦

Save the entry◦

Create a Process Code - Transaction WE42•

Create a new Process Code ZPCRZ◦

Select Processing with ALE Service◦

Choose Processing type as Processing by function module◦

Save the entry◦

On the next screen, select your function module from the list◦

Save the changes◦

Now you will be taken to the next screen◦

Double-click on Logical message◦

In the Assignment to logical message, specify the message type ZRZSO_MT◦

Save the changes◦

Send and receive data

On the sender system, execute the IDoc Generation Program. Check the status of IDoc using transaction WE02.

Check the status of the IDoc in the receiver system using transaction WE02. You can also check the contents of DDic tables to make sure that the records have been created in the receiver system.

Page 7 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS

8-11-2011http://wiki.sdn.sap.com/wiki/display/ABAP/ALE+IDOCS

Page 8: ale&idocs

7/29/2019 ale&idocs

http://slidepdf.com/reader/full/aleidocs 8/8

Thus to summarize we have learned how to:

Create a custom idoc•

Write an outbound idoc generation program.•

Write Inbound Function Module to post Inbound IDoc•

Configure and test ALE scenario to transmit data between systems distributed across the network•

Labels

Comments (3)

Contact Us   Site Index   Marketing Opportunities   Legal Terms   Privacy   Impressum  

Powered by SAP NetWeaver  

interfaces  ale  idocs 

Page 8 of 8SAP Community Network Wiki - ABAP Development - ALE IDOCS