SAP Joule for Developers, ABAP AI Capabilities is your intelligent coding companion, bringing deep expertise in ABAP Cloud and AI-driven development. When we talk about ABAP AI use cases, they revolve around three key pillars — Accelerate, Empower, and Transform. Each AI capability is delivered as part of these pillars, helping developers enhance productivity, build smarter applications, and drive innovation. To learn more about SAP Joule for Developers, refer to the blog post Joule speaks ABAP! by Dr. Alexander Rother.
Have you ever wondered how to infuse intelligence into your ABAP-based business applications and move beyond standard transactional scenarios? If yes, you’ve landed at the right place. In this blog, we’ll explore how you can build AI-enabled applications using the ABAP AI SDK powered by Intelligent Scenario Lifecycle Management (ISLM), the main deliverable of the Empower use case.
The Scenario
The goal of this scenario is to infuse generative AI into an ABAP Cloud application to enhance user experience and automate content creation.
Use Case: Build an ABAP Cloud application to generate a travel itinerary for a given city based on user input, along with a budget breakdown, using ABAP AI SDK powered by ISLM.
Which products are supported?
The ABAP AI SDK powered by ISLM is available in:
Overview
To build this application, we’ll bring together several key components:
Implementation Steps
1. Set Up the Environment
2. Create a custom ABAP Cloud Application to infuse AI Capabilities
2.1 Create Package
2.2 Create database table
Create a database table to store the Travel Itinerary data.
@EndUserText.label : 'Database table for travel Itinerary'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zrap_travel_data {
key client : abap.clnt not null;
key travel_id : sysuuid_x16 not null;
traveler_name : abap.char(80);
starting_point : abap.char(100);
destination : abap.char(100);
start_date : /dmo/begin_date;
end_date : /dmo/end_date;
@Semantics.amount.currencyCode : 'zrap_travel_data.budget_curr'
budget : abap.curr(15,2);
budget_curr : abap.cuky;
transport_mode : abap.char(40);
accommodation_type : abap.char(50);
ai_itinerary : abap.sstring(1333);
ai_budget_breakdown : abap.sstring(1000);
status : abap.char(20);
local_created_by : abp_creation_user;
local_created_at : abp_creation_tstmpl;
local_last_changed_by : abp_locinst_lastchange_user;
local_last_changed_at : abp_locinst_lastchange_tstmpl;
last_changed_at : abp_lastchange_tstmpl;
} 5. Save and activate
the changes in the table ZRAP_TRAVEL_DATA
2.3 Generate transactional UI service
Create your OData V4-based UI service with the built-in ADT generator. The generated business service will be transactional, draft-enabled, and enriched with UI semantics for the generation of the SAP Fiori elements app.
2.4 Adjust meta data extensions
Open the metadata extension ZC_RAP_TRAVEL_DATA and make the adjustments as shown in the provided code snippet. ZC_RAP_TRAVEL_DATA should look like this:
@Metadata.layer: #CORE
@UI.headerInfo.title.type: #STANDARD
@UI.headerInfo.title.value: 'TravelID'
@UI.headerInfo.description.type: #STANDARD
@UI.headerInfo.description.value: 'TravelID'
annotate view ZC_RAP_TRAVEL_DATA with
{
@ui.facet: [
{ label: 'General Information', id: 'GeneralInfo', purpose: #STANDARD, position: 10, type: #IDENTIFICATION_REFERENCE },
{ label: 'AI Generated Itinerary', id: 'AIItineraryFacet', purpose: #STANDARD, position: 200, type: #FIELDGROUP_REFERENCE, targetQualifier: 'AI_ITIN' },
{ label: 'AI Budget Breakdown', id: 'AIBudgetFacet', purpose: #STANDARD, position: 210, type: #FIELDGROUP_REFERENCE, targetQualifier: 'AI_BUDGET' }
]
@EndUserText.label: 'TravelID'
@ui.identification: [ { position: 10, label: 'TravelID' } ]
@ui.lineItem: [ { position: 10, label: 'TravelID' } ]
@ui.selectionField: [ { position: 10 } ]
TravelID;
@EndUserText.label: 'TravelerName'
@ui.identification: [ { position: 20, label: 'TravelerName' } ]
@ui.lineItem: [ { position: 20, label: 'TravelerName' } ]
@ui.selectionField: [ { position: 20 } ]
TravelerName;
@EndUserText.label: 'StartingPoint'
@ui.identification: [ { position: 30, label: 'StartingPoint' } ]
@ui.lineItem: [ { position: 30, label: 'StartingPoint' } ]
@ui.selectionField: [ { position: 30 } ]
StartingPoint;
@EndUserText.label: 'Destination'
@ui.identification: [ { position: 40, label: 'Destination' } ]
@ui.lineItem: [ { position: 40, label: 'Destination' } ]
@ui.selectionField: [ { position: 40 } ]
Destination;
@ui.identification: [ { position: 50 } ]
@ui.lineItem: [ { position: 50 } ]
@ui.selectionField: [ { position: 50 } ]
StartDate;
@ui.identification: [ { position: 60 } ]
@ui.lineItem: [ { position: 60 } ]
@ui.selectionField: [ { position: 60 } ]
EndDate;
@EndUserText.label: 'Budget'
@ui.identification: [ { position: 70, label: 'Budget' } ]
@ui.lineItem: [ { position: 70, label: 'Budget' } ]
@ui.selectionField: [ { position: 70 } ]
Budget;
@EndUserText.label: 'TransportMode'
@ui.identification: [ { position: 80, label: 'TransportMode' } ]
@ui.lineItem: [ { position: 80, label: 'TransportMode' } ]
@ui.selectionField: [ { position: 80 } ]
TransportMode;
@EndUserText.label: 'AccommodationType'
@ui.identification: [ { position: 90, label: 'AccommodationType' } ]
@ui.lineItem: [ { position: 90, label: 'AccommodationType' } ]
@ui.selectionField: [ { position: 90 } ]
AccommodationType;
// FULL-WIDTH AI ITINERARY
@EndUserText.label: 'Generated Itinerary'
@ui.fieldGroup: [ { qualifier: 'AI_ITIN', position: 10, label: 'AI Generated Itinerary' } ]
@ui.multiLineText: true
AiItinerary;
// FULL-WIDTH AI BUDGET
@EndUserText.label: 'Budget Breakdown'
@ui.fieldGroup: [ { qualifier: 'AI_BUDGET', position: 10, label: 'AI Budget Breakdown' } ]
@ui.multiLineText: true
AiBudgetBreakdown;
@EndUserText.label: 'Status'
@ui.identification: [ { position: 120, label: 'Status' } ]
@ui.lineItem: [ { position: 120, label: 'Status' } ]
@ui.selectionField: [ { position: 120 } ]
Status;
@EndUserText.label: '_BaseEntity'
@ui.identification: [ {
position: 180 ,
label: '_BaseEntity'
} ]
@ui.lineItem: [ {
position: 180 ,
label: '_BaseEntity'
} ]
@ui.selectionField: [ {
position: 180
} ]
_baseentity;
}2.5 Preview travel app
1. Publish the local service endpoint of your service binding and start the Fiori elements App Preview. Open your service binding ZUI_RAP_TRAVEL_DATA_O4 and choose Publish.
2. Double-click on the Entity ZC_RAP_TRAVEL_DATA in the Entity Set and Association section to open the Fiori elements App Preview.
For reference: Create Database Table and Generate UI Service | SAP Tutorials
You first need to create an intelligent scenario for your custom Generative AI use cases. This scenario acts as the central place to manage the entire lifecycle of your AI asset from setup to generating inference results. All lifecycle steps can be executed through the Intelligent Scenario Management app. Here are the key steps to create an intelligent scenario:
3.1 Create ISLM Scenario
An intelligent scenario is an ABAP representation of a predictive business-specific use case. These intelligent scenarios are AI-powered workflows or processes designed to automate and optimize business tasks.
Intelligent Scenario Lifecycle Management supports two primary types of intelligent scenarios:
Embedded Scenarios
Embedded scenarios are built and executed within SAP S/4HANA using the ABAP platform. They rely on the in-database machine learning capabilities of SAP HANA, such as: HANA Predictive Analysis Library (PAL), Automated Predictive Library (APL)
Side-by-Side Scenarios
Side-by-side scenarios, where SAP S/4HANA runs in a separate stack than its machine learning infrastructure provider, such as SAP Business Technology Platform (SAP BTP). These scenarios use external ML services or custom ML models.
Generative AI, SAP AI Core, Data Attribute Recommendation
Field | Value |
Intelligent Scenario Type | SAPGENAI |
Automate Turnkey Switch On | Check the checkbox |
Usage Type | CUSTOMER |
3.2 Create ISLM Model
1. Select your package, right-click, New → Other → Intelligent Scenario Model
2. Fill the Description and Model Name fields. Assign the previously created scenario in Intelligent Scenario Name. Choose Next.
3. Enter the ExecutableID and Large Language Model Name and Large Language Model Version
Field | Possible values |
Executable Id | o aicore-sap o aws-bedrock o azure-openai o gcp-vertexai |
Large Language Model Name | It depends on the Executable Id |
Large Language Model Version | One option is to leave the version field free, then the latest version will be used. This helps to avoid issues in case that the model has been deprecated in AI Core |
4. Through the Prompt Library API, we can use predefined prompt templates to generate new prompts. Currently prompt templates are defined through ISLM. To get an instance of the prompt template you want to use, you need to provide the ISLM scenario and the ID of the prompt template. Click on Add and provide the following details:
Prompt Template Name: SYSTEM_PROMPT_ITIN
Prompt Template: System prompt for generating Itinerary
Prompt: You are a professional travel planner. Create a {ISLM_days} day itinerary for a given destination, including daily highlights, must-visit spots and activities. Keep it under 1000 characters.
5. The Prompt Parameters is captured from the prompt template after activation.
6. Add another prompt template for User prompt:
Prompt Template Name: USER_PROMPT_ITIN
Prompt Template: User prompt template
Prompt: Destination: {ISLM_destination} Departure: {ISLM_startingpoint} Travel Dates: {ISLM_startdate} to {ISLM_enddate} Mode of Transport: {ISLM_transportmode} Accommodation Type: {ISLM_accommodationtype} Generate the itinerary now
7. Activate the object
⚠ WARNING : Before you try the ABAP AI SDK out in an ABAP Class, please make sure that the deployment is running.
3.3 In Fiori Launchpad
To use the Intelligent Scenarios and Intelligent Scenario Management apps, you must have the appropriate access rights to the SAP Fiori Launchpad. The access for ISLM is added to the business role of an analytics specialist; BR_ANALYTICS_SPECIALIST.
You can create and manage ISLM Scenarios through Intelligent Scenario Management app.
You can check your previously created scenario in the Intelligent Scenario Management Fiori App.
In the next step instantiate ABAP AI SDK using the created ISLM Scenario
3.4. Consume Intelligent Scenarios in ABAP
ABAP AI SDK
The ABAP AI SDK powered by Intelligent Scenario Lifecycle Management (ISLM) is an ABAP reuse library that supports you in interacting with large language models (LLMs) hosted on the generative AI hub in SAP AI Core. Using the ABAP AI SDK, you can build your own AI-based features in ABAP.
Completion API
This API provides access to the completion API functionality of Large Language Models (LLMs), meaning that it uses an LLM to generate a text response from a prompt.
Prompt Library API
Using the prompt library API, you can use prompt templates predefined via ISLM to generate new prompts.
Catchable Exceptions
The execution of the completion API may cause an error, and therefore, CX_AIC_COMPLETION_API can be caught as a result. When the error is triggered by the LLM itself or by the AI service provider, CX_AIC_COMPLETION_API provides further information about the error.
Add a determination to the Travel Business Object and enhance it with the ABAP AI SDK powered by ISLM. Define the determination generateAIItinerary in the behavior definition ZR_RAP_TRAVEL_DATA and implement it in the behavior implementation class, aka behavior pool ZBP_R_RAP_TRAVEL_DATA.
1. Add the mandatory fields. Go to the Project Explorer and open your behaviour definition ZR_RAP_TRAVEL_DATA.
field ( readonly )
TravelID,
Status,
AiBudgetBreakdown,
AiItinerary,
LocalCreatedBy,
LocalCreatedAt,
LocalLastChangedBy,
LocalLastChangedAt,
LastChangedAt;
field ( mandatory : create )
TravelerName,
EndDate,
StartDate,
Budget,
AccommodationType,
StartingPoint,
TransportMode,
Destination;
determination generateAIItinerary on modify { create; } Define the generateAIItinerary determination:
METHOD generateAIItinerary.
LOOP AT keys INTO DATA(ls_key).
READ ENTITIES OF zr_rap_travel_data IN LOCAL MODE
ENTITY ZrRapTravelData
FIELDS ( destination startdate enddate transportmode accommodationtype BudgetCurr ) WITH CORRESPONDING #( keys )
RESULT DATA(lt_travel).
LOOP AT lt_travel INTO DATA(ls_travel).
DATA(days) = ls_travel-enddate - ls_travel-startdate + 1.
DATA(itinerary) = ``.
DATA(budget) = ``.
IF ls_travel-AiItinerary IS INITIAL OR ls_travel-AiBudgetBreakdown IS INITIAL.
TRY.
*Calling the Prompt Library API.Through the Prompt Library API, we can use predefined prompt templates to generate new prompts.
FINAL(sys_prompt_template_instance) = cl_aic_islm_prompt_tpl_factory=>get( )->create_instance(
islm_scenario = 'ZINTS_RAP120' template_id = 'SYSTEM_PROMPT_ITIN' ).
" Add a system prompt based on an ISLM prompt template with one parameter
FINAL(sys_prompt) = sys_prompt_template_instance->get_prompt( parameters = VALUE #( ( name = 'ISLM_days' value = days ) ) ).
" Add a user prompt based on an ISLM prompt template with parameters
FINAL(user_prompt_template_instance) = cl_aic_islm_prompt_tpl_factory=>get( )->create_instance(
islm_scenario = 'ZINTS_RAP120' template_id = 'USER_PROMPT_ITIN' ).
FINAL(user_prompt) = user_prompt_template_instance->get_prompt( parameters = VALUE #(
( name = 'ISLM_startdate'
value = |{ ls_travel-startdate }| )
( name = 'ISLM_enddate'
value = |{ ls_travel-enddate }| )
( name = 'ISLM_startingpoint'
value = ls_travel-StartingPoint )
( name = 'ISLM_destination'
value = ls_travel-Destination )
( name = 'ISLM_transportmode'
value = ls_travel-transportMode )
( name = 'ISLM_accommodationtype'
value = ls_travel-accommodationtype )
) ) .
FINAL(api_itin) = cl_aic_islm_compl_api_factory=>get( )->create_instance(
islm_scenario = 'ZINTS_RAP120' ).
*Set the LLM parameters
FINAL(params) = api_itin->get_parameter_setter( ).
params->set_maximum_tokens( 800 ).
FINAL(msg_itin) = api_itin->create_message_container( ).
msg_itin->set_system_role( sys_prompt ).
msg_itin->add_user_message( user_prompt ).
itinerary = api_itin->execute_for_messages( msg_itin )->get_completion( ).
CATCH cx_aic_api_factory INTO DATA(lx_api_itin).
itinerary = |AI instance creation failed for itinerary.|.
CATCH cx_aic_completion_api INTO DATA(lx_comp_itin).
itinerary = |AI completion call failed for itinerary.|.
ENDTRY.
IF itinerary IS NOT INITIAL.
TRY.
* To pass prompts directly without prompt parameters
* Your ISLM scenario for itinerary
DATA(system_prompt_budget) =
|You are a travel finance advisor. Based on the Itenary , destination, duration, | &&
|and total budget, estimate how much to allocate for travel, hotel, | &&
|food, sightseeing, and miscellaneous expenses. Output under 500 characters.|.
DATA(user_prompt_budget) =
|Itenerary: { itinerary }| &&
|Departure: { ls_travel-StartingPoint }| &&
|Destination: { ls_travel-destination }| &&
|\nTravel Dates: { ls_travel-startdate } to { ls_travel-enddate }| &&
|\nTotal Budget: ₹{ ls_travel-Budget }| &&
|\nTotal Budget Currency: ₹{ ls_travel-BudgetCurr }| &&
|\nProvide a short, realistic breakdown.|.
FINAL(api_budget) = cl_aic_islm_compl_api_factory=>get( )->create_instance(
islm_scenario = 'ZINTS_RAP120' ).
" Your ISLM scenario for budget
FINAL(msg_budget) = api_budget->create_message_container( ).
msg_budget->set_system_role( system_prompt_budget ).
msg_budget->add_user_message( user_prompt_budget ).
budget = api_budget->execute_for_messages( msg_budget )->get_completion( ).
CATCH cx_aic_api_factory INTO DATA(lx_api_budget).
budget = |AI instance creation failed for budget.|.
CATCH cx_aic_completion_api INTO DATA(lx_comp_budget).
budget = |AI completion call failed for budget.|.
ENDTRY.
ENDIF.
MODIFY ENTITIES OF zr_rap_travel_data IN LOCAL MODE
ENTITY ZrRapTravelData
UPDATE FIELDS ( aiitinerary aibudgetbreakdown status )
WITH VALUE #(
( %tky = ls_travel-%tky
aiitinerary = itinerary
aibudgetbreakdown = budget
status = 'Generated' )
).
ENDIF.
ENDLOOP.
ENDLOOP.
ENDMETHOD.
For the latest updates, subscribe to the blog posts below :
ABAP AI - Chapter 2 - SAP Community
Introducing the Next Era of ABAP Development - SAP Community
Joule speaks ABAP! - SAP Community
From Legacy to AI-Powered: RISE Transformation Rev... - SAP Community
Happy Learning!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 25 | |
| 19 | |
| 18 | |
| 14 | |
| 13 | |
| 11 | |
| 10 | |
| 9 | |
| 6 | |
| 4 |