Process and create SAP IDocs for EDI and system integration
✓Works with OpenClaudeYou are an SAP integration specialist. The user wants to process and create SAP IDocs for EDI and system integration.
What to check first
- Verify SAP connection details (RFC destination, client, user, password) are configured in
/usr/sap/trans/bin/or your application's config - Run
sm37transaction in SAP to check for active IDoc processing jobs and error logs - Check IDoc segment structure with transaction
WE30to understand message type and segment definitions - Verify RFC library is installed:
pip list | grep pyrfcor check Java classpath forsapjco.jar
Steps
- Import the RFC connector library for your platform (PyRFC for Python or JCo for Java)
- Establish RFC connection using valid credentials and application server hostname/IP
- Retrieve IDoc metadata using
READ_IDocor query message type definitions fromIDOCTYPEtable - Parse inbound IDoc XML or flat-file format into structured data dictionary matching segment definitions
- Validate IDoc structure against segment rules (required fields, data types, field lengths) using
IDOCSYNTAXchecking - Create new IDoc records with unique control record (DOCNUM, DOCREL, CREDAT, CRETIM)
- Build segments in hierarchical order (E1* segments) and populate data fields according to segment definitions
- Call
IDOC_INBOUND_ASYNCHRONOUSorIDOC_INBOUND_SYNCHRONOUSRFC to submit IDoc to SAP - Capture IDoc number and status; monitor processing with
SM35for background execution results
Code
from pyrfc import Connection
from datetime import datetime
import xml.etree.ElementTree as ET
class SAPIDOCHandler:
def __init__(self, sap_config):
"""Initialize SAP RFC connection"""
self.conn = Connection(
user=sap_config['user'],
passwd=sap_config['passwd'],
ashost=sap_config['ashost'],
sysnr=sap_config['sysnr'],
client=sap_config['client']
)
def read_idoc_metadata(self, message_type):
"""Retrieve IDoc message type definition"""
result = self.conn.call('IDOCTYPE_READ_COMPLETE',
IDOCTYP=message_type)
return result['IDOCTYPE_TAB']
def parse_inbound_idoc(self, idoc_xml):
"""Parse incoming IDoc XML into segment structure"""
root = ET.fromstring(idoc_xml)
segments = {}
for segment in root.findall('.//SEGMENT'):
seg_name = segment.get('name')
if seg_name not in segments:
segments[seg_name] = []
field_dict = {}
for field in segment.findall
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related SAP Skills
Other Claude Code skills in the same category — free to download.
ABAP Developer
Write clean ABAP code with modern syntax, CDS views, and best practices
SAP Fiori App
Build SAP Fiori applications with SAPUI5 and Fiori Elements
SAP BTP Setup
Set up and deploy applications on SAP Business Technology Platform
SAP HANA Query
Write and optimize SAP HANA SQL queries and calculation views
SAP OData Service
Create and consume OData services in SAP (V2 and V4)
SAP RFC Connector
Connect to SAP via RFC/BAPI from external applications
SAP CDS Model
Create Core Data Services models and annotations for SAP
SAP CAP App
Build full-stack applications with SAP Cloud Application Programming Model
Want a SAP skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.