Skip to main content
Version: 10.3

Create and post incoming invoice in SAP

Problem statement

Many companies use ERP systems to manage their financials, logistics, human resources, and so on. SAP is one of the most known ERP systems in the world. The larger the company is, the greater is the need to use some system to manage company resources. Working in SAP takes a lot of time on different work levels. Thus, automation of this job will save time to focus on other tasks.

Existing manual process

Usually, to create and post invoices in SAP, a worker needs to open the application, log in, and enter all the required fields like Invoice Date, Posting Date, Amount, and others manually, which takes much time.

Automation solution

The example allows working with MIRO transactions in the SAP GUI desktop client by just starting it. The bot opens the client, logs in, fills in all required fields, and posts the invoice. As the result, a lot of time will be saved.

Reusable components

In this example, there are three reusable components:

  • Calculate the current date and convert it to a string.
  • Log in to the SAP GUI desktop client.

Example overview video

Preconditions

Before you start working, ensure all the requirements are met:

  1. Install:
    • Work.AI Developer
    • SAP GUI v. 7.40-7.50 connected to the environment
  2. Download the example.

Getting started

To get started, perform the following actions:

  1. Extract the sample folder and drop it into your default workspace in Recorder: C:/Users/username/workfusion-workspace/rpae_project.
  2. Open the sample in Recorder.
  3. Go to Window > Preferences, expand WorkFusion Recorder, and select the Secrets Vault tab.
  4. Press the Add button and enter SAP_creds as Alias. Enter the SAP username in the Key column and the SAP password–in Value.
  5. Press Apply and Close.
  6. Edit the following variables:
    • sap_path: the path to saplogon.exe
    • company_code
    • amount
    • purchase_order
    • quantity
  7. Click Play recording.

Script overview

On a high level, the script consists of the following actions.

  1. Open and log in to the SAP GUI desktop client.
  2. Find the MIRO transaction and enter the company code.
  3. Create an invoice and fill in all required fields.
  4. Post the invoice.

Let's explore these steps in detail.

Environment

Script variables

Variable nameTypeDescriptionDefault value
ok_codeStringTransaction codeMIRO
company_codeStringCompany code (needs to be set up before running the script)
amountStringAmount of money in the invoice (needs to be set up before running the script)
purchase_orderStringInvoice purchase order (needs to be set up before running the script)
loginSecretSAP username (needs to be set up before running the script)
passwordSecretSAP password (needs to be set up before running the script)
quantityStringQuantity of items in the invoice (needs to be set up before running the script)
current_dateDateTimeCurrent date
invoice_dateStringCurrent date converted to a string
transaction_typeStringRequired to choose the right transaction typeInvoice
sap_pathStringPath to saplogon.exe (needs to be set up before running the script)C:/Program Files (x86)/SAP/FrontEnd/SAPgui/saplogon.exe

Script workflow

Calculate current date

Description: The group calculates the current date and converts it to string.

  1. In the Constant Value action (reusable), the bot pushes the current date to the current_date variable.

  2. In the Date Format action, the bot converts the current_date variable into the invoice_date String variable with a specific format:

Log in to SAP GUI

Description: The group opens SAP GUI and logs into it.

tip

To reuse the group, make sure you added the required SAP GUI credentials in Secrets Vault in the Recorder's preferences. If you add another Secrets Vault entry, change the following variables:

  • login: SAP GUI username (Secrets Vault > Key)
  • password: SAP GUI password (Secrets Vault > Value)

Log in to SAP GUI (reusable). In this group, the bot launches SAP GUI using Launch Application, clicks the Log on button (Click Mouse) in a specific window (Window), and pastes credentials into the required fields (Enter Keystrokes).

Create and post incoming invoice

Description: The group allows opening the MIRO transaction for a specific company, filling in all required invoice fields, and posting into the system.

  1. Create and post an incoming invoice (reusable). The group of actions (Window, Click Mouse, Enter Keystrokes) opens the MIRO transaction for a specific company.

  2. The group of actions (Window, Enter Keystrokes, Click Mouse, Wait) fills in all required invoice fields (Invoice date, Amount, Purchase Order), clicks the Simulate button, and waits for the Simulate window to open.

  3. The Window and Click Mouse actions post the invoice into the SAP system.