# SAP IDoc Segment Data Reader: EDIDC, EDID4 and EDIDS in ABAP

> Source: https://netray.co/tools/sap-ecc-idoc-segment-data-edid4-abap-reader-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Choose a message type, basic type, segment and field, and get an ABAP report that lists IDocs, the value of that segment field and the last status message text.

## Category

developer

## Erp

SAP ECC 6.0

## Audience

- ABAP developer
- SAP integration support
- EDI analyst

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Report name

**Key:** report

**Type:** text

**Default:** ZEDI_IDOC_SEGMENT_READER

#### Message type

**Key:** mestyp

**Type:** text

**Default:** ORDERS

#### Basic type

**Key:** idoctp

**Type:** text

**Default:** ORDERS05

#### Segment type (EDID4-SEGNAM)

**Key:** segnam

**Type:** text

**Default:** E1EDK01

#### Segment structure (DDIC)

**Key:** segstruct

**Type:** text

**Default:** E1EDK01

#### Segment field to show

**Key:** field

**Type:** text

**Default:** BELNR

#### Direction

**Key:** direction

**Type:** select

**Options:**

- 1
- 2

**Default:** 2

**Help:** 1 outbound, 2 inbound

#### Status (blank = all)

**Key:** status

**Type:** text

**Default:** 51

#### Created from (YYYYMMDD)

**Key:** from_date

**Type:** text

**Default:** 20261001

#### Max IDocs

**Key:** max_idocs

**Type:** number

**Default:** 200

**Blocks:**

#### Report source

**Body:** REPORT {{report}}.

TYPES: BEGIN OF ty_out,
         docnum   TYPE edidc-docnum,
         status   TYPE edidc-status,
         credat   TYPE edidc-credat,
         segnum   TYPE edid4-segnum,
         value    TYPE c LENGTH 70,
         lastmsg  TYPE c LENGTH 220,
       END OF ty_out.

DATA: lt_edidc  TYPE STANDARD TABLE OF edidc,
      ls_edidc  TYPE edidc,
      lt_edid4  TYPE STANDARD TABLE OF edid4,
      ls_edid4  TYPE edid4,
      lt_edids  TYPE STANDARD TABLE OF edids,
      ls_edids  TYPE edids,
      ls_seg    TYPE {{segstruct}},
      lt_out    TYPE STANDARD TABLE OF ty_out,
      ls_out    TYPE ty_out,
      lr_status TYPE RANGE OF edidc-status,
      ls_status LIKE LINE OF lr_status,
      lv_text   TYPE string,
      lo_alv    TYPE REF TO cl_salv_table,
      lx_msg    TYPE REF TO cx_salv_msg.

PARAMETERS: p_mestyp TYPE edidc-mestyp DEFAULT '{{mestyp}}',
            p_idoctp TYPE edidc-idoctp DEFAULT '{{idoctp}}',
            p_direct TYPE edidc-direct DEFAULT '{{direction}}',
            p_status TYPE edidc-status DEFAULT '{{status}}',
            p_credat TYPE edidc-credat DEFAULT '{{from_date}}',
            p_max    TYPE i            DEFAULT {{max_idocs}}.

START-OF-SELECTION.

  IF p_status IS NOT INITIAL.
    ls_status-sign   = 'I'.
    ls_status-option = 'EQ'.
    ls_status-low    = p_status.
    APPEND ls_status TO lr_status.
  ENDIF.

* 1. Control records
  SELECT docnum mestyp idoctp status credat
    FROM edidc
    INTO CORRESPONDING FIELDS OF TABLE lt_edidc
    UP TO p_max ROWS
    WHERE mestyp = p_mestyp
      AND idoctp = p_idoctp
      AND direct = p_direct
      AND status IN lr_status
      AND credat >= p_credat
    ORDER BY docnum DESCENDING.

  LOOP AT lt_edidc INTO ls_edidc.
    CLEAR ls_out.
    ls_out-docnum = ls_edidc-docnum.
    ls_out-status = ls_edidc-status.
    ls_out-credat = ls_edidc-credat.

*   2. Last status record and its message text
    CLEAR: lt_edids, ls_edids.
    SELECT * FROM edids
      INTO TABLE lt_edids
      UP TO 1 ROWS
      WHERE docnum = ls_edidc-docnum
      ORDER BY countr DESCENDING.
    READ TABLE lt_edids INTO ls_edids INDEX 1.
    IF sy-subrc = 0.
      IF ls_edids-stamid IS NOT INITIAL.
        MESSAGE ID ls_edids-stamid TYPE 'E' NUMBER ls_edids-stamno
                WITH ls_edids-stapa1 ls_edids-stapa2
                     ls_edids-stapa3 ls_edids-stapa4
                INTO ls_out-lastmsg.
      ELSE.
        ls_out-lastmsg = ls_edids-statxt.
      ENDIF.
    ENDIF.

*   3. Data records of the chosen segment
    SELECT docnum segnum segnam sdata
      FROM edid4
      INTO CORRESPONDING FIELDS OF TABLE lt_edid4
      WHERE docnum = ls_edidc-docnum
        AND segnam = '{{segnam}}'.
    IF sy-subrc <> 0.
      APPEND ls_out TO lt_out.
      CONTINUE.
    ENDIF.

    LOOP AT lt_edid4 INTO ls_edid4.
