Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
sujeet2918
Active Contributor
16,224

This document illustrates how we can create our own Idoc from scratch, and an ABAP program is used to generate the Idoc and one Function module created for inbound process. The program adds the user name, the current date and time, and sends the information to the receiving system.  The receiving system processes the data and posts it to the database.  It also sets the appropriate status of the IDoc, which then can be checked in the IDoc List (WE05).

In order to achieve our task, the following steps are necessary:

1. Create data container (Idoc)

2. Create database table

3. Create outbound program

4. Create inbound function

5. Set up ALE customizing

6. Send data

Step 1: Creating a new IDoc

  • Create new segments

To create a new segment: Go to Transaction code WE30 and follow the steps shown in below screen shot.

Create the Segment with field ZIMATNR, ZMTART, SENDER, ZDATE, ZTIME.

After entering the segment fields, save and activate your segment.

  • Create new IDoc type

The IDoc type describes the technical structure of a message. It defines which segments will be used, and what is the hierarchical structure of the segments.  For each segment, it also specifies whether it's mandatory or optional, and how many times the segment may appear in the IDoc.

To Create IDoc Type Use Transaction WE30.

Add Segment Type to IDoc Basic type.

  • Create new message type

The message type describes the contents of the message.  It helps the system to decide how to process the message. To create a new message type use transaction code WE30.

  • Link message type with IDoc type:

Go to transaction Code WE82 and create new entry. And Link Message type with created IDoc type.

Step 2: Create a new database table

Go to the ABAP/4 Dictionary Initial screen (SE11), and create a new table. The table should mirror the structure of the segment created above.

Step 3: Create a program for outbound processing

Fill data into Idoc and pass IDoc to ALE layer.  Close LUW (commit work).  The IDoc consists of a control record and one or more data records (segments).  The data segments contain the data of the message.  They are passed to ALE as an internal table (structure EDIDD).  The control record contains general information about the IDoc (structure EDIDC).  Function MASTER_IDOC_DISTRIBUTE is called to pass the IDoc to ALE.  For further details, see the code below.

*&---------------------------------------------------------------------*
*& Report  ZALEIDOC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zaleidoc.

TABLES: z1segtyp. 
"IDoc segment

PARAMETERS: z1matnr
LIKE z1segtyp-z1matnr OBLIGATORY,
zmtart 
LIKE z1segtyp-zmtart OBLIGATORY.

DATA:
BEGIN OF f_idoc_header.
INCLUDE STRUCTURE edidc.
DATA:
END OF f_idoc_header.

DATA:
BEGIN OF t_idoc_data OCCURS 0.
INCLUDE STRUCTURE edidd.
DATA:
END OF t_idoc_data.

DATA:
BEGIN OF t_comm_idoc_control OCCURS 0.
INCLUDE STRUCTURE edidc.
DATA:
END OF t_comm_idoc_control.

CLEAR t_idoc_data.
REFRESH t_idoc_data.
CLEAR f_idoc_header.

* move parameters into field string
z1segtyp-z1matnr = z1matnr.
z1segtyp-zmtart  = zmtart.

* add data to field string
z1segtyp-sender = sy-uname.
z1segtyp-zdate  = sy-datum.
z1segtyp-ztime  = sy-uzeit.

* field string to IDoc-data
t_idoc_data-sdata = z1segtyp.

* segment name
t_idoc_data-segnam =
'Z1SEGTYP'.

* append data
APPEND t_idoc_data.

* fill IDoc header
f_idoc_header-mestyp =
'ZMESGTYP'.
f_idoc_header-idoctp =
'ZALECON'.

* send IDoc
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control            = f_idoc_header
TABLES
communication_idoc_control     = t_comm_idoc_control
master_idoc_data               = t_idoc_data
EXCEPTIONS
error_in_idoc_control          =
1
error_writing_idoc_status      =
2
error_in_idoc_data             =
3
sending_logical_system_unknown =
4
OTHERS                         = 5.

* check results
IF sy-subrc = 0.
WRITE:/
'IDoc created.'.
ELSE.
WRITE:/
'Error',sy-subrc,'in MASTER_IDOC_DISTRIBUTE'.
ENDIF.

* close LUW
COMMIT WORK.

Step 4: Inbound processing

Create a function module for the inbound processing.  Check that the IDoc contains the correct message type. Convert the character data to internal format, if necessary.  If the data is OK, post it to the database table.  Otherwise, return an error message to ALE.

