Application Development and Automation 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: 
Read only

outbound IDOC with sample code...

Former Member
0 Likes
5,446

Hi,

What is the step-by-step procedure to create a outbound IDOC? Sample code and detailed explanation of each step will be very helpful as iam new to this topic.

Regards

Aravindh A S

2 REPLIES 2
Read only

Former Member
0 Likes
1,675

hi,

Follow this link.

http://www.saptechnical.com/Tutorials/ALE/ALEMainPage.htm

http://sap.niraj.tripod.com/id51.html

Hope this helps, Do reward.

Edited by: Runal Singh on Mar 10, 2008 1:11 PM

Read only

Former Member
0 Likes
1,675

Hi,

Floowing code used to create outbound Idoc sample code>....

Selection Screen

The selection screen in the stand-alone programs allows the user to specify the objects for which IDocs are to be generated. Although the selection screen has not been standardized because of varying needs of the application programs, the ALE programs for master distribution have some similarities. At a minimum they allow a user to select one or more objects, a receiving system, and the message to be generated. Refer to the selection screen for distributing the material master (Transaction BD10).

Program Flow

The program logic contains the following blocks:

1. Provide a selection screen to allow a user to specify the various objects for which IDocs are to be generated.

2. Determine the key of the application document from the object specified in step 1.

3. Select application data from the database using the object key identified in step 2.

4. Populate control record information.

5. Populate an internal table of type EDIDD with data records for the various segments.

6. Call the ALE service layer (MASTER_IDOC_DISTRIBUTE) to create the IDocs in the database.

7. Commit work.

The program in Listing 32-2 generates the monthly report IDoc ZMREPT01, which illustrates a stand-alone outbound process.

Listing 32-2

REPORT ZARNEDI1 MESSAGE-ID ZE.

*----


  • Parameters

*----


  • object key (Social security number for the employee)

PARAMETERS: P_SSN LIKE ZEMPDETAIL-SSN.

  • message type

PARAMETERS: P_MESTYP LIKE EDMSG-MSGTYP OBLIGATORY.

  • destination system

PARAMETERS: P_LOGSYS LIKE TBDLST-LOGSYS.

*----


  • Constants

*----


DATA:

  • segment names

C_HEADER_SEGMENT LIKE EDIDD-SEGNAM VALUE 'Z1EMHDR',

C_WEEKLY_DETAILS_SEGMENT LIKE EDIDD-SEGNAM VALUE 'Z1WKDET',

C_CLIENT_DETAILS_SEGMENT LIKE EDIDD-SEGNAM VALUE 'Z1CLDET',

C_SUMMARY_SEGMENT LIKE EDIDD-SEGNAM VALUE 'Z1SUMRY',

  • idoc type

C_MONTHLY_REPORT_IDOC_TYPE LIKE EDIDC-IDOCTP VALUE 'ZMREPT01'.

*----


  • Data declarations

*----


  • idoc control record

data: control_record_out like edidc.

  • employee header data

DATA: FS_EMPHDR_DATA LIKE Z1EMHDR.

  • employee weekly details data

DATA: FS_WEEKDET_DATA LIKE Z1WKDET.

  • client details data

DATA: FS_CLIENTDET_DATA LIKE Z1CLDET.

  • employee monthly summary data

DATA: FS_SUMMARY_DATA LIKE Z1SUMRY.

  • total hours and amount for the summary segment

DATA: TOTAL_HRS_MONTH TYPE I,

TOTAL_AMT_MONTH TYPE I.

*----


  • Database Tables

*----


  • Application data tables

TABLES: ZEMPDETAIL, ZEMPWKDET.

*----


  • Internal tables

*----


DATA:

  • weekly details - appplication data

IT_WKDET LIKE ZEMPWKDET OCCURS 0 WITH HEADER LINE,

  • data records

INT_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE,

  • communication idocs geneerated

IT_COMM_IDOCS LIKE EDIDC OCCURS 0 WITH HEADER LINE.

*----


  • Program logic

*----


********************Select Application Data***************************

SELECT SINGLE * FROM ZEMPDETAIL WHERE SSN = P_SSN.

