UNPKG

major-ai-skills

Version:

Installable agentic skills / AI agent skills (SKILL.md) for Claude Code, Cursor, Codex CLI, Gemini CLI & Antigravity - 402+ professional app, token-efficiency, and common-sense skills. SEO/GEO ready.

153 lines (119 loc) 7.54 kB
--- title: "SAP GUI Desktop & Scripting Automation AI Skill Guide (GPT & Codex)" description: "Comprehensive operational skill specification for OpenAI GPT and Codex to automate, script, troubleshoot, and optimize SAP GUI Scripting API, VBScript/Python RPA generators, PyRFC, and GuiXT scripts." category: "SAP Desktop Client & Transaction Processing" tags: ["sap-gui", "sap-scripting-api", "vbs-automation", "pyrfc", "gpt-codex", "sap-rpa"] --- # SAP GUI Desktop & Scripting Automation AI Skill Guide (GPT & Codex) ## Overview & Engine Architecture SAP GUI provides an automation COM interface (**SAP GUI Scripting API**) and high-speed C-bindings (**SAP NetWeaver RFC / PyRFC**) for automated business transaction execution. GPT/Codex acts as a Principal SAP RPA Developer and Enterprise Integration Specialist, delivering **VBScript & Python SAP GUI scripts**, **PyRFC remote function call clients**, **GuiXT dynamic screen modifications**, and **automated mass data upload tools**. ### Developer Architecture & Scripting Object Model ``` ┌─────────────────────────────────────────────────────────────┐ SAP GUI Scripting API Model COM Object Model Hierarchy ├── `GuiApplication` (Root Scripting Engine Instance) └── `GuiConnection` (Active Connection to System) └── `GuiSession` (User Window Session) ├── `GuiMainWindow` (`wnd[0]`) ├── `GuiToolbar` / `GuiMenubar` ├── `GuiUserArea` (Screen Fields & Tabs) └── `GuiGridView` / `GuiTableControl` Native High-Speed Backend RFC Layer ├── SAP NetWeaver RFC SDK (`sapnwrfc.dll` / C-Bindings) └── Python `PyRFC` Connection Pool (`BAPI_...` Ingress) └─────────────────────────────────────────────────────────────┘ ``` --- ## Operational Capabilities & Agent Directives 1. **SAP GUI Scripting Automation (VBS/Python)**: Author clean, exception-guarded scripts using `session.findById()` to automate complex multi-screen transactions (`VA01`, `ME21N`, `FB50`). 2. **PyRFC Direct BAPI Integration**: Build high-performance Python scripts bypassing GUI overhead to call standard Business Application Programming Interfaces (`BAPI_MATERIAL_GET_DETAIL`, `BAPI_SALESORDER_CREATEFROMDAT2`). 3. **GuiXT Script Development**: Write GuiXT script files (`*.txt`) to simplify user screens, consolidate multi-tab workflows, and populate default transaction values. 4. **Mass Data Ingestion Pipelines**: Construct batch processing loops reading from CSV/Excel and updating SAP records with rollback safety. --- ## Production Python Automation: High-Speed PyRFC BAPI Sales Order Creator Save this script as `pyrfc_order_creator.py` (requires `pip install pyrfc` and SAP NW RFC SDK): ```python """ SAP NetWeaver RFC (PyRFC) Direct BAPI Integration Calls BAPI_SALESORDER_CREATEFROMDAT2 to create sales orders directly without GUI overhead. """ import sys from pyrfc import Connection SAP_CONFIG = { "user": "RFC_SERVICE_USER", "passwd": "SecureRFCPassword123!", "ashost": "sap-app-server.enterprise.io", "sysnr": "00", "client": "100", "lang": "EN" } def create_sales_order_via_bapi(cust_no: str, material: str, qty: float): print(f"Connecting to SAP NetWeaver RFC: {SAP_CONFIG['ashost']}...") try: conn = Connection(**SAP_CONFIG) except Exception as e: print(f"RFC Connection Error: {e}") return order_header = { "DOC_TYPE": "OR", # Standard Order "SALES_ORG": "1000", "DISTR_CHAN": "10", "DIVISION": "00" } order_partners = [ {"PARTN_ROLE": "AG", "PARTN_NUMB": cust_no} # Sold-To Party ] order_items = [ {"ITM_NUMBER": "000010", "MATERIAL": material} ] order_schedules = [ {"ITM_NUMBER": "000010", "REQ_QTY": qty} ] print(f"Invoking BAPI_SALESORDER_CREATEFROMDAT2 for Customer: {cust_no}...") result = conn.call( "BAPI_SALESORDER_CREATEFROMDAT2", ORDER_HEADER_IN=order_header, ORDER_PARTNERS=order_partners, ORDER_ITEMS_IN=order_items, ORDER_SCHEDULES_IN=order_schedules ) sales_document = result.get("SALESDOCUMENT") return_messages = result.get("RETURN", []) if sales_document: # Commit the transaction in SAP conn.call("BAPI_TRANSACTION_COMMIT", WAIT="X") print(f"✅ Success! Created SAP Sales Order: {sales_document}") else: print("🚨 BAPI Creation Failed. Return messages:") for msg in return_messages: if msg.get("TYPE") in ("E", "A"): print(f" [{msg.get('TYPE')}] {msg.get('MESSAGE')}") conn.close() if __name__ == "__main__": create_sales_order_via_bapi(cust_no="0000001000", material="MAT-100-200", qty=10.0) ``` --- ## Technical Troubleshooting Matrix | Issue & Failure Signature | Root Cause Analysis | Diagnostic & Resolution Pathway | | :--- | :--- | :--- | | **`session.findById() Fails: The control could not be found by id`** | Dynamic screen changed, modal popup dialog appeared, or timing latency between screen transitions. | 1. Check if `wnd[1]` (popup dialog) is active.<br>2. Add explicit wait loops or use `session.findById("wnd[0]").sendVKey(0)`.<br>3. Verify ID in SAP GUI Scripting Recorder. | | **PyRFC Fails: `RFC_COMMUNICATION_FAILURE: Connect to message server failed`** | Missing `sapnwrfc.dll` libraries in system `PATH` or firewall blocking RFC port 3300. | 1. Download SAP NW RFC SDK 7.50 $\rightarrow$ Add `lib` directory to system `PATH`.<br>2. Verify TCP port **3300** is open to SAP host. | | **`BAPI_TRANSACTION_COMMIT` Missing** | Database changes discarded at session close because explicit commit BAPI was omitted. | Always invoke `conn.call("BAPI_TRANSACTION_COMMIT", WAIT="X")` after successful creation BAPIs. | | **GuiXT Script Not Executing on Target Screen** | Script filename does not match Dynpro program and screen number convention (e.g. `sapmv45a.e0100.txt`). | Verify active screen number in SAP GUI by clicking *System $\rightarrow$ Status*. | --- ## Command Line Syntax & Batch Processing ```bash # Run Automated VBScript SAP GUI Script cscript //nologo C:\SAP_Scripts\CreateInvoices.vbs # Verify PyRFC Installation and Native SDK Version python -c "import pyrfc; print(pyrfc.__version__)" ``` ### Essential File Locations - **SAP NW RFC SDK**: `C:\nwrfcsdk\lib\` - **GuiXT Configuration**: `C:\Program Files (x86)\SAP\FrontEnd\SAPgui\GuiXT\guixt.ini` --- ## Agent Operational Directive > **MANDATORY**: When using PyRFC / BAPIs, always call `BAPI_TRANSACTION_COMMIT` with `WAIT="X"` to ensure transactional persistence. For SAP GUI Scripting, handle modal popup windows (`wnd[1]`) defensively.