Learn how to install and use a custom program to change IDoc statuses en masse in SAP ERP Central Component (ECC) with flexible selection options that a standard SAP system does not have. By using this custom program, you can keep the IDoc queue clean and focus on IDocs that really need to be corrected.
Key Concept
An IDoc is an object in an SAP system designed to carry the data related to some transaction or master data from one application to another or from one system to another system. During the processing, an IDoc has various statuses until it reaches its final status (e.g., status 03 Data passed to port OK for an outbound IDoc). Therefore, organizations are interested in controlling the IDocs that are not yet in their final status and monitoring them to take corrective actions on those IDocs. If no more action is needed on the IDoc, the status can be changed to final so that there is no more monitoring done on that IDoc.
The following scenarios call for a change in status:
• In in-house cash management, the in-house cash center (IHC) sends the bank statement IDoc (FINSTA). However, if a duplicate bank statement is triggered before the original IDocs are processed, then the original IDocs fail because of a duplicate statement check. In such a case, the original IDoc needs to be set as processed. If the duplicate bank statement is triggered after the original IDoc is processed successfully, then the duplicate statement IDoc fails and the status of that would be required to be changed.
These examples describe a few situations in which correcting IDoc statuses helps an organization keep the IDoc list clean for better IDoc status monitoring. Keeping the IDoc status corrected enables the organization to focus on IDocs that really need correcting. I explain how to use a ready-to-install program to change the IDoc status en masse. This program is not limited only to SAP ERP Financials, but my focus is only on its use in finance.
First, I explain how to install a custom utility program and then explain how it can be used to change the IDoc status en masse.
How to Install the Custom Utility
To install a custom utility to change the status of IDocs, you need to create a custom program called Z_CHANGE_IDOC_STATUS. To do this, execute transaction code SE38 and create a custom program by following the procedure to create a custom report as shown in my article “Cross Task List Monitoring in the SAP Closing Cockpit in ECC 6.0.” You can use the code shown in Figure 1, text symbols shown in Table 1, and the selection screen data shown in Table 2 to create a custom program Z_CHANGE_IDOC_STATUS.
*&---------------------------------------------------------------------*
*& Report Z_CHANGE_IDOC_STATUS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_change_idoc_status.
TABLES: edidc.
SELECTION-SCREEN BEGIN OF BLOCK 1.
PARAMETERS: p_mestyp LIKE edidc-mestyp.
SELECT-OPTIONS: p_idoc FOR edidc-docnum.
SELECT-OPTIONS: p_credat FOR edidc-credat DEFAULT sy-datum OBLIGATORY .
SELECTION-SCREEN END OF BLOCK 1.
SELECTION-SCREEN BEGIN OF BLOCK 2.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-011 .
SELECT-OPTIONS: s_from1 FOR edidc-status NO INTERVALS OBLIGATORY .
SELECTION-SCREEN COMMENT 60(30) text-012 .
PARAMETERS: p_to1 LIKE edids-status OBLIGATORY .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-011 .
SELECT-OPTIONS: s_from2 FOR edidc-status NO INTERVALS.
SELECTION-SCREEN COMMENT 60(30) text-012 .
PARAMETERS: p_to2 LIKE edids-status .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-011 .
SELECT-OPTIONS: s_from3 FOR edidc-status NO INTERVALS.
SELECTION-SCREEN COMMENT 60(30) text-012 .
PARAMETERS: p_to3 LIKE edids-status .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-011 .
SELECT-OPTIONS: s_from4 FOR edidc-status NO INTERVALS.
SELECTION-SCREEN COMMENT 60(30) text-012 .
PARAMETERS: p_to4 LIKE edids-status .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-011 .
SELECT-OPTIONS: s_from5 FOR edidc-status NO INTERVALS.
SELECTION-SCREEN COMMENT 60(30) text-012 .
PARAMETERS: p_to5 LIKE edids-status .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK 2.
SELECTION-SCREEN SKIP.
PARAMETERS p_test AS CHECKBOX DEFAULT 'X'.
DATA: l_edidc_tab LIKE edidc OCCURS 1 WITH HEADER LINE,
l_idoc_status_tab LIKE bdidocstat OCCURS 1 WITH HEADER LINE,
l_lines LIKE sy-tabix,
l_idoc_control LIKE edidc,
l_zaehler LIKE sy-tabix.
IF s_from2 IS NOT INITIAL.
APPEND s_from2 TO s_from1.
ENDIF.
IF s_from3 IS NOT INITIAL.
APPEND s_from3 TO s_from1.
ENDIF.
IF s_from4 IS NOT INITIAL.
APPEND s_from4 TO s_from1.
ENDIF.
IF s_from5 IS NOT INITIAL.
APPEND s_from5 TO s_from1.
ENDIF.
IF p_mestyp <> space.
SELECT * INTO TABLE l_edidc_tab FROM edidc
WHERE mestyp = p_mestyp
AND status IN s_from1
AND docnum IN p_idoc
AND credat IN p_credat.
ELSEIF NOT p_idoc[] IS INITIAL.
SELECT * INTO TABLE l_edidc_tab FROM edidc
WHERE status IN s_from1
AND docnum IN p_idoc
AND credat IN p_credat.
ELSE.
SELECT * INTO TABLE l_edidc_tab FROM edidc
WHERE status IN s_from1
AND credat IN p_credat.
ENDIF.
DESCRIBE TABLE l_edidc_tab LINES l_lines.
IF p_test = 'X'.
WRITE: l_lines, 'IDocs to be converted.'(001).
EXIT.
ELSE.
LOOP AT l_edidc_tab.
CLEAR l_idoc_status_tab. REFRESH l_idoc_status_tab.
l_idoc_status_tab-docnum = l_edidc_tab-docnum.
IF l_edidc_tab-status IN s_from1.
l_idoc_status_tab-status = p_to1.
ELSEIF l_edidc_tab-status IN s_from2.
l_idoc_status_tab-status = p_to2.
ELSEIF l_edidc_tab-status IN s_from3.
l_idoc_status_tab-status = p_to3.
ELSEIF l_edidc_tab-status IN s_from4.
l_idoc_status_tab-status = p_to4.
ELSEIF l_edidc_tab-status IN s_from5.
l_idoc_status_tab-status = p_to5.
ENDIF.
APPEND l_idoc_status_tab.
CALL FUNCTION 'IDOC_STATUS_WRITE_TO_DATABASE'
EXPORTING
idoc_number = l_edidc_tab-docnum
IMPORTING
idoc_control = l_idoc_control
TABLES
idoc_status = l_idoc_status_tab
EXCEPTIONS
idoc_foreign_lock = 1
idoc_not_found = 2
idoc_status_records_empty = 3
idoc_status_invalid = 4
db_error = 5
OTHERS = 6.
ADD 1 TO l_zaehler.
IF l_zaehler = 1000.
CALL FUNCTION 'DEQUEUE_ALL'.
CLEAR l_zaehler.
ENDIF.
IF sy-subrc = 1.
WRITE : / l_edidc_tab-docnum, text-021 .
ELSEIF sy-subrc = 2.
WRITE : / l_edidc_tab-docnum, text-022 .
ELSEIF sy-subrc = 3.
WRITE : / l_edidc_tab-docnum, text-023 .
ELSEIF sy-subrc = 4.
WRITE : / l_edidc_tab-docnum, text-024 .
ELSEIF sy-subrc = 5.
WRITE : / l_edidc_tab-docnum, text-025 .
ELSEIF sy-subrc = 6.
WRITE : / l_edidc_tab-docnum, text-026 .
ELSEIF sy-subrc = 0.
WRITE : / l_edidc_tab-docnum, text-027 .
ENDIF.
ENDLOOP.
WRITE: / l_lines, 'IDocs were converted.'(002).
ENDIF.
Figure 1
Code to change an IDoc status
Tables 1 and 2 show text symbols and selection texts to use in developing the custom program to change an IDoc status.
Number | Description |
001 | IDocs to be converted |
002 | IDocs were converted |
011 | Present IDoc status |
012 | ---> Target IDoc status |
021 | IDoc locked |
022 | IDoc not found |
023 | IDoc status record empty |
024 | IDoc status invalid |
025 | Database error |
026 | Unidentified error |
027 | IDoc status changed successfully |
Table 1
Text symbols
Text | Description |
P_CREDAT | IDoc creation dates |
P_IDOC | IDoc numbers |
P_MESTYP | Message type |
P_TEST | Test run |
P_TO1 | Target IDoc status |
P_TO2 | Target IDoc status |
P_TO3 | Target IDoc status |
P_TO4 | Target IDoc status |
P_TO5 | Target IDoc status |
S_FROM1 | Present IDoc status |
S_FROM2 | Present IDoc status |
S_FROM3 | Present IDoc status |
S_FROM4 | Present IDoc status |
S_FROM5 | Present IDoc status |
Table 2
Selection texts
Use Procedure for the Custom Utility
To use this custom utility, execute transaction code SE38 or follow SAP Easy Access menu > Tools > ABAP Workbench > Development > SE38 - ABAP Editor. In the screen that appears, enter Z_ CHANGE_IDOC_STATUS in the Program field and click the execute icon (Figure 2).

