Amazon Keyspaces examples using SDK for SAP ABAP
The following code examples show you how to perform actions and implement common scenarios by using the Amazon SDK for SAP ABAP with Amazon Keyspaces.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use CreateKeyspace.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. oo_result = lo_kys->createkeyspace( iv_keyspacename = iv_keyspace_name ). MESSAGE 'Keyspace created successfully.' TYPE 'I'. CATCH /aws1/cx_kysconflictexception. MESSAGE 'Keyspace already exists.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see CreateKeyspace in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use CreateTable.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. " Define schema with columns DATA(lt_columns) = VALUE /aws1/cl_kyscolumndefinition=>tt_columndefinitionlist( ( NEW /aws1/cl_kyscolumndefinition( iv_name = 'title' iv_type = 'text' ) ) ( NEW /aws1/cl_kyscolumndefinition( iv_name = 'year' iv_type = 'int' ) ) ( NEW /aws1/cl_kyscolumndefinition( iv_name = 'release_date' iv_type = 'timestamp' ) ) ( NEW /aws1/cl_kyscolumndefinition( iv_name = 'plot' iv_type = 'text' ) ) ). " Define partition keys DATA(lt_partition_keys) = VALUE /aws1/cl_kyspartitionkey=>tt_partitionkeylist( ( NEW /aws1/cl_kyspartitionkey( iv_name = 'year' ) ) ( NEW /aws1/cl_kyspartitionkey( iv_name = 'title' ) ) ). " Create schema definition DATA(lo_schema) = NEW /aws1/cl_kysschemadefinition( it_allcolumns = lt_columns it_partitionkeys = lt_partition_keys ). " Enable point-in-time recovery DATA(lo_pitr) = NEW /aws1/cl_kyspointintimerec( iv_status = 'ENABLED' ). oo_result = lo_kys->createtable( iv_keyspacename = iv_keyspace_name iv_tablename = iv_table_name io_schemadefinition = lo_schema io_pointintimerecovery = lo_pitr ). MESSAGE 'Table created successfully.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see CreateTable in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use DeleteKeyspace.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. lo_kys->deletekeyspace( iv_keyspacename = iv_keyspace_name ). MESSAGE 'Keyspace deleted successfully.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see DeleteKeyspace in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use DeleteTable.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. lo_kys->deletetable( iv_keyspacename = iv_keyspace_name iv_tablename = iv_table_name ). MESSAGE 'Table deleted successfully.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see DeleteTable in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use GetKeyspace.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. oo_result = lo_kys->getkeyspace( iv_keyspacename = iv_keyspace_name ). MESSAGE 'Keyspace retrieved successfully.' TYPE 'I'. CATCH /aws1/cx_kysresourcenotfoundex. MESSAGE 'Keyspace does not exist.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see GetKeyspace in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use GetTable.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. oo_result = lo_kys->gettable( iv_keyspacename = iv_keyspace_name iv_tablename = iv_table_name ). MESSAGE 'Table information retrieved successfully.' TYPE 'I'. CATCH /aws1/cx_kysresourcenotfoundex. MESSAGE 'Table does not exist.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see GetTable in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use ListKeyspaces.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. oo_result = lo_kys->listkeyspaces( iv_maxresults = iv_max_results ). MESSAGE 'Keyspaces listed successfully.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see ListKeyspaces in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use ListTables.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. oo_result = lo_kys->listtables( iv_keyspacename = iv_keyspace_name ). MESSAGE 'Tables listed successfully.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see ListTables in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use RestoreTable.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. oo_result = lo_kys->restoretable( iv_sourcekeyspacename = iv_source_keyspace_name iv_sourcetablename = iv_source_table_name iv_targetkeyspacename = iv_target_keyspace_name iv_targettablename = iv_target_table_name iv_restoretimestamp = iv_restore_timestamp ). MESSAGE 'Table restore initiated successfully.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see RestoreTable in Amazon SDK for SAP ABAP API reference.
-
The following code example shows how to use UpdateTable.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. TRY. " Add a new column to track watched movies DATA(lt_add_columns) = VALUE /aws1/cl_kyscolumndefinition=>tt_columndefinitionlist( ( NEW /aws1/cl_kyscolumndefinition( iv_name = 'watched' iv_type = 'boolean' ) ) ). oo_result = lo_kys->updatetable( iv_keyspacename = iv_keyspace_name iv_tablename = iv_table_name it_addcolumns = lt_add_columns ). MESSAGE 'Table updated successfully.' TYPE 'I'. CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDTRY.-
For API details, see UpdateTable in Amazon SDK for SAP ABAP API reference.
-