SAP

A BDK Book containing automation procedures for SAP.

Overview

The SAP BDK Book integrates with SAP systems via OData v2 APIs. It enables users to discover available services and entities, retrieve and create records, and upload attachments—all using natural language commands.

Prerequisites

Learning the SAP Book (BDK)

Connectivity

This book supports connecting to the SAP OData v2 API using a base URL, username, and password. To establish a connection, provide the following details:

Label
Description
Type

Base URL

The base URL of the SAP OData API.

Text

Username

The username used for authentication.

Text

Password

The password associated with the user.

Text

Sample Workflow

//# 1. Load the book
learn "lambda://sap/2.1.0"

# 2. Connect to SAP
connect sap via a user password method
  the base url is "<url>"
  the username is "<username>"
  the password is "<password>"

# 3. Explore available services
retrieve some services from sap

# 4. Explore entities in a service
retrieve some entities from sap
  the api service is "API_SALES_ORDER_SRV"

# 5. Discover the entity you want to work with
discover "API_SALES_ORDER_SRV/A_SalesOrder" from sap

# 6. Retrieve existing records
retrieve some ASalesOrder records from sap
  the limit is 10

# 7. Create new data structure
imagine the items
create a json
use the above as the item
the item's "Material" is "TG11"
the item's "RequestedQuantity" is "2"
the item's "RequestedQuantityUnit" is "EA"
add the item to the items

# 8. Create the main record data
create a json
use the above as the body
the body's "SalesOrderType" is "OR"
the body's "SalesOrganization" is "1710"
set the body's "to_Item" to the items
the body's "DistributionChannel" is "10"
the body's "OrganizationDivision" is "00"
the body's "SoldToParty" is "17100002"
the body's "PurchaseOrderByCustomer" is "test-po-2.1.0-ONE"

# 9. Create the record in SAP
create a ASalesOrder record in sap
  the body is the body

# 10. Update the created record
use the above as the created order
set the created order's "PurchaseOrderByCustomer" to "test-po-2.1.0-TWO"

update a ASalesOrder record in sap
  the body is the created order

Tips for Success

Entity Names

  • After discovery, entity names are normalized for easier use

  • A_SalesOrder becomes ASalesOrder

  • C_MfgQualifnCertBPAssgmt becomes CMfgQualifnCertBPAssgmt

Working with Data

  • Use create a json to build data structures

  • Use use the above as [variable] to reference previous results

  • Use set the [variable]'s "[field]" to "[value]" to modify data

  • Use add the [item] to the [list] to build arrays

Common Patterns

  • Always connect before using any other procedures

  • Explore services and entities before discovering

  • Build your data structure before creating records

  • Save created records to variables for later updates

Error Prevention

  • Make sure all required fields are included when creating records

  • Include the id field when updating records

  • Check field names match exactly what SAP expects

Troubleshooting

Connection Issues

  • Verify the base URL is correct and accessible

  • Check that the username and password are valid

  • Ensure you have proper permissions for the SAP services

Discovery Issues

  • Make sure the service name and entity name are exactly as shown in the entities list

  • Use the exact format: "SERVICE_NAME/ENTITY_NAME"

Create/Update Issues

  • Ensure all required fields are provided

  • Check that field names match SAP's expectations

  • Verify data types are appropriate for each field

  • For updates, make sure the record ID is included

Data Issues

  • Use the retrieve procedure to see the expected data format

  • Check that related entities (like line items) are structured correctly

  • Verify that reference values (like customer numbers) exist in SAP

Last updated

Was this helpful?