# SAP ABAP Outbound IDoc Code Generator

> Source: https://netray.co/tools/sap-abap-outbound-idoc-master-idoc-distribute-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in message type, IDoc type, receiver and a segment, and get an ABAP skeleton that creates and dispatches an outbound IDoc.

## Category

sap

## Erp

SAP ECC / S/4HANA

## Audience

- SAP ABAP developer
- SAP integration developer

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Report name

**Key:** program

**Type:** text

**Default:** ZR_SEND_SHIPNOTICE_IDOC

#### Message type

**Key:** mestyp

**Type:** text

**Default:** ZSHPNOT

#### Basic IDoc type

**Key:** idoctp

**Type:** text

**Default:** ZSHPNOT01

#### Receiver partner type

**Key:** rcvprt

**Type:** select

**Options:**

- LS
- KU
- LI

**Default:** LS

#### Receiver partner number

**Key:** rcvprn

**Type:** text

**Default:** WMSCLNT100

#### Segment name

**Key:** segnam

**Type:** text

**Default:** Z1SHPHDR

#### Segment data (flat string)

**Key:** segdata

**Type:** text

**Default:** 8000012345 20261015 PLANT1010

**Blocks:**

#### Outbound IDoc report

**Body:** REPORT {{program}}.

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 = '{{mestyp}}'.
ls_control-idoctp = '{{idoctp}}'.
ls_control-rcvprt = '{{rcvprt}}'.
ls_control-rcvprn = '{{rcvprn}}'.

* One header segment, SDATA holds the field values as a flat string
ls_data-segnam = '{{segnam}}'.
ls_data-sdata  = '{{segdata}}'.
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

**Body:** 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 {{rcvprn}} with message type {{mestyp}}.
4. Set output mode to transfer immediately or schedule RSEOUT00.

**Notes:** 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.

## Content

**Intro:** 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.

**Sections:**

#### How to use the generator

**Body:** 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

**Body:** 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

**Body:** 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

**Body:** 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.

**Bullets:**

- 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

**Cta:** 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.

**Faq:**

#### Do I always need COMMIT WORK after MASTER_IDOC_DISTRIBUTE?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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.

## Search terms

master_idoc_distribute example, abap send idoc code, create outbound idoc abap, idoc abap program example, sap custom idoc outbound program, master_idoc_distribute sample code, abap idoc segment sdata, send idoc from report

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
