Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

i need a sample code regarding to create a custom IDOC...

Former Member
0 Kudos

Hi All,

can u help me in where can i find the sample code to create a new custom idoc, and the processing code to process it.. if any have the procedure to create the idoc...thanx in advance

3 REPLIES 3

BalaMalvatu
Participant
0 Kudos

Hi,

FUNCTION ZMM_EXIT_SAPLEINM_001.

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

*"*"Local interface:

*"  IMPORTING

*"     VALUE(IT_CEKKO) LIKE  EKKO STRUCTURE  EKKO

*"  TABLES

*"      IT_BEKPO STRUCTURE  UEKPO OPTIONAL

*"      IT_BEKET STRUCTURE  UEKET OPTIONAL

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

**--------------------------------------------------------------------**

**            DATA-DECLARATION  & INTERNAL TABLES

**--------------------------------------------------------------------**

DATA: i_menge1(10) TYPE n,

i_ebelp(15) TYPE c,

i_trim(2) VALUE '00',

c_qty(3) TYPE n.

DATA: it_docnum LIKE  edidc-docnum.

DATA: it_ekko LIKE ekko OCCURS 0 WITH HEADER LINE,

it_resb LIKE TABLE OF resb WITH HEADER LINE,

it_zpur_idoc LIKE zpur_idoc OCCURS 0 WITH HEADER LINE,

i_child LIKE zpordch01 OCCURS 0 WITH HEADER LINE,

g_child LIKE zpordch OCCURS 0 WITH HEADER LINE.

**--------------------------------------------

**  Start of data filling in segments

**--------------------------------------------

**--------------------------------------------

** Fill segment for Header data.

**--------------------------------------------

MOVE it_cekko-ebeln TO it_zpur_idoc-ebeln.         " Purchase Order

SHIFT it_zpur_idoc-ebeln LEFT DELETING LEADING '0'.

MOVE it_cekko-lifnr TO it_zpur_idoc-lifnr.         " Vendor

MOVE it_cekko-ekorg TO it_zpur_idoc-ekorg.         " Purchasing Org

MOVE it_cekko-bedat TO it_zpur_idoc-bedat.         "ConfirmedRelease

" date/ PO Date

APPEND it_zpur_idoc.

CLEAR  it_zpur_idoc.

**--------------------------------------------

** End of Filling segment form Header data.

**--------------------------------------------

**--------------------------------------------

** Fill segment form Item level data.

**--------------------------------------------

LOOP AT it_bekpo WHERE ebeln = it_cekko-ebeln.

MOVE it_bekpo-ebelp+2 TO g_child-ebelp.            " Item Number

MOVE it_bekpo-werks TO g_child-werks.              " Plant

MOVE it_bekpo-matnr TO g_child-matnr.              " Materials No.

MOVE it_bekpo-revlv TO g_child-revlv.              " Revision No.

i_menge1 = it_bekpo-menge.                         " Quantity

g_child-menge = i_menge1.

**---Function module to remove leading Zeros

CALL FUNCTION 'BKK_ACCNT_DELETE_LEADING_ZERO'

CHANGING

c_field = g_child-menge.

**---Function Module to get material description

CALL FUNCTION 'HAZMAT_MATNR_GET_TEXT'

EXPORTING

i_matnr         = g_child-matnr

IMPORTING

e_maktx         = g_child-maktx

EXCEPTIONS

no_record_found = 1

OTHERS          = 2.

READ TABLE it_beket WITH KEY ebeln = it_bekpo-ebeln

ebelp = it_bekpo-ebelp.

MOVE it_beket-eindt TO g_child-eindt.         " ExpectComplDate

APPEND g_child.

CLEAR  g_child.

**--------------------------------------------

** End of Filling segment form Item level data.

**--------------------------------------------

**--------------------------------------------

**  Fill the segments for child items.

**--------------------------------------------

SELECT * FROM resb

INTO TABLE it_resb

WHERE baugr = it_bekpo-matnr

AND   ebeln = it_bekpo-ebeln

AND   ebelp = it_bekpo-ebelp

