*//初探
*//IDOC 的创建
*//IDOC 的创建
*//IDOC 的创建
DATA: g_idoc_ctl LIKE edidc,
g_e1maram LIKE e1maram,
g_e1maktm LIKE e1maktm.
DATA: gi_ret_ctl LIKE edidc OCCURS 0,
gi_idoc_data LIKE edidd OCCURS 0 WITH HEADER LINE.
* BUILD IDOC_CTL RECORD
PERFORM build_idoc_ctl.
* BUILD ICOC_SEGMENT DATA
PERFORM build_idoc_seg.
* CALL FUNCTION AND CREATE IDOC
PERFORM create_idoc.
*&---------------------------------------------------*
*& form BUILD_IDOC_CTL
*&--------------------------------------------------*
FORM build_idoc_ctl.
* TYPE
g_idoc_ctl-idoctp = 'ZMMIDOC'. "IDOC TYPE
g_idoc_ctl-mestyp = 'ZMMCRT'. "MESSAGE TYPE
* RECEIVER
g_idoc_ctl-rcvprt = 'LS'. "PARTNER TYPE
g_idoc_ctl-rcvprn = 'MMRECV800'. "PARTNER NO
* SENDER
g_idoc_ctl-sndprt = 'LS'. "PARTNER TYPE
g_idoc_ctl-sndprn = 'T90CLNT090'. "PARTNER NO
g_idoc_ctl-sndpor = 'SAPC11'. "PORT
ENDFORM. " BUILD_IDOC_CTL
*&---------------------------------------------------*
*& form BUILD_IDOC_SEG
*&---------------------------------------------------*
FORM build_idoc_seg.
* HEAD DATA
gi_idoc_data-segnam = 'E1MARAM'. "SEGMENT NAME
gi_idoc_data-segnum = 1. "SEGMENT NO
g_e1maram-matnr = 'IDOCTEST15'. "MM NO
g_e1maram-meins = '10'. "BASE UOM
g_e1maram-mbrsh = 'M'. "INDUSTRY
g_e1maram-mtart = 'DIEN'. "MM TYPE
MOVE g_e1maram TO gi_idoc_data-sdata.
APPEND gi_idoc_data.
* DESCRIPTION
gi_idoc_data-segnam = 'E1MAKTM'. "SEGMENT NAME
gi_idoc_data-segnum = 2. "SEGMENT NO
g_e1maktm-spras = sy-langu. "LANGUAGE
g_e1maktm-maktx = 'IDOC TEST'. "DESCRIPTION
MOVE g_e1maktm TO gi_idoc_data-sdata.
APPEND gi_idoc_data.
ENDFORM. " BUILD_IDOC_SEG
*&---------------------------------------------------*
*& form CREATE_IDOC
*&---------------------------------------------------*
FORM create_idoc.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = g_idoc_ctl
TABLES
communication_idoc_control = gi_ret_ctl
master_idoc_data = gi_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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
COMMIT WORK.
ENDIF.
ENDFORM. " CREATE_IDOC