SAP IDoc Segment Data Reader: EDIDC, EDID4 and EDIDS in ABAP
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.
Fill in
1 outbound, 2 inbound
Report source
REPORT ZEDI_IDOC_SEGMENT_READER.
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 E1EDK01,
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 'ORDERS',
p_idoctp TYPE edidc-idoctp DEFAULT 'ORDERS05',
p_direct TYPE edidc-direct DEFAULT '2',
p_status TYPE edidc-status DEFAULT '51',
p_credat TYPE edidc-credat DEFAULT '20261001',
p_max TYPE i DEFAULT 200.
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 = 'E1EDK01'.
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-BELNR.
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
* 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.
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.
Get an IDoc error triage report
Send us a week of status 51 IDocs (numbers and messages only) and we group them by root cause with the fix for each group.
Optional. The tool and every export work without this. No spam.
Which table holds what
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.
- 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
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
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
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.
Frequently Asked Questions
Which SAP table stores IDoc segment data?
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?
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?
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?
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.
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.
Related Tools
SAP IDoc Status Codes Reference
Look up any IDoc status code, see whether it is inbound or outbound, whether it is an error, and which transaction to use to fix it.
SAPSAP ABAP IDoc Status Query Generator (EDIDC and EDIDS)
Build an ABAP SELECT that lists failed or waiting IDocs from EDIDC and joins in the latest status message from EDIDS.
SAPSAP IDoc Control Record (EDIDC) Fields Reference
Look up every commonly used field of the IDoc control record (table EDIDC and structure EDI_DC40) with its meaning and data type.
Developer ToolsSAP ECC Custom Inbound IDoc Function Module Skeleton Generator
Generate a ready-to-adapt inbound IDoc function module for a custom message type and segment: standard interface, segment cast, validation, status 51 or 53, workflow return variables and the configuration steps.
More Developer Tools tools
See all- SAP ECC Enhancement Transactions and Exit Tables Reference (SMOD, CMOD, SE18, MODSAP, SXC_EXIT)
- SAP ECC Data Dictionary and Repository Tables Reference (DD02L, DD03L, T100, E070, TSTC)
- SAP ECC ABAP Runtime Errors (ST22 Dumps) and Error Log Transactions Reference
- SAP ECC Background Job History ABAP Query Generator (TBTCO + TBTCP)
- SAP ECC Background Job Creation ABAP Generator (JOB_OPEN, SUBMIT, JOB_CLOSE)
- SAP ECC BAPI_SALESORDER_CHANGE ABAP Generator
- SAP ECC BAPI_PO_CHANGE ABAP Generator
- SAP ECC BAPI_MATERIAL_SAVEDATA Material Creation ABAP Generator
- SAP ECC BAPI_ACC_DOCUMENT_POST G/L and Vendor Posting ABAP Generator
Keep exploring
Free tools
- SAP ABAP IDoc Status Query Generator (EDIDC and EDIDS)Build an ABAP SELECT that lists failed or waiting IDocs from EDIDC and joins in the latest status message from EDIDS.
- SAP IDoc Control Record (EDIDC) Fields ReferenceLook up every commonly used field of the IDoc control record (table EDIDC and structure EDI_DC40) with its meaning and data type.
- SAP ABAP Outbound IDoc Code Generator (MASTER_IDOC_DISTRIBUTE)Fill in message type, IDoc type, receiver and a segment, and get an ABAP skeleton that creates and dispatches an outbound IDoc.