*     SDATA (1000 characters) cast onto the segment structure
      ls_seg = ls_edid4-sdata.
      ls_out-segnum = ls_edid4-segnum.
      ls_out-value  = ls_seg-{{field}}.
      APPEND ls_out TO lt_out.
    ENDLOOP.
  ENDLOOP.

  TRY.
      cl_salv_table=>factory(
        IMPORTING r_salv_table = lo_alv
        CHANGING  t_table      = lt_out ).
      lo_alv->display( ).
    CATCH cx_salv_msg INTO lx_msg.
      lv_text = lx_msg->get_text( ).
      MESSAGE lv_text TYPE 'I'.
  ENDTRY.

#### Alternative: read one IDoc completely

**Body:** * Reads control, data and status records of one IDoc in one call
*  DATA: ls_ctrl TYPE edidc,
*        lt_data TYPE STANDARD TABLE OF edidd,
*        lt_stat TYPE STANDARD TABLE OF edids.
*  CALL FUNCTION 'IDOC_READ_COMPLETELY'
*    EXPORTING
*      document_number         = ls_edidc-docnum
*    IMPORTING
*      idoc_control            = ls_ctrl
*    TABLES
*      int_edids               = lt_stat
*      int_edidd               = lt_data
*    EXCEPTIONS
*      document_not_exist      = 1
*      document_number_invalid = 2
*      OTHERS                  = 3.

**Notes:** The segment structure must be the DDIC structure of the segment type (E1EDK01, E1EDP01, Z1...) and must be purely character-like, which all IDoc segment structures are. EDID4-SEGNAM holds the segment type, not the version-specific definition (E2EDK01005). Check in SE11 that your system stores data records in EDID4 (standard since release 4.0) and in SE37 that IDOC_READ_COMPLETELY has the parameters shown.

## Content

**Intro:** This generator creates an ABAP report for SAP ECC 6.0 that reads IDoc control records from EDIDC, segment data from EDID4 and the latest status record from EDIDS, then shows one segment field and the resolved status message in ALV. Use it to answer questions like which order numbers sit in status 51 this week.

**Sections:**

#### Which table holds what

**Body:** EDIDC is the control record: one row per IDoc with DOCNUM, status, direction, message type, basic type, partners and creation date. EDID4 holds the data records: one row per segment with DOCNUM, SEGNUM, SEGNAM, the hierarchy level and SDATA, a 1000-character field containing the segment content. EDIDS holds the status history: one row per status change with COUNTR, STATUS, the message class STAMID, number STAMNO, parameters STAPA1 to STAPA4 and the text STATXT. EDIDD is only the structure used in memory and in function interfaces; EDID2 is the older data record table used for release 3.x record formats.

**Bullets:**

- WE02 and WE05 display the same three tables.
- Segment content is only readable after casting SDATA to the segment structure.
- The error message is rebuilt from STAMID, STAMNO and STAPA1 to STAPA4.

#### How to use it

**Body:** Enter message type, basic type, the segment you need and the field to display, plus direction and status. For inbound sales orders in error that would be ORDERS, ORDERS05, E1EDK01, BELNR, direction 2 and status 51. Paste the code into SE38 and run it. Each output row shows the IDoc number, current status, creation date, segment number, the field value and the last status message in readable form.

#### Worked example

**Body:** A customer reports that three purchase orders were not created as sales orders. Run the report for ORDERS, ORDERS05, segment E1EDK01, field BELNR, direction 2, status 51 from the start of the month. The value column shows the customer PO numbers, and lastmsg shows text such as a missing sales area determination or a material that cannot be found, rebuilt from the message class and parameters in EDIDS. Fix the master data, then reprocess with BD87.

#### Gotchas

**Body:** SELECTs inside the loop are fine for a few hundred IDocs; for larger volumes, collect DOCNUMs and use FOR ALL ENTRIES on EDID4 and EDIDS. The last status is found by COUNTR, not by date and time, because several status records can share a timestamp. For a field that occurs in repeating segments, such as E1EDP01-POSEX, expect one output row per segment. Archived IDocs are not in EDID4 any more and need the archive read programs.

**Cta:** If you want your support team to ask which IDocs failed and why in plain English on your own servers, we can set that up over your ECC system.

**Faq:**

#### Which SAP table stores IDoc segment data?

**Answer:** EDID4 stores IDoc data records in ECC 6.0, one row per segment, keyed by DOCNUM, COUNTER and SEGNUM. The segment content is in SDATA, a 1000-character field. To read individual fields, move SDATA into a variable typed with the segment structure, for example E1EDK01, as the generated code does.

#### Which SAP table holds the IDoc error message?

**Answer:** EDIDS holds every status record of an IDoc. The message is stored as message class STAMID, number STAMNO and parameters STAPA1 to STAPA4, plus a text template in STATXT. Use MESSAGE ID ... INTO to build the full text, and read the record with the highest COUNTR for the current status.

#### What are the main IDoc tables in SAP?

**Answer:** EDIDC for control records, EDID4 for data records and EDIDS for status records. Configuration lives elsewhere: EDP13 and EDP21 hold outbound and inbound partner profile parameters (WE20), and EDBAS and EDISEGMENT describe basic types and segments. WE02 and WE05 display the runtime tables.

#### What is the difference between EDID4 and EDIDD?

**Answer:** EDID4 is the database table where data records are stored. EDIDD is a structure with the same main fields used in memory, for example in the IDOC_DATA table of inbound function modules and in IDOC_READ_COMPLETELY. You select from EDID4 and pass EDIDD lines between function modules.

## Search terms

sap table for idoc segment data, sap table idoc segments, sap idoc content table, sap table for idoc data, sap table for idoc error message, edid4 table, edids status message, sap idoc tables in sap

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