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

need Code to generate Inbound Idocs

Former Member
0 Likes
966

Hi friends

i have a flat file consists of delivery confirmation data

by using this i need to generate inbound idocs

i filled all the segments in idoc type /afs/delvry03 and message type whscon

can any one have the code to generate inbound idocs

please remember that here i am not using XI

thanks

Anil

Hi friends

i have a flat file consists of delivery confirmation data

by using this i need to generate inbound idocs

i filled all the segments in idoc type /afs/delvry03 and message type whscon

can any one have the code to generate inbound idocs

please remember that here i am not using XI

thanks

Anil

6 REPLIES 6
Read only

Former Member
0 Likes
926

Hi this is for Stand alone Programs, I hope it is useful to you.

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.

Read only

0 Likes
926

This is example code only

Read only

0 Likes
926

Hi Krishna

Master_idoc_distribute works for outbound idocs and not for inbound idocs

Cheers

Anil

Read only

0 Likes
926

Sorry, Check this sample code

FUNCTION Z_IDOC_INPUT_ZMREPT.

*"----


""Local interface:

*" IMPORTING

*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD

*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC

*" EXPORTING

*" VALUE(WORKFLOW_RESULT) LIKE BDWFAP_PAR-RESULT

*" VALUE(APPLICATION_VARIABLE) LIKE BDWFAP_PAR-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 MBDCONWF.

*----


  • Database Tables

*----


  • Application data tables (Defined in global data)

*tables: zempdetail, zempwkdet.

*----


  • Data declarations

*----


  • employee details - IDoc

DATA: FS_EMPHDR_DATA LIKE Z1EMHDR.

  • employee weekly details data - IDoc

DATA: FS_WEEKDET_DATA LIKE Z1WKDET.

  • client details data - IDoc

DATA: FS_CLIENTDET_DATA LIKE Z1CLDET.

  • employee monthly summary data - IDoc

DATA: FS_SUMMARY_DATA LIKE Z1SUMRY.

  • total hours and amount

DATA: TOTAL_HRS_MONTH TYPE I,

TOTAL_AMT_MONTH TYPE I.

  • employee details - application data

DATA: FS_APP_EMPDET LIKE ZEMPDETAIL.

  • weekly details - appplication data

DATA: IT_APP_WKDET LIKE ZEMPWKDET OCCURS 0 WITH HEADER LINE.

*----


  • Program logic

*----


  • initialize workflow result

WORKFLOW_RESULT = C_WF_RESULT_OK.

LOOP AT IDOC_CONTRL.

  • make sure we have the correct message passed to us

IF IDOC_CONTRL-MESTYP NE 'ZMREPT'.

RAISE WRONG_FUNCTION_CALLED.

ENDIF.

  • clear application buffers before reading new employee

CLEAR: IT_APP_WKDET, FS_APP_EMPDET.

REFRESH IT_APP_WKDET.

  • process all data records in an IDoc and transfer them to

  • application buffers

LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.

CASE IDOC_DATA-SEGNAM.

WHEN 'Z1EMHDR'. " employee header

FS_EMPHDR_DATA = IDOC_DATA-SDATA.

MOVE-CORRESPONDING FS_EMPHDR_DATA TO FS_APP_EMPDET.

WHEN 'Z1WKDET'. " employee weekly details

FS_WEEKDET_DATA = IDOC_DATA-SDATA.

MOVE-CORRESPONDING FS_WEEKDET_DATA TO IT_APP_WKDET.

WHEN 'Z1CLDET'. " client details

FS_CLIENTDET_DATA = IDOC_DATA-SDATA.

MOVE-CORRESPONDING FS_CLIENTDET_DATA TO IT_APP_WKDET.

MOVE FS_APP_EMPDET-SSN TO IT_APP_WKDET-SSN.

APPEND IT_APP_WKDET. " append weekly details

WHEN 'Z1SUMRY'. " summary data

