Skip to main content

Automate SAP data extraction, SharePoint upload, and Excel macro execution

Project description

SAP Automation

What is this?

We regularly need to pull data from SAP, format it as Excel, and upload it to SharePoint. Doing this manually is slow and repetitive. These scripts automate the entire process so you can run a single Python file and have the data extracted, saved, and uploaded automatically.

Who is this for?

Anyone who needs to extract SAP reports on a recurring basis. You do not need to be a programmer. The templates are designed so you only need to:

  1. Record your SAP steps (SAP has a built-in script recorder)
  2. Paste the recording into the template
  3. Fill in a few settings (transaction code, file paths)
  4. Run the script

How it works

The scripts follow this workflow:

  1. Open SAP and connect to PR1
  2. Run your recorded SAP transaction (fill in fields, execute report, click export)
  3. Save the exported file locally
  4. Read the file into memory
  5. Copy a checked-in Excel template from SharePoint, write the data into it, and save it back to SharePoint
  6. Clean up temporary files

The "checked-in file" is an .xlsx template that lives in a SharePoint folder. You specify the path to this template in your script. The scripts copy it, fill it with your data, and save the result as a new file in your destination folder. This ensures every upload has consistent formatting.

Folder Structure

SAP_Automation/
├── functions/     Core modules that do the actual work (you don't edit these)
├── templates/     Starter scripts you copy and customize for each SAP transaction
└── tools/         Utilities like the transaction checker

Templates

SAP Pipeline (template_sap_pipeline.py)

The main template. Handles the full workflow: connect to SAP, run your transaction, export data, upload to SharePoint.

df = run_extract(sap_script,
    transaction="ZSUPVENG",
    export_format="xlsx",
    template_path=r"Z:\path\to\TEMPLATE_DO_NOT_DELETE.xlsx",
    sharepoint_folder=r"Z:\path\to\your_sharepoint_folder",
)

How to use:

  1. Copy this template and rename it (e.g. ZSUPVENG.py)
  2. Paste your SAP recording into the sap_script() function
  3. Set transaction to your transaction code
  4. Set template_path to the full path of your checked-in .xlsx template file
  5. Set sharepoint_folder to where you want the output file saved
  6. Run the script

SharePoint Upload (template_sharepoint_upload.py)

Uploads any data to SharePoint as a formatted Excel file. No SAP needed. Useful when you already have data in a file or DataFrame and just want to push it to SharePoint.

result = save_excel_to_sharepoint(df,
    template_path=r"Z:\path\to\TEMPLATE_DO_NOT_DELETE.xlsx",
    sharepoint_folder=r"Z:\path\to\your_sharepoint_folder",
    output_filename_prefix="MyReport_2026-01-01",
)

Excel Macros (template_excel_macro.py)

Opens an Excel workbook and runs VBA macros by name.

run_excel_macro(
    file_path=r"Z:\path\to\your_workbook.xlsm",
    macro_name="MyMacro",
    module_name="Module1"
)

Core Modules (functions/)

These are the building blocks. You don't need to edit these files.

File What it does
sap_extract.py The main engine. Connects to SAP, runs your recording, handles the save dialog, reads the file, uploads to SharePoint
sap_connection.py Opens SAP GUI, connects to PR1, handles popups like "Multiple Logon"
sharepoint_upload.py Copies the checked-in template, writes your data into it, saves it to SharePoint
excel_macro.py Opens an Excel file and runs a VBA macro

Export Formats

Your SAP recording should include the export menu clicks (right-click, select format, etc.). The export_format setting just tells the engine what file type to expect so it can handle the save dialog correctly.

Format What the engine does
"txt" Fills in the save dialog, reads the tab-delimited text file
"xlsx" Fills in the save dialog, waits for the file, closes the Excel window SAP opens
"clipboard" No save dialog needed, reads directly from clipboard

Tools

Transaction Checker (tools/check_transactions.py): Scans all your scripts for SAP transaction codes, then connects to SAP and verifies each one opens successfully. Run it with check_transactions.bat.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

process_automation-1.0.3.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

process_automation-1.0.3-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file process_automation-1.0.3.tar.gz.

File metadata

  • Download URL: process_automation-1.0.3.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for process_automation-1.0.3.tar.gz
Algorithm Hash digest
SHA256 18bf75a3a2a39ec98a9b26d94092b6bf07492d9a66fb98ff07d0ccbdbee3f9db
MD5 9530343c06407beb940b54516b497a51
BLAKE2b-256 b8d9cc7515df035cc8baf4d8db745a00a22188ec8bf75e0e53d4e16eece53f85

See more details on using hashes here.

Provenance

The following attestation bundles were made for process_automation-1.0.3.tar.gz:

Publisher: publish.yml on Mircea-Sava/process-automation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file process_automation-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for process_automation-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d5deb9f227cbf0b128c455b5025097553032164e7d54f92ef5d884f5b28743b2
MD5 e9fa416edd48977fed345520e7b6f94c
BLAKE2b-256 d35fc8dbc2444830206eb9b2216073fb5cf78b2b1431f07cb71976d6f6f5876f

See more details on using hashes here.

Provenance

The following attestation bundles were made for process_automation-1.0.3-py3-none-any.whl:

Publisher: publish.yml on Mircea-Sava/process-automation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page