AND   matnr LIKE 'G%'.

LOOP AT it_resb.

MOVE it_resb-matnr TO i_child-chmtnr.

*      c_qty = it_resb-esmng .

MOVE it_resb-esmng TO i_child-esmng .

i_child-esmng = i_child-esmng(6).

SHIFT i_child-esmng LEFT DELETING LEADING ' '.

**---Function Module to get material description

CALL FUNCTION 'HAZMAT_MATNR_GET_TEXT'

EXPORTING

i_matnr         = it_resb-matnr

IMPORTING

e_maktx         = i_child-cmtext

EXCEPTIONS

no_record_found = 1

OTHERS          = 2.

APPEND i_child.

CLEAR i_child.

ENDLOOP.

**--------------------------------------------

**  End of filling segments for child item

**--------------------------------------------

ENDLOOP.

**--------------------------------------------

**  End of data filling in segments

**--------------------------------------------

**--------------------------------------------

** Create and Send IDOC for segment data

**--------------------------------------------

READ TABLE it_zpur_idoc INDEX 1.

****Function Module to CREATE and SEND IDOC

CALL FUNCTION 'ZMM_CREATE_IDOC_ZPORDR'

EXPORTING

it_zpur_idoc        = it_zpur_idoc

IMPORTING

docnum              = it_docnum

TABLES

zpordch             = g_child

zpordch01           = i_child

EXCEPTIONS

error_creating_idoc = 1

OTHERS              = 2.

IF sy-subrc <> 0.

MESSAGE e001(391) WITH 'IDOC not send'.

ENDIF.

ENDFUNCTION.

FUNCTION zmm_create_idoc_zpordr.

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

*"*"Local interface:

*"  IMPORTING

*"     VALUE(IT_ZPUR_IDOC) LIKE  ZPUR_IDOC STRUCTURE  ZPUR_IDOC

*"  EXPORTING

*"     REFERENCE(DOCNUM) LIKE  EDIDC-DOCNUM

*"  TABLES

*"      ZPORDCH STRUCTURE  ZPORDCH

*"      ZPORDCH01 STRUCTURE  ZPORDCH01

*"  EXCEPTIONS

*"      ERROR_CREATING_IDOC

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

DATA: BEGIN OF F_IDOC_HEADER.

INCLUDE STRUCTURE edidc.

DATA: END OF F_IDOC_HEADER.

DATA: BEGIN OF T_IDOC_COMM_CONTROL OCCURS 0.

INCLUDE STRUCTURE edidc.

DATA: END OF T_IDOC_COMM_CONTROL.

DATA: BEGIN OF t_idoc_data OCCURS 1.

INCLUDE STRUCTURE edidd.

DATA: END OF t_idoc_data.

DATA: it_zpord LIKE zpord.

CLEAR t_idoc_data.

REFRESH t_idoc_data.

MOVE-CORRESPONDING it_zpur_idoc to it_ZPORD.

t_idoc_data-segnam  = 'ZPORD'.

t_idoc_data-sdata  = it_zpord.

APPEND t_idoc_data.

CLEAR  t_idoc_data.

LOOP AT ZPORDCH.

t_idoc_data-segnam  = 'ZPORDCH'.

t_idoc_data-sdata  = ZPORDCH.

APPEND t_idoc_data.

CLEAR  t_idoc_data.

ENDLOOP.

LOOP AT ZPORDCH01.

t_idoc_data-segnam  = 'ZPORDCH01'.

t_idoc_data-sdata  = ZPORDCH01.

APPEND t_idoc_data.

CLEAR  t_idoc_data.

ENDLOOP.

*---Control Data .

*---fill IDOC Header

**  MOVE space TO aledc.

F_IDOC_HEADER-MESTYP = 'ZPORDR'.

F_IDOC_HEADER-IDOCTP = 'ZPORDR01'.

F_IDOC_HEADER-SNDPRN = 'WW_DEV_200'.

F_IDOC_HEADER-SNDPRT = 'LS'.

F_IDOC_HEADER-RCVPRN = 'BCPODEV'.

