SAP on Power

SAP on Power

IBM Power servers are purpose built for data-intensive applications such as SAP HANA and S/4HANA that require large amounts of in-memory computing but still let you maintain the high availability and flexibility required for your hybrid cloud. 


#Power
#TechXchangeConferenceLab
 View Only

watsonx.ai Integration with SAP S/4HANA® on IBM Power Virtual Server (5/6): Using watsonx.ai Studio to leverage SAP S/4HANA® data

By Sofia Gutierrez posted yesterday

  

This is part 5 of the technical guidance series, “watsonx.ai Integration with S/4HANA® on PowerVS.”

This blog provides an example of using the foundation models available on IBM watsonx.ai® studio to run OData queries against an SAP S/4HANA® system and return answers based on the application data. This setup authenticates to SAP S/4HANA® from a Jupyter notebook running on the watsonx.ai python runtime, and prompts an LLM to formulate user-facing answers from OData query results. Read the code on a sample Notebook right next to this article.

Setting up a watsonx.ai project and Notebook

This example requires an IBM Cloud API key to authenticate to watsonx.ai and access foundation models. Log into the watsonx platform at https://dataplatform.cloud.ibm.com/auth/iamid/login?context=wx and create a new project. Then go to assets and add a Parameter Set from the Prepare data tab.

Add a name and description to the set and create string parameters for the OData Endpoint URL, and the S/4HANA credentials to the user configured to use the OData service.

Then create a Jupiter Notebook from the New Asset tab, add a name and pick the desired runtime.

Open the new notebook and install the watsonx.ai Python SDK. Initialize the client with the URL endpoint that matches the region your watsonx resource resides in. Then load the project or space ID that provides access to the project-scoped resources and parameters. To manage or create a watsonx API key navigate to https://cloud.ibm.com/iam/apikeys. Do not forget to copy and save your API key in a secure location as soon as you create it. For security reasons, an API key is visible only immediately after creation.

Then load the parameters defined on the project

Build the model prompt and run the chat

The language model should receive a user question and decide which information needs to be retrieved from the database in order to answer. The prompt includes instructions on how to write URL calls to the OData service. Initially fetch the OData metadata document to discover entity types and properties. This information guides future queries by adding some context for the model to work with, and is passed to the LLM directly as part of the prompt. Test the HTTP request and format the metadata string to include the Entity Sets, Fields, and Data Types on each available collection.

Then choose a model from the foundation model library. The instruction prompt must explain how to create queries correctly for OData v2. We initialized two Model Inference instances: one for creating queries, and another for processing the output and writing the answers. The query generating model receives the following prompt template for processing user queries.

You are an expert in OData v2 query generation. Translate the given natural-language question into a single valid OData v2 query URL for the service described below. Your output must be only the complete OData URL — no markdown, no quotes, and no explanations [...]

Rules for Query Construction:

  1. Use only OData v2 system query options: $filter, $select, $orderby, $top, $skip. 

    Do not use $apply, groupby(), aggregate(), or any OData v4 features.

  2. Respect data types:

    • Edm.String → wrap values in single quotes ('value')

    • Edm.DateTime → use UTC ISO8601 format ('YYYY-MM-DDT00:00:00')

    • Edm.Decimal → use plain numeric format (no quotes)

    • Edm.Int32 → use integer (no quotes)

    • Edm.Boolean → use lowercase true or false (no quotes)

    • Never omit quotes for string fields, even if they look numeric (e.g. '30')

  3. Syntax rules:

    • Combine multiple filters with 'and' or 'or'

    • Use valid comparison operators: eq, ne, gt, ge, lt, le

    • Use entity set and field names exactly as shown in the metadata

    • Do not infer relationships or modify property names

  4. Output format:

    • Return exactly one complete OData v2 URL starting with {base_url}

    • No extra spaces, markdown, or explanations

    • The URL must be syntactically correct and complete

  5. Aggregation:

    • If the question requests totals, averages, or similar, return a query that retrieves the raw rows needed for that aggregation

    • Do not perform aggregation within the OData query

  6. Defaults:

    • If $select is not mentioned in the question, return all fields

    • Use $top=100 if the question implies a sample or recent records without specifying a limit

You can use a second call to the model or a separate one to run the summarizing prompt that takes the question and the OData query result. This is how the output to a user question should look like. 

0 comments
24 views

Permalink