ABAP SDK for Google Cloud: Pro Tips & Tricks for Developers

Satish Inamdar
Google Cloud - Community
11 min readDec 27, 2023

ABAP SDK for Google Cloud V1.5 provides a simplified and coherent way to connect and consume Google Cloud APIs.

The purpose of this blog is to provide valuable insights into utilities and uncover hidden gems. The configuration of ABAP SDK can be accessed through the SPRO transaction. Subsequent to installing ABAP SDK by importing the transport requests, transaction SPRO can be utilized to access various configuration nodes that are involved in the setup process of SDK.

The below screenshot shows all the different configuration settings and options available with ABAP SDK for Google Cloud

ABAP SDK IMG Node for Configuration

All the configuration nodes have documentation linked to them, you can read through them before performing the corresponding configuration step.

Now, let’s take a look at various Utilities that are available to SDK users and developers and how one can utilize them.

ABAP SDK for Google Cloud’s Toolbox

Validate Authentication Configuration

Scenario: A user follows the ABAP SDK for Google Cloud’s configuration steps reading the public documentation & wants to verify if the configuration has been done correctly

Go to the utility Validate Authentication Configuration either by going to transaction SPRO > ABAP SDK for Google Cloud > Utilities > Validate Authentication Configuration or use the direct transaction code: /GOOG/CHECK_AUTH_CNF

This screen displays a mandatory input field where you can input your Google Cloud Key Name. Additionally, there is an optional checkbox that you can select to display troubleshooting information which can be particularly useful when encountering issues with the configuration.

Configuration Validation Selection Screen

Example 1: Configuration has been done correctly

Output for IAM Based Authentication — Valid Configuration
Output for JWT Based Authentication — Valid Configuration

Example 2: Incorrect Configuration

Output for JWT Based Authentication — Invalid Configuration

Example 3: Troubleshooting Information

Troubleshooting Information for JWT Based Authentication

This tool can quickly help in validating the ABAP SDK configuration and also provides in-tool troubleshooting documentation that is useful in identifying most of the commonly occurring errors & mistakes (missed steps)

Get RFC Settings for Google Cloud Services

ABAP SDK allows connectivity to Google Cloud APIs using RFC Destinations. You can read about this more here to know how to use RFC Destinations and how to configure them in Service Map Table (/GOOG/SERIVC_MAP).

To know what RFC Settings have to be maintained for a specific Google API. You can make use of this utility by going to transaction code SPRO > ABAP SDK for Google Cloud > Utilities > Get RFC Settings for Google Cloud Services or use the direct transaction code /GOOG/RFC_INFO

The selection screen requires the API ID to be passed which can be inputted by using the F4 help. On execution the report displays the required values to be set for various parameters when creating and RFC Destination.

Below screenshots show how this utility can be used

Selection Screen and F4 Help

Selection Screen and F4 Help

RFC Settings for DLP (Data Loss Prevention) API

RFC Destination Parameters for DLP API

RFC Settings for Cloud Storage JSON API

RFC Destination Parameters for Cloud Storage API

Validate API Key Retrieval (Using Secret Manager)

Certain Google Cloud APIs use API Keys instead of OAUTH tokens for authentication. Examples of such APIs are:

  • Translation API V2 (Basic)
  • Address Validation API
  • All Google Maps Platform based APIs

Please note: It is also possible for an API to support more than one way of authentication i.e. API Key as well as OAUTH token. One should read about the respective API before choosing the authentication approach

The SDK provides two options to store and retrieve API Keys:

  • Store API Key in SSF (Secure Store & Forward)
  • Store using Secret Manager API

The configuration for these two approaches is clearly documented in the Authentication Guide:

The following blog covers in detail all the steps involved in using Secret Manager API for securely storing & retrieving API Keys:

Now, lets come to the utility Validate API Key Retrieval (Using Secret Manager), this helps you to validate if the API Keys are successfully retrieved or not. As there are multiple steps involved in the configuration, this utility is a quick help. If data is retrieved successfully from Secret Manager it shows base64 encoded & decoded value of the secret.

The Selection Screen is shown in the below screenshot and it requires Cloud Key Name to be provided as input:

Selection Screen

Below screenshot shows successful execution where API Key stored as secret is successfully retrieved

Program Output — Success Scenario

