ERPClimb logoERPClimb
IDoc
ABAP Developmentadvanced 10 min read

IDoc Part 6: Inbound Process Code and Custom Function Module

Preview · a free account unlocks the full lesson

Key takeaway

Build a custom inbound IDoc: own message type and basic type, the standard inbound function module interface (IDOC CONTRL, IDOC DATA, IDOC STATUS, RETURN VARIABLES, WORKFLOW RESULT), process code in WE42, assignment in WE57/BD51, and correct status handling.

In this lessonShow sections

Visual overview

IDoc Part 6: Inbound Process Code and Custom Function Module — learning sheetFlow: Create segment, basic type and message type in a sandbox → Create the FM (code example) and register it in WE57, BD51, WE42 → Test with WE19 and check status records in WE02. Key ideas: OBJECTS TO CREATE; FM LOGIC PER IDOC; ROLLBACK HANDLING; TESTING. Watch out: The FM must never COMMIT WORK itself (the IDoc framework commits) and must never stop with MESSAGE E — errors go into IDOC_STATUS.ERPClimb.com / ABAP / LESSON 6/10 / LEARNING SHEETIDoc Part 6: Inbound Process Code and Custom FunctionModule1 · HOW IT FLOWS1Create segment, basictype and message type ina sandbox2Create the FM (codeexample) and register itin WE57, BD51, WE423Test with WE19 and checkstatus records in WE022 · KEY IDEAS EXPLAINEDObjects To CreateSegment(s) WE31 (e.g. Z1PROJHDR), basic type WE30(ZPROJECT01), message type WE81 (ZPROJECT),assignment WE82.Function module Z_IDOC_INPUT_ZPROJECT with thestandard interface (copy from IDOC_INPUT_ORDERSsignature).Fm Logic Per IDoc1. Loop at IDOC_CONTRL (one per IDoc when massprocessing).Rollback HandlingIf a posting fails after partial updates, callBAPI_TRANSACTION_ROLLBACK (or ROLLBACK WORK)carefully: in mass processing it affects all IDocs…TestingWE19 with "inbound function module"option allows debugging the FM directly with acopied IDoc.3 · REMEMBER · WATCH OUTRememberA custom inbound FM uses SAP's fixed interface: IDOC_CONTRL, IDOC_DATA(in), IDOC_STATUS, RETURN_VARIABLES, WORKFLOW_RESULT (out)…For each IDoc, the FM appends one status record (53 or 51) and aRETURN_VARIABLES entry ("Processed_IDOCs" or…Registration: WE57 (FM ↔ basic type/message type), BD51 (input type,e.g. 0 mass or 1 single), WE42 (process code → FM), WE20 (partner…!Watch outThe FM must never COMMIT WORK itself(the IDoc framework commits) andmust never stop with MESSAGE E —errors go into IDOC_STATUS.4 · IN A REAL PROJECTA warehouse partner sent project assignments that SAP had no standard IDoc for. The first custom FM calledCOMMIT WORK and MESSAGE E on errors: failing IDocs ended with dumps, and successful ones were sometimescommitted together with half-processed data. The rewrite followed the standard interface: status records per…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 3 covered using SAP's own inbound function modules; when a partner sends data that SAP has no standard IDoc for, you need to build your own custom inbound function module instead.

A custom inbound function module follows SAP's fixed interface shape: IDOC_CONTRL, IDOC_DATA, and IDOC_STATUS on the way in, plus RETURN_VARIABLES and WORKFLOW_RESULT on the way out, along with INPUT_METHOD and MASS_PROCESSING controlling how it's called.

For every IDoc it processes, the function module appends exactly one status record — either 53 or 51 — and a corresponding entry in RETURN_VARIABLES, tagged "Processed_IDOCs" or "Error_IDOCs." Registration ties several pieces together: WE57 links the function module to a basic type and message type, BD51 declares its input type (0 for mass processing, 1 for single IDoc, which allows dialog), WE42 maps a process code to the function module, and WE20's partner profile references that process code.

One rule that must never be broken: the function module must never issue COMMIT WORK itself, since the IDoc framework handles the commit, and it must never halt with MESSAGE E — errors need to go into IDOC_STATUS instead.

The objects you need to create are: one or more segments in WE31 (for example Z1PROJHDR), a basic type in WE30 (ZPROJECT01), a message type in WE81 (ZPROJECT), and their assignment together in WE82. Then build the function module itself, say Z_IDOC_INPUT_ZPROJECT, copying its interface signature from an existing one like IDOC_INPUT_ORDERS.

Register it in WE57 against the basic type and message type, with direction 2 for inbound and type F for function module. In BD51, register its input type — 0 if mass processing should be allowed, 1 if it should process a single IDoc with dialog possible.

In WE42, create process code ZPRJ pointing to the function module, and in WE20, add inbound parameter ZPROJECT to the relevant partner profile, pointing to process code ZPRJ.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.