The Vision: Talk to your SAP system
Do you use still SAP transactions? Talk with your SAP system! AI can do the same things like you but faster and smarter!
What the agent does:
- ✅Connect to your live SAP GUI session via COM
- ✅Navigate through SAP transactions
- ✅Export data and do analysis on it
🛠️ What We Built: The SAP GUI Scripting AI Agent
This Python application combines cutting-edge AI frameworks with battle-tested SAP automation:
Tech Stack:
├── 🖥️ pywin32 (COM automation for SAP GUI)
├── 📊 openpyxl (Excel generation)
├── 📚 sap_scripting.py (reusable SAP GUI API sap_gui_scripting_api.pdf )
└── 📝 CLAUDE.md (living project documentation)Core Capabilities Demonstrated
Capability Description
| Live SAP GUI Connection | ROT-based COM access to running sessions |
| Intelligent Navigation | Transaction execution, screen exploration, button discovery |
| Complex Grid Parsing | Tree controls, ALV grids, splitter shells, dynamic content |
| Error Analysis | Message classification, severity scoring, root cause mapping |
| Excel Automation | Structured remediation plans with SAP transaction references |
| Conversational Interface | Natural language → structured SAP operations |
📊The Real-World Use Case: DMLT Posting Engine Error Analysis
Context: Migration project has 14,000+ posting simulation errors
Top 3 Critical Errors (from 10 total message classes)
# Message Count Severity Solution
| 1 | NR 751 - Number range interval missing | 9999+ | 🔴HIGH | FBN1/SNRO → Maintain number ranges in target |
| 2 | CNV_PE 451 - TRule error | 2,328 | 🔴HIGH | CNV_PE_CUSTOM → Read Customizing + Regenerate TRules |
| 3 | CNV_OT_CX 000 - Generic exception | 1,746 | 🔴HIGH | ST22/SM21 → Check dumps/system log for root cause |
Complete Error Analysis Generated
Message Count Severity Root Cause SAP Transaction
| NR 751 | 9999+ | HIGH | Number range gap | FBN1/SNRO |
| CNV_PE 451 | 2,328 | HIGH | TRule customization | CNV_PE_CUSTOM |
| CNV_OT_CX 000 | 1,746 | HIGH | System exception | ST22/SM21 |
| F5A 002 | 86 | MEDIUM | Vendor deletion flag | XK02/FK02 |
| CNV_PE 589 | 54 | MEDIUM | WL2MOD exit error | Debug ABAP exit |
| CNV_PE 205 | 51 | MEDIUM | Reference doc missing | Post ref docs first |
| F5 351 | 17 | MEDIUM | Account blocked | FS00/FK02 |
| F5A 003 | 14 | MEDIUM | G/L deletion flag | FS00 |
| F5 026 | 10 | LOW | Missing bank details | FK02 |
| /SLO/PECON 102 | 5 | LOW | WHT data missing | FK02 |
🏗️ Architecture: How the Agent Works
┌─────────────────────────────────────────────────────────────────┐
│ User: Natural Language Request │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ 1. COM Connection → session.Info → System validation │
│ 2. /SLO/PECON → Error Monitor (ERR_OV) → F8 Execute │
│ 3. Tree Control parsing → MSGNO/MSGCNT_RCV/MSGTEXT extraction │
│ 4. LLM Reasoning → Severity classification + solution mapping │
│ 5. openpyxl → Structured Excel with 2 sheets │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Output: PE_Error_Analysis_ZFI_SDT.xlsx │
└─────────────────────────────────────────────────────────────────┘SAP Connection Pattern (ROT-based COM)
import win32com.client
# Connect to RUNNING SAP session (never launch from script)
SapGuiAuto = win32com.client.GetObject("SAPGUI")
application = SapGuiAuto.GetScriptingEngine
connection = application.Children(0) # first connection
session = connection.Children(0) # first session
# Validate connection
print(f"System: {session.Info.SystemName}")
print(f"Client: {session.Info.Client}")
print(f"User: {session.Info.User}")💰Why This Matters
Traditional Approach AI Agent Approach
| Manual Error Monitor → Export → Excel → Manual analysis → 4+ hours | "Check errors and create Excel" → ✅Done in 2 minutes |
| Static SQL queries → Miss dynamic tree data | Live GUI parsing → Always current |
| Generic error lists | Severity-ranked remediation with exact transactions |
| Consultant dependency | Self-service analysis for any team member |
💬The Conversation That Built This
Here's the actual conversation flow with Claude Code that produced this solution:
User: "List SAP connections"
Agent: → Found 2 connections
User: "Test System"
Agent: → Connected to system
User: "Open /SLO/PECON"
Agent: → Transaction opened, PECON Start screen displayed
User: "Go into Error Monitor, check messages, create Excel with solutions"
Agent: → Clicked ERR_OV → F8 Execute → Parsed tree (16 nodes)
→ Generated PE_Error_Analysis.xlsx with 10 errors + solutionsTotal time: ~2 minutes. Zero manual SAP navigation.
✅Prerequisites (Production-Ready)
- ✅Windows OS + SAP GUI for Windows
- ✅Scripting enabled (Alt+F12 → Options → Scripting)
- ✅RZ11:
sapgui/user_scripting = TRUE - ✅Open SAP session before agent execution
- ✅Python 3.11+ with virtual environment
📁Project Structure
sap_gui_scripting_ai/ ├── 📚 sap_scripting.py #SAP GUI Scripting Framework Generic Python wrapper#├── 📝 CLAUDE.md # Living documentation (auto-updated) ├── 📊 PE_Error_Analysis.xlsx # Generated output └── 📁 posting_engine_knowledge/ # SAP docs + extracted knowledge ├── PECON_User_Guide_v2.1.pdf ├── PECON_FAQ_v1.5.pdf └── PE_Enablement_2025_10.pdf
❓FAQs
Q: Does this replace SAP GUI scripting consultants? A: It augments them. The agent handles 80% of repetitive analysis; consultants focus on exceptions.
Q: Is this safe for Production SAP? A: Read-only analysis mode. No postings, no data changes. Uses your existing session permissions.
Q: What SAP systems are supported? A: Any SAP GUI system with scripting enabled — ECC, S/4HANA, any client. Multi-system aware.
Q: Can it handle custom Z-transactions? A: Yes! Recursive screen exploration + visual debugging discovers any SAP screen pattern.
Q: What LLM powers the agent? A: Currently using Claude (Anthropic) via LangChain, but architecture supports OpenAI, Azure, or local models.
📣What's Coming in Part 1?
- 🎥Live demo video (agent solving NR 751 in real-time)
- 🛠️ Step-by-step setup (5 minutes to first execution)
- 🔧Advanced patterns (Outlook integration, multi-session handling)
- 📈Scaling to production (error handling, logging, monitoring)
- 💻Full source code walkthrough
👍Like this post if you want Part 1 next week!
Share your SAP challenges in the comments below — which analysis blocks you most often?