Aug 12, 2015

An example code of using Function Module MASTER_IDOC_DISTRIBUTE

DATA:
Z_SEGNAME(7) TYPE C VALUE 'SEGMENT',
Z_MESTYPE(9) TYPE C VALUE 'MESSAGE',
Z_IDOC_TYPE(8) TYPE C VALUE 'IDOC'.


DATA:
IDOC_CONTROL LIKE EDIDC,
T_COMM_CONTROL LIKE EDIDC OCCURS 0 WITH HEADER LINE,
IDOC_DATA LIKE EDIDD OCCURS 0 WITH HEADER LINE.

*Reads data from Z table
SELECT *
FROM ZTABLE
INTO TABLE L_ZTABLE.

*Set the control data info required for the distribution
IDOC_CONTROL-MESTYP = Z_MESTYPE.
IDOC_CONTROL-DOCTYP = Z_IDOC_TYPE.


*Populate the IDoc
LOOP AT L_ZTABLE.
  CLEAR IDOC_DATA.
  IDOC_DATA-SEGNAM = Z_SEGNAME.
  IDOC_DATA-SDATA = ZTABLE. 
  APPEND IDOC_DATA.
ENDLOOP.


*Deliver the IDOC as defined in distribution model/partner profile
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' IN UPDATE TASK
  EXPORTING
    MASTER_IDOC_CONTROL = IDOC_CONTROL
  TABLES
    COMMUNICATION_IDOC_CONTROL = T_COMM_CONTROL  
    MASTER_IDOC_DATA = 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.
COMMIT WORK.
ENDIF.

No comments :