IF SY-SUBRC NE 0.

MESSAGE E001 WITH P_SSN.

EXIT.

ENDIF.

SELECT * FROM ZEMPWKDET INTO TABLE IT_WKDET WHERE SSN = P_SSN.

IF SY-SUBRC NE 0.

MESSAGE E002 WITH P_SSN.

EXIT.

ENDIF.

********************Build Control Record******************************

  • Fill control record information

CONTROL_RECORD_OUT-MESTYP = P_MESTYP.

control_record_out-idoctp = c_monthly_report_idoc_type.

control_record_out-rcvprt = 'LS'.

control_record_out-rcvprn = p_logsys.

********************Build Data Records********************************

*--


Employee header--


  • fill the employee header information

FS_EMPHDR_DATA-LNAME = ZEMPDETAIL-LNAME.

FS_EMPHDR_DATA-FNAME = ZEMPDETAIL-FNAME.

FS_EMPHDR_DATA-SSN = ZEMPDETAIL-SSN.

FS_EMPHDR_DATA-DOB = ZEMPDETAIL-DOB.

  • fill the administrative section of the data record

INT_EDIDD-SEGNAM = C_HEADER_SEGMENT.

INT_EDIDD-SDATA = FS_EMPHDR_DATA.

  • append the employee header data record to the IDoc data

APPEND INT_EDIDD.

*--


Employee weekly details--


LOOP AT IT_WKDET.

  • fill the weekly details for each week

FS_WEEKDET_DATA-WEEKNO = IT_WKDET-WEEKNO.

FS_WEEKDET_DATA-TOTHOURS = IT_WKDET-TOTHOURS.

FS_WEEKDET_DATA-HRLYRATE = IT_WKDET-HRLYRATE.

  • add administrative information to the data record

INT_EDIDD-SEGNAM = C_WEEKLY_DETAILS_SEGMENT.

INT_EDIDD-SDATA = FS_WEEKDET_DATA.

  • append the data for the week to the IDoc data

APPEND INT_EDIDD.

  • Client details of each week

FS_CLIENTDET_DATA-CLSITE = IT_WKDET-CLSITE.

FS_CLIENTDET_DATA-WORKDESC = IT_WKDET-WORKDESC.

  • add administrative information to the data record

INT_EDIDD-SEGNAM = C_CLIENT_DETAILS_SEGMENT.

INT_EDIDD-SDATA = FS_CLIENTDET_DATA.

  • append the client details for the week to the IDoc data

APPEND INT_EDIDD.

ENDLOOP.

*--


Employee monthly summary--


  • compute total hours and amount for the month

LOOP AT IT_WKDET.

TOTAL_HRS_MONTH = TOTAL_HRS_MONTH + IT_WKDET-TOTHOURS.

TOTAL_AMT_MONTH = TOTAL_AMT_MONTH + ( IT_WKDET-TOTHOURS *

IT_WKDET-HRLYRATE ).

ENDLOOP.

  • fill the summary information

FS_SUMMARY_DATA-TOTHRS = TOTAL_HRS_MONTH.

FS_SUMMARY_DATA-TOTAMT = TOTAL_AMT_MONTH.

  • condense the summary record fields to remove spaces

CONDENSE FS_SUMMARY_DATA-TOTHRS.

CONDENSE FS_SUMMARY_DATA-TOTAMT.

  • add administrative information to the data record

INT_EDIDD-SEGNAM = C_SUMMARY_SEGMENT.

INT_EDIDD-SDATA = FS_SUMMARY_DATA.

  • append summary data to the IDoc data

APPEND INT_EDIDD.

*************Pass control to the ALE layer****************************

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

master_idoc_control = control_record_out

TABLES

COMMUNICATION_IDOC_CONTROL = IT_COMM_IDOCS

MASTER_IDOC_DATA = INT_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 NE 0.

MESSAGE E003 WITH P_SSN.

ELSE.

LOOP AT IT_COMM_IDOCS.

WRITE: / 'IDoc generated', IT_COMM_IDOCS-DOCNUM.

ENDLOOP.

COMMIT WORK.

ENDIF.

Thanks,

Krishna Rao, Reward if helpful