F_IDOC_HEADER-RCVPRT = 'LS'.

F_IDOC_HEADER-OUTMOD = '2'.

*--Function Module to Distribute IDOC

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' "IN UPDATE TASK

EXPORTING

master_idoc_control            = F_IDOC_HEADER

TABLES

communication_idoc_control     = T_IDOC_COMM_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.

IF sy-subrc <> 0.

ROLLBACK WORK.

ENDIF.

*  ELSE.

*    COMMIT WORK. "AND WAIT.

READ TABLE T_IDOC_COMM_CONTROL INDEX 1.

IF sy-subrc = 0.

docnum = T_IDOC_COMM_CONTROL-docnum.

ENDIF.

*  ENDIF.

ENDFUNCTION.

Regards

Bala.M

Former Member
0 Kudos

Hi,

steps

1>WE81(create z mesagetype)

2>WE31(Create Z segment)

3>WE30(Create zbasictype)

4>se37(create ur own function module)

5>WE57(attach ur function module to ur message and basictype)

6>BD51(Attch ur z function module)

7>WE42(Create ur own process code)

8>WE20(Partner profiles)

Regards,

Satish

Former Member
0 Kudos

Hi,

Outbound Interface

PROCESS DIAGRAM for Outbound Interface

1. Analyse Hierarchy Levels

2. Create New segment

3. Create New IDoc Type

4. Create New Message Type

5. Link Message with IDoc Type

6. Create an entry in EDP13 via transactions WE20 and BD64

7. Populate the Custom IDoc via ABAP Program

7b Error Handling

7c. Send Status Email

8. Test the Population of the Custom IDoc

Step 1 – Analyse Hierarchy Levels:

Analyse the data relationships being processed in the interface. Define the appropriate hierarchical Parent-to-Child relationships.

Navigate to transaction code WEDI

Transaction WEDI displays the IDOC main menu. This allows navigation around the various development and control areas to create a customised IDOC.

Step 2 – Create a new segment:

via wedi : Development - IDOC Segments or Transaction code WE31.

• Enter segment name and click on Create.

? The name of the segment type must start with Z1 , and have a maximum of eight characters.

• Enter description and enter the relevant field names and data elements.

? The segment should represent a structure in the program so for each field in the segment a field name and a data element must be defined.

• Save the segment and enter Person Responsible and Processing Person .

• Go to Edit and Set Release.

• Repeat this procedure for each new Segment in the IDOC.

Step 3 – Create a new IDOC Type

via wedi Development - IDOC Types or Transaction WE30.

• Enter segment name (starting with Z), click on Basic Type and then Create.

• Create as new, enter Person Responsible and Processing Person and enter description.

• On ‘Create Basic Type’ screen decide where segments should be inserted and go to Edit/Create Segment.

• Complete relevant fields in the Maintain Attributes screen:

• From the relevant segments created in Step 2 enter the Segment type and if mandatory segment.

• The Minimum and Maximum number of segments to be allowed in the sequence. (One minimum and one maximum if segment is mandatory).

• The Parent Segment and Hierarchy Level will be automatically created depending on where in the IDOC tree you decided to create that particular segment.

• Repeat this process for each segment needed in the IDOC type, deciding whether to add the next segments at the same level or as a ‘Child’.

• When IDOC created return to initial screen. Go to Edit and Set Release.

• Go to Transaction WE60 to view the IDoc Type you have created.

Step 4 – Create new Message Type

via wedi Development - Message Types or Transaction WE81.

• Display/Change and click on New Entries

• Create a new Message Type and Save.

Step 5 – Link Message Type to IDOC Type

via wedi Development - IDOC Type/Message or Transaction WE82.

• Display/Change and then click on New Entries.

• Enter Message Type, Basic Type (IDOC Type) and Release (46C) and Save.

Step 6 – Create an entry in EDP13 via transactions WE20 and BD64.

The partner profile for the Idoc must be set up and generated in the transaction BD64 and transaction WE20.