Figure 2
Execute the new report
In the next screen, you see various selection options (Figure 3).

Figure 3
The selection screen for the new report
The screen shown in Figure 3 includes the following selection fields:
• Message Type: Here you can enter the message type of the IDocs to be changed (e.g., message type FINSTA for bank statement). I recommend that you execute this utility separately for each type of message type, as there can be different statuses in different message types relevant for the IDoc flow.
• IDoc Number(s): If you know which IDocs should be changed, you can enter the IDoc numbers here. You can enter specific IDocs or a range of IDocs.
• IDOC Creation Date(s): In this field you enter the IDoc creation date. The data you enter in this field is quite important while executing this program, as it limits the data selection and enhances the program performance. You might be interested to monitor and control the IDoc status of a certain time period only (e.g., for the last three months).
• Present IDOC Status(s): In this field you enter the present IDoc status that you want to change.
• Target IDOC Status: Here you enter the target status for the IDoc having status as entered in “From IDoc Status(es)” (I have provided five placeholders for defining the combinations of present status and target status, so that you can define the combinations more flexibly and do not need to run it multiple times.)
• Test Run: If you select this option, the IDoc status does not actually change. If you do not select this option, then only the IDoc status is changed.
After entering the selection screen data, click the execute icon as shown in Figure 3. This action opens a screen that displays the various IDocs changed (Figure 4). At the end of the report, it states the total number of IDocs processed. If the IDoc status can’t be changed, then the reason for that is also shown in the output (e.g., IDoc not found).

Figure 4
Execution output for the IDoc status change report
You can also execute this report in the back end via a batch job (e.g., to change the status of IDocs for those that are older than three months).
Gaurav Agarwal
Gaurav Aggarwal is SAP S/4HANA lead consultant at Infosys Limited. He has more than 14 years of experience, including 11 years in SAP Finance. He has expertise in both SAP FI and Controlling (CO) with integration to other modules in manufacturing and process industries. He is a chartered accountant and SAP Certified Financial Consultant. He holds a bachelor’s degree in commerce and is a techno-functional expert with thorough knowledge of the necessary ABAP for functional experts. He is a veteran in G/L, AR, AP, banking, FA, Travel Management, and closing cockpit and has handled greenfield implementation, upgrades and conversions, rollouts, and support projects.
You may contact the author at gka2707@gmail.com.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.