FUNCTION Z_IDOC_INPUT_ZALEIDOC.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT_METHOD) TYPE  INPUTMETHD
*"     REFERENCE(MASS_PROCESSING) TYPE  MASS_PROC
*"  EXPORTING
*"     REFERENCE(WORKFLOW_RESULT) TYPE  RESULT
*"     REFERENCE(APPLICATION_VARIABLE) TYPE  APPL_VAR
*"     REFERENCE(IN_UPDATE_TASK) TYPE  UPDATETASK
*"     REFERENCE(CALL_TRANSACTION_DONE) TYPE  CALLTRANS2
*"  TABLES
*"      IDOC_CONTRL STRUCTURE  EDIDC
*"      IDOC_DATA STRUCTURE  EDIDD
*"      IDOC_STATUS STRUCTURE  BDIDOCSTAT
*"      RETURN_VARIABLES STRUCTURE  BDWFRETVAR
*"      SERIALIZATION_INFO STRUCTURE  BDI_SER
*"  EXCEPTIONS
*"      FAILED_FUNCTION_CALL
*"----------------------------------------------------------------------
* IDoc inbound processing for ALE2

* database tables
TABLES: ZALETAB.

* field string for segment data
DATA: F_Z1SEGTYP
LIKE Z1SEGTYP.

* read IDoc control record
LOOP AT IDOC_CONTRL.

* check correct IDoc type
IF IDOC_CONTRL-IDOCTP <> 'ZALECON'.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.

* clear segment field string
CLEAR F_Z1SEGTYP.

* read segments of the IDoc
LOOP AT IDOC_DATA WHERE DOCNUM = IDOC_CONTRL-DOCNUM.

* move segment data into field string
F_Z1SEGTYP = IDOC_DATA-SDATA.

* common 3 statements for error or success
CLEAR IDOC_STATUS.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

* check error
IF F_Z1SEGTYP-zmtart IS INITIAL.  "error
IDOC_STATUS-STATUS =
'51'.
IDOC_STATUS-MSGTY =
'E'.
IDOC_STATUS-MSGID =
'ZA'.
IDOC_STATUS-MSGNO =
'001'.
IDOC_STATUS-UNAME = SY-UNAME.
IDOC_STATUS-REPID = SY-REPID.
WORKFLOW_RESULT =
99999.
RETURN_VARIABLES-WF_PARAM =
'Error_IDOCs'.
ELSE.      
"no error
* post data
MOVE-CORRESPONDING F_Z1SEGTYP TO ZALETAB.
MODIFY ZALETAB.
* write IDoc status OK
IDOC_STATUS-STATUS =
'53'.
RETURN_VARIABLES-WF_PARAM =
'Processed_IDOCs'.
WORKFLOW_RESULT =
0.
ENDIF.

* common 2 statements for error or success
APPEND IDOC_STATUS.
APPEND RETURN_VARIABLES.
ENDLOOP.     
"loop at idoc_data
ENDLOOP.       
"loop at idoc_contrl.

ENDFUNCTION.

a) Allocate API to Message Type WE57

      Now go to transaction code WE57 to allocate API to Message Type.

      Module                    name of your function

      Type                        'F' (function module)

BasicIDoc type        you created in step 1

      Message type            you created in step 1

      Direction                  '2' (inbound)

   b) Declare API Attributes BD51

Go to Transaction Code BD51 to declare the API attributes.

      And maintain Function module name, Input t. Dialog allowed as shown below:

   c) Maintain Inbound Process Code: WE42

Go to Transaction Code WE42 to maintain the Inbound Process Code.

Then Click on the Logical message and maintain message type as shown in below screen.

Step 5: Set up ALE customizing BD64

In the distribution model, you have to define which messages are distributed from one system to another.  The model directly controls the distribution.  ALE IMG->Distribution customer model->Maintain customer distribution model directly; Maintain message flow. We assume that the communication parameters, like partner profiles, ports, RFC destinations, have been set up by this time.  You can run a consistency check for your set up.

Step 6 : Send data

On the sending system, run the program created in Step 3. The data will be put into an IDoc and sent to the receiving system.  On the receiving system, use the IDoc overview (WE05) to check that your IDoc has arrived.  If it has been processed successfully, the database table created in Step 2 must contain the new record.

1 Comment
Labels in this area