Project 5 — Advanced
SAP Data Entry Bot
SAP me vendor master, purchase orders, invoice entry — sab manually. Ek batch entry me 40 minute. Is project me bot banayenge jo Excel se data leke SAP GUI me transactions post kare — element IDs se, error status bar se alert ke saath.
Project kya karega?
WHAT
Bot Excel file padhega (vendor details ya PO data), SAP Logon kholkar session attach karega, transaction code run karega (jaise XK01 vendor creation), har field me data type karega, post karega, aur status bar check karega — success ya error, dono log honge. Errors wali rows ek error report me jayengi.
WHEN
SAP ERP wali koi bhi company — manufacturing, pharma, FMCG, automobiles. SAP data entry repetitive hai aur costly (SAP consultant time = expensive). RPA + SAP = India me sabse high-paying automation niche.
WHERE
Enterprise shared services (TCS, Infosys, Wipro ke SAP automation teams), Fortune 500 ke in-house CoEs. "SAP automation UiPath" job listings me salary 30-50% zyada hoti hai plain RPA se.
Step-by-step build
Main.xaml (Sequence)
|
+-- Try Catch
| +-- SAP Logon (system: in_System) -> session
| +-- Assign: session.findById("wnd[0]/tbar[0]/okcd").Text = "XK01"
| +-- Assign: session.findById("wnd[0]").SendVKey 4 (Enter)
| +-- Read Excel in_File -> dtVendors
| +-- For Each row in dtVendors
| +-- Try Catch (per row - ek row fail ho to batch na ruke)
| +-- Assign: session.findById("wnd[0]/usr/ctxtLFA1-LIFNR").Text = row("VendorCode")
| +-- Assign: session.findById("wnd[0]/usr/txtLFA1-NAME1").Text = row("VendorName")
| +-- Assign: session.findById("wnd[0]/usr/ctxtLFA1-STCD1").Text = row("GSTIN")
| +-- Assign: session.findById("wnd[0]").SendVKey 0 (Validate/Enter)
| +-- Assign: strStatus = session.findById("wnd[0]/sbar").Text
| +-- If strStatus.Contains("Error") OR strStatus.Contains("exists")
| | +-- Write Row: [row, strStatus, "FAILED"]
| | +-- session.findById("wnd[0]/tbar[0]/btn[3]").Press() (Back - cancel)
| +-- Else
| | +-- session.findById("wnd[0]/tbar[0]/btn[11]").Press() (Save)
| | +-- Write Row: [row, "Posted", "OK"]
| +-- Catch (Exception)
| +-- Log Message LogLevel.Error ex.Message
| +-- Write Row: [row, ex.Message, "EXCEPTION"]
| +-- Write Range dtResult "C:\Output\SAP_Result_" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx"
SAP selectors = Element IDs
SAP GUI me web jaise CSS selectors nahi hote — Element ID hote hain. Inko UI Explorer se nikalte ho:
# Field element IDs (SAP scripting):
wnd[0]/tbar[0]/okcd - Transaction code box
wnd[0]/usr/ctxtLFA1-LIFNR - Vendor code field (ctxt = dropdown field)
wnd[0]/usr/txtLFA1-NAME1 - Vendor name (txt = text field)
wnd[0]/usr/ctxtLFA1-LAND1 - Country dropdown
wnd[0]/sbar - Status bar (success/error message)
wnd[0]/tbar[0]/btn[11] - Save button
wnd[0]/tbar[0]/btn[3] - Back/Cancel
# UI Explorer se exact ID nikalo - naad manual type karo na guess
# Tab order: SendVKey 0 = Enter (field validate + next screen)
Error handling — status bar is truth
- SAP error message: Status bar (wnd[0]/sbar) me error/text hota hai — always read karo before Save. Message type bhi milta hai (Success/Error/Warning).
- Screen change: Valid entry pe screen badal jata hai — element ID change ho sakta hai. "Element exists" se screen verify karo step ke baad.
- Duplicate vendor code: SAP khud error dega "already exists" — status bar se catch karke skip karo.
- Per-row Try Catch: 500 rows me 1 fail = baaki 499 process honi chahiye. Row-level isolation mandatory.
Enterprise tips
- SAP GUI scripting ON/OFF policy centralized hoti hai — service account me scripting permission check karo.
- Ek SAP user parallel me do sessions nahi khulta transactions ke liye — Orchestrator me concurrency 1 rakho. Multi-process chahiye to alag SAP service accounts.
- Test client (QAS) pe pehle run karo, Production (PRD) kabhi test mat karo.
- BAPI/RFC based automation (bypass GUI) enterprise me preferred hai — lekin GUI automation legacy systems ka backbone hai. Dono aane chahiye.
Exercise
Question: SAP status bar (success/error message padhne wale) ka element ID path? (Format: wnd[0]/... )
Question: SAP me Save (post) karne wale button ka element ID? (Format: btn[...])
Common mistakes
- Status bar na padhna: Bot save dabata rahega, SAP error dikhata rahega — data loss. Always check sbar.
- Fixed delays (Sleep) har field pe: Slow chalega. Element waits (element exists + timeout) better hain.
- Production pe test: QAS client pe validate karo PRD kabhi nahi.
- Concurrency ignore: 3 robots ek SAP account pe = lock errors. Account-per-robot mapping.
Project ban gaya? Ab next project pe chalte hain — REST API + JSON + Database Bot.