we31 – Создать сегмент
we30 – Создать базисный тип
we81 – Создать логический тип сообщений
we82 – Привязать логический тип сообщений к базисному типу
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
*&---------------------------------------------------------------------* *& Report ZIDOC *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zidoc. DATA: zsegname TYPE STRING VALUE 'ZCUST_SEG', zmestype TYPE STRING VALUE 'ZCUST_MSG', zidoctype TYPE STRING VALUE 'ZCUST_IDOC'. DATA: idoc_control LIKE edidc, comm_control LIKE edidc OCCURS 0 WITH HEADER LINE, idoc_data LIKE edidd OCCURS 0 WITH HEADER LINE. TYPES BEGIN OF itab. TYPES mandt TYPE sy-mandt. TYPES ebeln TYPE ekpo-ebeln. TYPES matnr TYPE ekpo-matnr. TYPES END OF itab. DATA table TYPE TABLE OF itab WITH HEADER LINE. DO 100 TIMES. table-mandt = sy-mandt. table-ebeln = '100000' && sy-index. table-matnr = '200000' && sy-index && 100. APPEND table. ENDDO. idoc_control-mestyp = zmestype. *idoc_control-doctyp = zidoctype. idoc_control-idoctp = zidoctype. LOOP AT table. CLEAR idoc_data. idoc_data-segnam = zsegname. idoc_data-sdata = table. APPEND idoc_data. ENDLOOP. CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' IN UPDATE TASK EXPORTING master_idoc_control = idoc_control * OBJ_TYPE = '' * CHNUM = '' tables communication_idoc_control = 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. * Implement suitable error handling here ENDIF. COMMIT WORK. WRITE: / 'idoc отправлен'. |
С Современным синтаксисом
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
DATA(control_record) = VALUE edidc( mestyp = 'ZWMS_INV_OUT' doctyp = 'ZWMS_INV' ). DATA t_idoc TYPE TABLE OF edidd WITH HEADER LINE. CLEAR t_idoc[]. "Заголовок. APPEND VALUE edidd( segnam = 'ZWMS_INV_HEAD' sdata = VALUE zwms_inv_head( plant = p_werks storage = p_lgort date_inv = sy-datum type_inv = '20' ) ) TO t_idoc[]. "Позиции. LOOP AT tt_record INTO l_record. APPEND VALUE edidd( segnam = 'ZWMS_INV_ITEM' sdata = VALUE zwms_inv_item( material = l_record-matnr current_stock = l_record-stock ) ) TO t_idoc. ENDLOOP. DATA t_edidc TYPE TABLE OF edidc WITH HEADER LINE. CLEAR: t_edidc[]. DATA stext TYPE string. CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING master_idoc_control = control_record TABLES communication_idoc_control = t_edidc[] master_idoc_data = t_idoc 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 INTO stext. WRITE: / |Ошибка при отправке IDOC: { stext }|. ROLLBACK WORK. RETURN. ELSE. COMMIT WORK AND WAIT. WRITE: / |Создан IDOC: { t_edidc[ 1 ]-docnum }|. CALL FUNCTION 'DEQUEUE_ALL'. ENDIF. |