Below screenshot shows the program output when there is an issue in the configuration step or communication step and API Key stored as secret cannot be retrieved successfully

Program Output — Error Scenario

Clear Cache

The SDK provides an option to cache the tokens which can be helpful for high volume calls. You can enable it in the Client Key Settings Table (/GOOG/CLIENT_KEY).

So, when token caching is enabled and you make changes to the roles that are assigned to the service account that the ABAP SDK for Google Cloud uses to connect to the APIs it needs, the new access token that goes with those updated roles won’t be fetched until the old cached token timeouts (3600 seconds). In such cases you can make use of the Clear Cache Utility to manually clear the cached token

You can access the Clear Cache utility by going to transaction code SPRO > ABAP SDK for Google Cloud > Utilities > Clear Cache or alternatively use the direct transaction code/GOOG/CLEAR_CACHE

The Clear Cache utility provides two options for execution:

  • Clear Cache for all the Google Cloud Keys (Client Keys) stored in /GOOG/CLIENT_KEY table
  • Clear Cache for a Selected Google Cloud Keys (Client Keys)
Clear Cache — All Client Keys
Clear Cache — Selected Client Keys

Get Product Version

As of writing this blog, there are two versions of ABAP SDK available: V1.0 and V1.5 (latest). To quickly know which version of ABAP SDK is currently installed in your SAP systems, you can check it by traversing to transaction code: SPRO > ABAP SDK for Google Cloud > Utilities > Get Product Version or alternatively use the direct transaction code: /GOOG/GET_VERSION

If you are on the latest product version, you will see a popup as shown below when you execute the transaction

Pop-up confirms Latest Version

In case you are on a previous version then you will see a pop up with message as shown below:

Pop-up display shows earlier product version installed

Code Wizard is another useful utility and it is covered in detail in the following blog: ABAP SDK for Google Cloud: Code Wizard. It definitely is a productivity booster

Beyond Basic Calls: Power your SDK developments using these advanced concepts

The package /GOOG/CLIENT hosts all the API Classes or as we call it API Client Stub. Every API Client Stub has public methods that correspond with methods of the corresponding Google API. You can read further about the design & structure of the API Client Stub here. However, every API stub still has certain additional public methods that can be used. In the below section we will explore this further:

Method: ADD_COMMON_QPARAM

Common query parameters or system parameters are generic across many of the Google Cloud APIs and are not available to the developers as separate importing parameters for the API methods. To set such parameters ADD_COMMON_QPARAM method is available.

This method takes a key & value pair as input ( Importing parameters IV_NAME and IV_VALUE respectively) and appends these values to the URI string. If you want to add additional query parameters then this method needs to be called before the required API method is called.

Some examples of common query parameters are: alt callback and prettyPrint

You can read about them further using the link: Google Cloud APIs System Parameters

You can clear the set common query parameters all at once using the method CLEAR_ALL_COMMON_QPARAM or you can selectively clear the values by using the method CLEAR_COMMON_QPARAM and pass the query parameter name as input.

Sample code snippet:

Code Snippet for ADD_COMMON_QPARAM method usage

Method: ADD_CUSTOM_HEADER

Certain Google APIs require optional or additional HTTP Request Headers to be set. For example, the Storage API can accept certain custom headers that are listed on this page

The ADD_CUSTOM_HEADER method lets you assign values to extra headers in the HTTP request object. It takes two importing parameters: IV_NAME and IV_VALUE, which act as the key-value pair for the custom header. You can provide the values you want using these parameters.

Remember, you need to use this method before calling the API method you want.

To remove all custom headers that have been set, the CLEAR_ALL_CUSTOM_HEADERS method can be utilized. Alternatively, to selectively remove the values of a specific custom header, the CLEAR_CUSTOM_HEADER method should be utilized.

Sample code snippet:

Sample Code Snippet for usage of method ADD_CUSTOM_HEADER

In the above example header X-Goog-User-Project which sets the call specific project for billing and quota

For more information about the HTTP Request Headers that are required or optional for a specific Google API, please refer to the respective documentation for that API.

Method: SET_OVERRIDING_URI

Every API method requires either one of the below or combination of two or more of the below as inputs:

  • Path Parameters (represented as importing parameter IV_P_<…..>)
  • Query Parameters (represented as importing parameter IV_Q_<……>)
  • Request Body (represented as importing parameter IS_INPUT)

