SAP MB5B Export
Use the bundled Python workflow. Do not recreate the SAP automation with VBS or PowerShell.
Required Workflow
- Read references/environment.md before the first run on a machine or after an SAP GUI or Windows upgrade.
- Run
scripts/check_environment.pywith the input workbook. Add--require-sapbefore a live run. - Run
scripts/mb5b_export.pywith--dry-runand review all individual and merged output paths. - On a new SAP GUI language, version, theme, or Windows scale, run a live
--limit 1test before processing all rows. - Run the complete export only after the one-row file has the expected filename and
Data!D1header. - Report exit code
2as partial success and use the log to identify failed plant/storage pairs.
Commands
python scripts/check_environment.py --input "<LOCAL_WORKSPACE>\保管場所.xlsx" --require-sap
python scripts/mb5b_export.py `
--input "<LOCAL_WORKSPACE>\保管場所.xlsx" `
--date 2026-02-28 `
--dry-run
python scripts/mb5b_export.py `
--input "<LOCAL_WORKSPACE>\保管場所.xlsx" `
--date 2026-02-28 `
--limit 1
Pass --overwrite only when the user explicitly permits replacing existing individual and merged files. Use --output-dir to keep test exports separate from production files.
Language Independence
- Use SAP technical control IDs and Windows control structure only.
- Never add window-title, button-label, translated-message, OCR, or fixed-coordinate matching to execution logic.
- Treat labels as diagnostic data only.
- Stop on an ambiguous multi-button dialog. Do not guess which action means allow, save, or overwrite.
- Use
--inspect-ui --output-dir <directory>passively while the user has the unsupported dialog open. This writes screenshots and a control-tree JSON without clicking anything. - Preserve the one-submit-per-state rule. Do not retry clicks in a loop.
Output Contract
- Individual:
MB5B_<plant>_<storage>_<YYYYMMDD>.xlsx - Merged:
MB5B_<plant>_<YYYYMMDD>.xlsx - Insert column D when needed, set
D1to the configured storage header, and fill data rows with the target storage code. - Keep one header row in each plant merge and append only successful individual files in input order.
- Return
0for full success,1for preflight/startup failure, and2for partial export or merge failure.
Do not bulk-delete files or directories. Keep runtime logs and diagnostics local and out of source control.