• WE20 – Add Message Type to appropriate Partner Type, Enter Message Type, Receiver Port and Idoc Type and Save.

• BD64 – Create a Model View, Enter Sender and Receiver Ports, Attach Message Type. Go to ‘Environment’ on Menu and click on Generate Partner Profiles and generate (not save) profile.

Step 7 – Populate the custom IDOC via ABAP Program

See Test Program ZOUTBD_IDOC_TEMPLATE, Appendix IV.

• Create an Internal Table for each segment type, this should be exactly the same structure as the segment type.

• The control record is filled into a structure like EDIDC. The message type and the Idoc type for the Idoc must be populated into the eddic structure.

- PERFORM populate_Control_structure USING c_mestyp

c_SEGMENT_type1.

• The data segments are filled into a structure like edidd-sdata; sdata and the segment name are populated into the edidd structure.

- PERFORM transfer_Parent_data_to_seg.

• The standard SAP function module MASTER_IDOC_DISTRIBUTE is called to pass the populated IDOC to the ALE Layer.

- PERFORM master_idoc_distribute.

• NOTE: This function module is only called for stand alone programs and Shared Master Data programs (SMD). It is not called when using extensions or output determination.

• The ALE Layer handles the sending of the IDOC to the receiving system.

• Error Handling (see Step 7b).

• Commit work.

Project Specific

Step 7b – Error Handling• Analyse which fields in the interface are mandatory for the receiving system and who needs to receive error notification.

• Declare a structure of type ‘MCMAILOBJ’ for sending instructions.

• Enter values for the internal table based on structure ‘MCMAILOBJ’

• For selection processes, on SY-SUBRC checks and where fields are mandatory for the receiving system; insert Function Module ‘MC_SEND_MAIL’.

• Enter values in the following parameters: -

MS_MAIL_SENDMODE = ‘B’ (Batch Mode)

MS_MAIL_TITLE = 'Mail Title'

MS_MAIL_DESCRIPTION = ‘Error description’ (e.g. MATNR not given)

MS_MAIL_RECEIVER = ‘Name of Receiver’ (To be determined)

MS_MAIL_EXPRESS = ‘E’ (Express Delivery)

MS_MAIL_DLINAME = Leave Blank

MS_MAIL_LANGU = 'E' (Language)

MS_MAIL_FUNKOBJ_NAME = Leave Blank

TABLES

MS_MAIL_CONT = I_MCMAILOBJ

Note:

It has to be determined separately for each interface how these errors and mail notifications are to be grouped – dependant upon the number of errors that are potentially likely. One possible approach is to send an email for each reason for rejection and include all the records that failed for that reason in the mail notification. Another possible approach is to send an email for every failure.

When error checking for mandatory fields it is common SAP practice to reject a record on its first failure (irrespective of subsequent errors in that record)

Step 7c – Send status mail

• Append to table I_MCMAILOBJ details of the time the interface was processed, how many Idocs were created and how many of these produced a status of 03.

• Select the user to receive the mail from ZINT_RECEIVER, using the name of the program as a key (SY-CPROG).

• Use function Module ‘MC_SEND_MAIL’ to send a mail to the user containing the contents of I_MCMAILOBJ at the end of the interface processing.

Step 8 – Test the population of the custom IDOC

via wedi IDoc - Display IDoc or Transaction WE02.

• Enter your message type and execute.

• Status should be green, double click on one of the Idocs you have created to view its contents.

• If a problem has occurred click on Status which will give you a description of the error.

• Drop down Data Records arrow and this should list the data in the IDoc in the correct hierarchical structure.

• Click on each individual segment and view the content to check that the correct data has been read.

• If you have UNIX access by using AL11 you can view the file that you have created.

Note:

For some interfaces it may be valid to send an empty file to SAP. This empty file is converted to the custom IDOC format expected by SAP. This custom IDOC will contain dummy information. In the inbound processing code, if the dummy information is identified then the processing of the IDOC is considered to be complete and the IDOC should then be assigned a successfully processed status of 53, even though it has not been processed at all.

Reward If helpfull.

Regards Madhu.