SAPFree generatorPDF, Excel, Word exportSAP ECC / S/4HANA

SAP ABAP Outbound IDoc Code Generator

Sending a custom IDoc from ABAP follows the same pattern every time: fill the control record, fill the data records, call MASTER_IDOC_DISTRIBUTE and commit. This generator produces that skeleton with your own names.

Fill in

Generated code
Download:

Outbound IDoc report

REPORT ZR_SEND_SHIPNOTICE_IDOC.

DATA: ls_control TYPE edidc,
      lt_comm    TYPE STANDARD TABLE OF edidc,
      ls_comm    TYPE edidc,
      lt_data    TYPE STANDARD TABLE OF edidd,
      ls_data    TYPE edidd.

* Control record: sender is filled by the system from the partner profile
ls_control-mestyp = 'ZSHPNOT'.
ls_control-idoctp = 'ZSHPNOT01'.
ls_control-rcvprt = 'LS'.
ls_control-rcvprn = 'WMSCLNT100'.

* One header segment, SDATA holds the field values as a flat string
ls_data-segnam = 'Z1SHPHDR'.
ls_data-sdata  = '8000012345 20261015 PLANT1010'.
APPEND ls_data TO lt_data.

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
  EXPORTING
    master_idoc_control            = ls_control
  TABLES
    communication_idoc_control     = lt_comm
    master_idoc_data               = lt_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 e398(00) WITH 'IDoc creation failed, subrc' sy-subrc.
ELSE.
  COMMIT WORK.
  READ TABLE lt_comm INTO ls_comm INDEX 1.
  IF sy-subrc = 0.
    WRITE: / 'IDoc created:', ls_comm-docnum.
  ENDIF.
ENDIF.

Prerequisites to configure

1. Create the segment in WE31 and the basic IDoc type in WE30.
2. Create the logical message in WE81 and link it to the IDoc type in WE82.
3. Create the port in WE21 and the outbound partner profile in WE20 for WMSCLNT100 with message type ZSHPNOT.
4. Set output mode to transfer immediately or schedule RSEOUT00.

Skeleton only. The SDATA string must match the segment field lengths exactly, so for real segments assign a typed structure to SDATA instead of a literal. MASTER_IDOC_DISTRIBUTE needs COMMIT WORK to release the IDoc to the dispatch. Verify exception names and behavior in SE37 on your release.

Want an IDoc design reviewed?

Optional: have an SAP integration expert look over your IDoc and partner profile design before you build it.

Optional. The tool and every export work without this. No spam.

How to use the generator

Enter the message type, IDoc type, receiver and first segment, then copy the generated code into a new report in SE38. Adjust the segment assignment so it builds from your own structure. Before activating, make sure the segment, IDoc type, message type and partner profile exist, or the call will return an exception.

What the function module does

MASTER_IDOC_DISTRIBUTE takes a master IDoc, looks up receivers in the distribution model or partner profile, and creates one communication IDoc per receiver. It writes status records and, depending on the output mode in the partner profile, passes the IDoc to the port immediately or leaves it at status 30 for RSEOUT00. Nothing is stored permanently until COMMIT WORK, which is why the commit is part of the code.

Reading the result

The table COMMUNICATION_IDOC_CONTROL returns one control record per receiver, including the new document number. Open that number in WE02. Status 03 means data passed to the port, 30 means ready for dispatch, 02 means the port failed, and 29 or 26 point to errors while creating the IDoc.

Common mistakes

The most frequent faults are a missing COMMIT WORK, sending a message type that is not in the distribution model or partner profile, and segment data that is shifted because fixed-width field lengths do not match.

  • Use a typed structure and MOVE it to SDATA
  • Do not commit inside a loop for thousands of IDocs without thinking about packaging
  • Test with WE19 before scheduling the report

Frequently Asked Questions

Do I always need COMMIT WORK after MASTER_IDOC_DISTRIBUTE?

Yes when you call it from your own program. The IDoc and its status are written in the update task and only become visible and dispatchable after a commit. If your report is called inside a transaction that commits later, the commit can be left to the caller.

Should I use MASTER_IDOC_DISTRIBUTE or the outbound process code?

For standard documents that use output control, the process code and its function module do the work. For custom reports and extracts, MASTER_IDOC_DISTRIBUTE is the simple route. Both end up with the same tables and the same monitoring.

Why is my IDoc stuck at status 30?

Status 30 means the IDoc is ready for dispatch but nothing has sent it. The partner profile probably uses collect mode, so schedule RSEOUT00 as a periodic job, or change the output mode to transfer immediately if volume allows.

Can I send several segments or child segments?

Yes. Add one row to the data table per segment in the order of the hierarchy, and set the PSGNUM and HLEVEL fields of each EDIDD row so child segments point to their parent. The segment numbers must follow the IDoc type definition.

Netray works with SAP developers to build integrations and private assistants over SAP data. If you want a second pair of eyes on an IDoc design, ask for a review.