Amazon SDK for SAP ABAP features - Amazon SDK for SAP ABAP
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Amazon SDK for SAP ABAP features

Amazon SDK for SAP ABAP provides the following features.

Programmatic configuration

Use /n/AWS1/IMG IMG transacation for Amazon SDK for SAP ABAP, and Custom Business Configuration application for Amazon SDK for SAP ABAP - BTP edition for programmatic configuration.

To begin programmatic configuration, begin by retrieving a configuration object with the get_config( ) command.

data(lo_config) = lo_s3->get_config( ).

Each configuration object implements /AWS1/IF_RT_CONFIG interface that includes GETters and SETters corresponding to the IMG. For example, the default region can be overridden. See the following example command.

lo_s3->get_config( )->/aws1/if_rt_config~set_region( 'us-east-1' ).

Some configuration objects have no IMG representation and can only be set programmatically, such as maximum retry attempts. See the following example command.

lo_s3->get_config( )->/aws1/if_rt_config~set_max_attempts( 10 ).

The configuration object of Amazon Web Services services can also include service specific methods that are not represented in /aws1/if_rt_config. For example, Amazon S3 can address a bucket named foobucket using either foobucket.s3.region.amazonaws.com virtual endpoint or s3.region.amazonaws.com/foobucket path style. You can enforce the use of path style with the following example command.

lo_s3->get_config( )->set_forcepathstyle( abap_true ).

For more information about service configurations, see Amazon SDK for SAP ABAP – API Reference Guide.

Waiters

When working with asynchronous Amazon APIs, you need to wait for a certain resource to become available before taking further actions. For example, the CREATETABLE() API of Amazon DynamoDB responds right away with table status CREATING. You can initiate read or write operations only after the status of the table has changed to ACTIVE. Waiters give you the ability to confirm that Amazon resources are in a particular state before performing actions on them.

Waiters use service operations to poll the status of Amazon resources until the resource reaches the intended state or until it is determined that the resource doesn't reach the desired state. It can be time-consuming and error-prone to write the code to poll Amazon resources continually. Waiters help in simplifying this complexity by taking the responsibility of performing polls on your behalf.

See the following Amazon S3 example using waiter.

DATA(lo_session) = /aws1/cl_rt_session_aws=>create( cv_pfl ). DATA(lo_s3) = /aws1/cl_s3_factory=>create( lo_session ). “ Create a bucket - initiates the process of creating an S3 bucket and might return before the bucket exists lo_s3→createbucket( iv_bucket = |amzn-s3-demo-bucket| ). “ Wait until the newly created bucket becomes available lo_s3->get_waiter( )->bucketexists( iv_max_wait_time = 200 iv_bucket = |amzn-s3-demo-bucket| ).
  • In this example, Amazon S3 client is used to create a bucket. The get_waiter() command is implemented to specify when the bucketexists.

  • You must specify the iv_max_wait_time parameter for each waiter. It represents the total amount of time a waiter must wait before completion. In the preceding example, a waiter can run for 200 seconds.

  • You may need to provide additional inputs for required parameters. In the preceding example, Amazon S3 bucket name is required for iv_bucket parameter.

  • /AWS1/CX_RT_WAITER_FAILURE exception indicates that the waiter exceeded the maximum time specified in iv_max_wait_time parameter.

  • /AWS1/CX_RT_WAITER_TIMEOUT exception indicates that the waiter has stopped due to not reaching the desired state.

Paginators

Some Amazon Web Services service operations offer paged responses. They are paginated to return a fixed amount of data with each response. You need to make subsequent requests with a token or a marker to retrieve the entire set of results. For instance, the ListObjectsV2 Amazon S3 operation return up to 1,000 objects at a time. You must make subsequent requests with the appropriate token to get the next page of results.

Pagination is the process of sending successive requests to pick up where a previous request left off. Paginators are iterators of results provided by SDK for SAP ABAP. You can use paginated APIs with ease, and without understanding the underlying mechanism of API using pagination tokens.

Working with paginators

You can create paginators with the get_paginator() method that returns a paginator object. The paginator object calls the operation being paginated. The paginator object accepts required parameters to be provided to the underlying API. This process returns an iterator object that can be used to iterate over paginated results, using the has_next() and get_next() methods.

  • has_next() returns a boolean value indicating if there are more responses or pages available for the called operation.

  • get_next() returns the operation response.

The following example list all objects in an S3 bucket retrieved by using paginator.

DATA(lo_session) = /aws1/cl_rt_session_aws=>create( 'DEMO' ). DATA(lo_s3) = /aws1/cl_s3_factory=>create( lo_session ). TRY. DATA(lo_paginator) = lo_s3->get_paginator( ). DATA(lo_iterator) = lo_paginator->listobjectsv2( iv_bucket = 'example_bucket' ). WHILE lo_iterator->has_next( ). DATA(lo_output) = lo_iterator->get_next( ). LOOP AT lo_output->get_contents( ) INTO DATA(lo_object). WRITE: / lo_object->get_key( ), lo_object->get_size( ). ENDLOOP. ENDWHILE. CATCH /aws1/cx_rt_generic INTO DATA(lo_ex). MESSAGE lo_ex->if_message~get_text( ) TYPE 'I'. ENDTRY.

Retry behavior

SDK for SAP ABAP enables you to configure the maximum number of retries for requests to Amazon Web Services services that fail due to throttling or transient errors. The number of retries allowed at the service client level, that is the number of times the SDK retries the operation before failing and raising an exception is specified by the AV_MAX_ATTEMPTS attribute in the service configuration object. When a service client object is created, the SDK configures AV_MAX_ATTEMPTS attribute to a default value of 3. The service configuration object may be used to programmatically set the maximum retry attempt to a desired value. See the following example for more details.

“ Retrieve configuration object using Amazon S3 service’s get_config( ) method DATA(lo_config) = lo_s3->get_config( ). “ Set the maximum number of retries to 5 lo_config->/aws1/if_rt_config~set_max_attempts( 5 ). “ Get the value of the maximum retry attempt. DATA(lv_max_retry_attempts) = lo_config->/aws1/if_rt_config~get_max_attempts( ).
Note

Although the configuration object ABAP SDK allows retry mode to be set with the /AWS1/IF_RT_CONFIG~SET_RETRY_MODE() method, the SDK only supports the standard retry mode. For more information, see Retry behavior in Amazon SDKs and Tools Reference Guide.