Introduction
The world of SAP ABAP development is often associated with robust business logic, data processing, and enterprise resource planning. However, the increasing demand for richer user experiences and automated content generation opens up exciting new possibilities. One such frontier is the integration of generative AI models.
At Google Cloud Next 2025 we saw how Google’s Imagen models on Vertex AI can transform a user's imagination into high quality visual assets using AI generation, in seconds. In this blog post, we'll delve into the technical aspects of invoking Google Cloud's powerful Imagen models directly from your SAP ABAP applications to realise AI powered image generation and visualisation use cases for SAP customers.
Why Integrate Imagen with ABAP?
While ABAP excels in transactional processing, it traditionally lacks native capabilities for generating sophisticated visual content. Integrating with Imagen unlocks a plethora of use cases, including:
Prerequisites
To successfully invoke Imagen models from ABAP, make sure:
ABAP SDK for Google Cloud brings the power of Google Cloud to SAP developers in the programming language of their choice - ABAP. The SDK is available as a set of client libraries in the form of ABAP classes. Using these classes, ABAP developers can connect to and use Google Cloud APIs.
Invoke Imagen models from ABAP applications
We would be using class /GOOG/CL_AIPLATFORM_V1 of the SDK to invoke Imagen models on Vertex AI platform. You can invoke Imagen with a prompt to,
Below example places the generated image in a GCS folder.
TYPES:
BEGIN OF ty_instance,
prompt TYPE string,
END OF ty_instance,
tt_instances TYPE STANDARD TABLE OF ty_instance,
BEGIN OF ty_parameters,
sample_count TYPE i,
aspect_ratio TYPE string,
storage_uri TYPE string,
END OF ty_parameters.
DATA:
ls_input TYPE /goog/cl_aiplatform_v1=>ty_001,
ls_instance TYPE ty_instance,
lt_instances TYPE tt_instances,
ls_parameters TYPE ty_parameters,
lv_raw TYPE string.
TRY.
* Open HTTP Connection
DATA(lo_client) = NEW /goog/cl_aiplatform_v1( iv_key_name = '<CLIENT_KEY>' ).
ls_instance-prompt = '<INPUT_PROMPT>'.
APPEND ls_instance TO lt_instances.
CLEAR ls_instance.
GET REFERENCE OF lt_instances INTO ls_input-instances.
ls_parameters-sample_count = <SAMPLE_COUNT>.
ls_parameters-storage_uri = '<GCS_URI>'.
GET REFERENCE OF ls_parameters INTO ls_input-parameters.
* Call API method: aiplatform.projects.locations.publishers.models.predict
CALL METHOD lo_client->predict_models
EXPORTING
iv_p_projects_id = '<GCP_PROJECT_NAME>
iv_p_locations_id = '<LOCATION_ID>'
iv_p_publishers_id = 'google'
iv_p_models_id = '<IMAGEN_MODEL_ID>'
is_input = ls_input
IMPORTING
es_raw = lv_raw
es_output = DATA(ls_output)
ev_ret_code = DATA(lv_ret_code)
ev_err_text = DATA(lv_err_text)
es_err_resp = DATA(ls_err_resp).
IF lo_client->is_success( lv_ret_code ).
cl_demo_output=>display( ls_output-predictions ).
ELSE.
MESSAGE lv_err_text TYPE 'E'.
ENDIF.
* Close HTTP Connection
lo_client->close( ).
CATCH /goog/cx_sdk INTO DATA(lo_exception).
MESSAGE lo_exception->get_text( ) TYPE 'E'.
ENDTRY.
Replace,
An example invocation
Below is an example invocation of the code snippet when run with below parameter values,
CLIENT_KEY, GCP_PROJECT_NAME and LOCATION_ID can be entered based on your configurations and Google Cloud project setup.
Once executed, the generated images are placed at the GCS folder location.
Here is one of the images generated for reference.
Bingo….with few configurations and minimum lines of code, we were able to invoke Imagen models in SAP ABAP using ABAP SDK for Google Cloud.
There are other input parameters that you can pass along with the prompt and "sample count". Refer to the link to the list of parameters that you can define under TY_PARAMETERS and pass in LS_INPUT of the code snippet.
You can also achieve these features along with image generation using text prompts with Imagen.
Conclusion
ABAP SDK for Google Cloud provides comprehensive tools to integrate Google’s AI with your SAP ABAP applications or ABAP AI Agents. Refer to the blog linked here to show how to invoke Gemini models from your ABAP applications. You can also refer to the blog linked here to invoke Gemini models in free tier without the need of any Google Cloud project.
Let us know your use cases that you would like to explore with Imagen and Gemini by starting a conversation on our Google Cloud Channel.