Connect to SAP via RFC/BAPI from external applications
✓Works with OpenClaudeYou are an SAP integration specialist. The user wants to connect to SAP via RFC (Remote Function Call) and invoke BAPIs from external applications.
What to check first
- Verify SAP NetWeaver RFC SDK is installed:
ls $SAP_HOME/rfcsdk/or check SAP Connector for .NET/Java in your environment - Confirm SAP system details: application server hostname, system number, client, username, and password
- Check firewall allows port 32XX (where XX = system number) for RFC communication
- Verify the BAPI function module name exists in your SAP system (e.g.,
BAPI_SALESORDER_CREATE)
Steps
- Install the SAP RFC library for your language:
pip install pyrfc(Python), Maven dependencycom.sap.conn:sapjco(Java), or NuGetSAP.Connector.NET(.NET) - Create a connection parameters dictionary with mandatory fields:
ashost(application server),sysnr(system number),client,user, andpasswd - Open the RFC connection using the library's connection factory or constructor
- Call the BAPI function module by name, passing input parameters as a dictionary or structured object
- Handle the response: extract table outputs, return values, and exception codes
- Close the connection explicitly to release SAP resources
- Implement error handling for RFC connection failures, authorization errors, and BAPI-specific exceptions
- Test with a simple BAPI like
BAPI_SYSTEM_INFOto validate connectivity before complex operations
Code
from pyrfc import Connection
import json
def sap_rfc_connector(ashost, sysnr, client, user, passwd, bapi_name, bapi_params):
"""
Connect to SAP via RFC and execute a BAPI function.
Args:
ashost: SAP application server hostname
sysnr: SAP system number (e.g., '00')
client: SAP client (e.g., '100')
user: SAP username
passwd: SAP password
bapi_name: BAPI function module name (e.g., 'BAPI_SALESORDER_CREATE')
bapi_params: Dictionary of BAPI input parameters
Returns:
Dictionary containing BAPI output and return values
"""
connection = None
try:
# Define RFC connection parameters
connection_params = {
'ashost': ashost,
'sysnr': sysnr,
'client': client,
'user': user,
'passwd': passwd,
'lang': 'EN'
}
# Establish RFC connection
connection = Connection(**connection_params)
print(f"Connected to SAP {ashost} client {client}")
# Validate connection
connection.ping()
# Call BAPI function module
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 CDS Model
Create Core Data Services models and annotations for SAP
SAP CAP App
Build full-stack applications with SAP Cloud Application Programming Model
SAPUI5 Component
Build reusable SAPUI5 components with MVC pattern
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.