FS_SUMMARY_DATA = IDOC_DATA-SDATA.

ENDCASE.

ENDLOOP.

  • verify totals in the data records against the summary record

CLEAR: TOTAL_HRS_MONTH, TOTAL_AMT_MONTH.

  • compute total hours and amount for the month from weekly details

LOOP AT IT_APP_WKDET.

TOTAL_HRS_MONTH = TOTAL_HRS_MONTH + IT_APP_WKDET-TOTHOURS.

TOTAL_AMT_MONTH = TOTAL_AMT_MONTH + ( IT_APP_WKDET-TOTHOURS *

IT_APP_WKDET-HRLYRATE ).

ENDLOOP.

  • compare the values with values in the summary record

IF TOTAL_HRS_MONTH NE FS_SUMMARY_DATA-TOTHRS OR

TOTAL_AMT_MONTH NE FS_SUMMARY_DATA-TOTAMT.

  • totals in the summary record do not match with weekly details

  • fill IDOC_Status

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '51'.

IDOC_STATUS-MSGTY = 'E'.

IDOC_STATUS-MSGID = 'ZE'.

IDOC_STATUS-MSGNO = '005'.

IDOC_STATUS-MSGV1 = FS_APP_EMPDET-SSN.

APPEND IDOC_STATUS.

WORKFLOW_RESULT = C_WF_RESULT_ERROR.

RETURN_VARIABLES-WF_PARAM = 'Error_IDOCs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

APPEND RETURN_VARIABLES.

ELSE.

  • Data looks good. Create weekly report if it does not already exist

  • If wekly report exists then simply update the records

SELECT SINGLE * FROM ZEMPDETAIL WHERE SSN EQ FS_APP_EMPDET-SSN.

IF SY-SUBRC NE 0.

INSERT INTO ZEMPDETAIL VALUES FS_APP_EMPDET.

INSERT ZEMPWKDET FROM TABLE IT_APP_WKDET.

ELSE.

UPDATE ZEMPDETAIL FROM FS_APP_EMPDET.

UPDATE ZEMPWKDET FROM TABLE IT_APP_WKDET.

ENDIF.

IF SY-SUBRC EQ 0.

  • poulate return variables for success

RETURN_VARIABLES-WF_PARAM = 'Processed_IDOCs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

RETURN_VARIABLES-WF_PARAM = 'Appl_Objects'.

RETURN_VARIABLES-DOC_NUMBER = FS_APP_EMPDET-SSN.

APPEND RETURN_VARIABLES.

  • add status record indicating success

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '53'.

IDOC_STATUS-MSGTY = 'I'.

IDOC_STATUS-MSGID = 'ZE'.

IDOC_STATUS-MSGNO = '006'.

IDOC_STATUS-MSGV1 = FS_APP_EMPDET-SSN.

APPEND IDOC_STATUS.

ELSE.

  • poulate return variables indicating error

WORKFLOW_RESULT = C_WF_RESULT_ERROR.

RETURN_VARIABLES-WF_PARAM = 'Error_IDOCs'.

RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

APPEND RETURN_VARIABLES.

  • add status record indicating failure in updating

IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.

IDOC_STATUS-STATUS = '51'.

IDOC_STATUS-MSGTY = 'E'.

IDOC_STATUS-MSGID = 'ZE'.

IDOC_STATUS-MSGNO = '007'.

IDOC_STATUS-MSGV1 = FS_APP_EMPDET-SSN.

APPEND IDOC_STATUS.

ENDIF.

ENDIF.

ENDLOOP. "End loop at idoc_contrl.

ENDFUNCTION.

Read only

0 Likes
926

Hi

Dont we SAP standard Function modules for Inbound Idoc generation

like we have Master_idoc_distribute for outbound idocs

cheers

Anil

Read only

0 Likes
926

can any one tell me wat are the FM used for Inbound Idoc generations