In almost all the cases the developer of the SDK needs to only pass correct values to these importing parameters when calling API methods. The path parameters and the query parameters form the HTTP Request URI where as the input parameter (IS_INPUT) is converted to JSON and constitutes the HTTP Request body.

However in certain cases (though rare) it can happen that importing parameters available do not fully make up the required URI for a HTTP call. Another possible scenario could be that the previous API method call returns the complete URI for the subsequent method call. In such cases the method SET_OVERRIDING_URI can really come handy.

You can construct the URI string and call this method before call the required API method. This method also takes two importing parameters: IV_URI and IV_KEEP_ACTIVE. You can pass the URI string to the parameter IV_URI. IV_KEEP_ACTIVE is an optional parameter and it’s value (‘X’ or space) influences the API method calls in the following way:

  • If IV_KEEP_ACTIVE is set to ‘X’ then the URI passed in the importing parameter IV_URI will be used for all the subsequent API method calls (for the same API object)
  • If IV_KEEP_ACTIVE is not set(default) then the URI passed in the importing parameter IV_URI will be used only for the next API method call

You can also clear or unset this overriding URI value using the method UNSET_OVERRIDING_URI method.

Sample code snippet:

Sample Code Snippet for usage of method SET_OVERRIDING_URI

In the above code snippet we are using Translation API V3 to create a glossary (first call) and then check the status of the operation (second call)

Method IS_SUCCESS

This method returns ABAP_TRUE if the passed HTTP Status Code denotes a successful HTTP Status code, else returns ABAP_FALSE

Use: You can use this method to pass the return code exported by the API Client Stub method in the parameter EV_RET_CODE to validate if the API Method call was successful or not.

Sample code snippet:

Sample Code Snippet for usage of method IS_SUCCESS

Method: IS_ERROR

This method is opposite of the method IS_ERROR. It returns ABAP_FALSE if the passed HTTP Status Code denotes a successful HTTP Status code, else returns ABAP_TRUE

Use: You can use this method to pass the return code exported by the API Client Stub method in the parameter EV_RET_CODE to validate if the API Method call was successful or not.

Sample code snippet:

Sample code snippet for usage of method IS_ERROR

Note: You can use either of the methods (IS_SUCCESS or IS_ERROR) to validate the HTTP Status Code for success or failure. It depends on your coding style or design choice.

Additional Note: Please make sure to call the CLOSE( ) method using the instantiated object of the API Client Class once all the processing is completed.

Conclusion

I hope that this blog post proves to be beneficial in both introducing the utilities that are available within the ABAP SDK for Google Cloud as well as exploring some of the public methods that are commonly available in API Client Classes and the functionalities that they provide.

Next Steps

Ready to start using ABAP SDK for Google Cloud?

Bookmark What’s new with the ABAP SDK for Google Cloud for the latest announcements and follow installation and configuration instructions.

Check out these blog posts to get started with ABAP SDK for Google Cloud

  • This blog, explains how you can evaluate ABAP SDK for Google Cloud using ABAP Platform Trial 1909 on Google Cloud Platform.
  • Read this blog post to get a sneak peek on how a business process such as Sales Order entry in SAP can be automated using ABAP SDK for Google Cloud.
  • This blog is an excellent start to understand how BigQuery ML which is a powerful machine learning service that lets you build and deploy models using SQL queries. you can now be accessed with ABAP SDK for Google Cloud.
  • This blog provides details of Translation API Advanced (V3) and Translating with Glossaries using ABAP SDK for Google Cloud
  • This blog provides details of setting up JWT Based Authentication for ABAP SDK for Google Cloud

Join the community today!

The ABAP SDK for Google Cloud Community is now open! This is a place for you to ask questions, share knowledge, and collaborate with other ABAP developers who are using Google Cloud.

We encourage you to get involved in the community and help us make the ABAP SDK for Google Cloud even better. We have an exciting roadmap filled with innovative features, and we envision your involvement as an integral part of this transformative journey.

Checkout the youtube Channel!!

Subscribe to the below youtube channel where you would find, a quick 5 minutes overview covering the design principles and capabilities of ABAP SDK, reference architectures and art of the possible SAP solutions based on Google’s AI services, Google Workspace APIs and Google Maps Platform APIs…. along many more insightful references.

--

--