There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon Redshift examples using SDK for SAP ABAP
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for SAP ABAP with Amazon Redshift.
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 CreateCluster.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Create the cluster.
TRY. " Example values: iv_cluster_identifier = 'my-redshift-cluster' " Example values: iv_node_type = 'ra3.4xlarge' " Example values: iv_master_username = 'awsuser' " Example values: iv_master_password = 'AwsUser1000' " Example values: iv_publicly_accessible = abap_true " Example values: iv_number_of_nodes = 2 oo_result = lo_rsh->createcluster( iv_clusteridentifier = iv_cluster_identifier iv_nodetype = iv_node_type iv_masterusername = iv_master_username iv_masteruserpassword = iv_master_password iv_publiclyaccessible = iv_publicly_accessible iv_numberofnodes = iv_number_of_nodes ). MESSAGE 'Redshift cluster created successfully.' TYPE 'I'. CATCH /aws1/cx_rshclustalrdyexfault. MESSAGE 'Cluster already exists.' TYPE 'I'. CATCH /aws1/cx_rshclstquotaexcdfault. MESSAGE 'Cluster quota exceeded.' TYPE 'I'. ENDTRY.-
For API details, see CreateCluster in AWS SDK for SAP ABAP API reference.
-
The following code example shows how to use DeleteCluster.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Delete the cluster.
TRY. " Example values: iv_cluster_identifier = 'my-redshift-cluster' lo_rsh->deletecluster( iv_clusteridentifier = iv_cluster_identifier iv_skipfinalclustersnapshot = abap_true ). MESSAGE 'Redshift cluster deleted successfully.' TYPE 'I'. CATCH /aws1/cx_rshclustnotfoundfault. MESSAGE 'Cluster not found.' TYPE 'I'. CATCH /aws1/cx_rshinvcluststatefault. MESSAGE 'Invalid cluster state for deletion.' TYPE 'I'. ENDTRY.-
For API details, see DeleteCluster in AWS SDK for SAP ABAP API reference.
-
The following code example shows how to use DescribeClusters.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Describe the cluster.
TRY. " Example values: iv_cluster_identifier = 'my-redshift-cluster' (optional) oo_result = lo_rsh->describeclusters( iv_clusteridentifier = iv_cluster_identifier ). lt_clusters = oo_result->get_clusters( ). lv_cluster_count = lines( lt_clusters ). MESSAGE |Retrieved { lv_cluster_count } cluster(s).| TYPE 'I'. CATCH /aws1/cx_rshclustnotfoundfault. MESSAGE 'Cluster not found.' TYPE 'I'. ENDTRY.-
For API details, see DescribeClusters in AWS SDK for SAP ABAP API reference.
-
The following code example shows how to use DescribeStatement.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. TRY. " Example values: iv_statement_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' oo_result = lo_rsd->describestatement( iv_id = iv_statement_id ). lv_status = oo_result->get_status( ). MESSAGE |Statement status: { lv_status }| TYPE 'I'. CATCH /aws1/cx_rsdresourcenotfoundex. MESSAGE 'Statement not found.' TYPE 'I'. CATCH /aws1/cx_rsdinternalserverex. MESSAGE 'Internal server error.' TYPE 'I'. ENDTRY.-
For API details, see DescribeStatement in AWS SDK for SAP ABAP API reference.
-
The following code example shows how to use ExecuteStatement.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. TRY. " Example values: iv_cluster_identifier = 'redshift-cluster-movies' " Example values: iv_database_name = 'dev' " Example values: iv_user_name = 'awsuser' " Example values: iv_sql = 'SELECT * FROM movies WHERE year = :year' " Example values: it_parameter_list - SQL parameters for parameterized queries " Only pass parameters if the list is not empty IF it_parameter_list IS NOT INITIAL. oo_result = lo_rsd->executestatement( iv_clusteridentifier = iv_cluster_identifier iv_database = iv_database_name iv_dbuser = iv_user_name iv_sql = iv_sql it_parameters = it_parameter_list ). ELSE. oo_result = lo_rsd->executestatement( iv_clusteridentifier = iv_cluster_identifier iv_database = iv_database_name iv_dbuser = iv_user_name iv_sql = iv_sql ). ENDIF. lv_statement_id = oo_result->get_id( ). MESSAGE |Statement executed. ID: { lv_statement_id }| TYPE 'I'. CATCH /aws1/cx_rsdexecutestatementex. MESSAGE 'Statement execution error.' TYPE 'I'. CATCH /aws1/cx_rsdresourcenotfoundex. MESSAGE 'Resource not found.' TYPE 'I'. ENDTRY.-
For API details, see ExecuteStatement in AWS SDK for SAP ABAP API reference.
-
The following code example shows how to use GetStatementResult.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Check the statement result.
TRY. " Example values: iv_statement_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' " Handle pagination for large result sets DO. lo_result_page = lo_rsd->getstatementresult( iv_id = iv_statement_id iv_nexttoken = lv_next_token ). " Collect records from this page lt_page_records = lo_result_page->get_records( ). APPEND LINES OF lt_page_records TO lt_all_records. " Check if there are more pages lv_next_token = lo_result_page->get_nexttoken( ). IF lv_next_token IS INITIAL. EXIT. " No more pages ENDIF. ENDDO. " For the last call, set oo_result for return value oo_result = lo_result_page. lv_record_count = lines( lt_all_records ). MESSAGE |Retrieved { lv_record_count } record(s).| TYPE 'I'. CATCH /aws1/cx_rsdresourcenotfoundex. MESSAGE 'Statement not found or results not available.' TYPE 'I'. CATCH /aws1/cx_rsdinternalserverex. MESSAGE 'Internal server error.' TYPE 'I'. ENDTRY.-
For API details, see GetStatementResult in AWS SDK for SAP ABAP API reference.
-
The following code example shows how to use ListDatabases.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. TRY. " Example values: iv_cluster_identifier = 'redshift-cluster-movies' " Example values: iv_database_name = 'dev' " Example values: iv_database_user = 'awsuser' oo_result = lo_rsd->listdatabases( iv_clusteridentifier = iv_cluster_identifier iv_database = iv_database_name iv_dbuser = iv_database_user ). lt_databases = oo_result->get_databases( ). lv_db_count = lines( lt_databases ). MESSAGE |Retrieved { lv_db_count } database(s).| TYPE 'I'. CATCH /aws1/cx_rsddatabaseconnex. MESSAGE 'Database connection error.' TYPE 'I'. CATCH /aws1/cx_rsdresourcenotfoundex. MESSAGE 'Cluster not found.' TYPE 'I'. ENDTRY.-
For API details, see ListDatabases in AWS SDK for SAP ABAP API reference.
-
The following code example shows how to use ModifyCluster.
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Modify a cluster.
TRY. " Example values: iv_cluster_identifier = 'my-redshift-cluster' " Example values: iv_pref_maintenance_wn = 'wed:07:30-wed:08:00' lo_rsh->modifycluster( iv_clusteridentifier = iv_cluster_identifier iv_preferredmaintenancewin00 = iv_pref_maintenance_wn ). MESSAGE 'Redshift cluster modified successfully.' TYPE 'I'. CATCH /aws1/cx_rshclustnotfoundfault. MESSAGE 'Cluster not found.' TYPE 'I'. CATCH /aws1/cx_rshinvcluststatefault. MESSAGE 'Invalid cluster state for modification.' TYPE 'I'. ENDTRY.-
For API details, see ModifyCluster in AWS SDK for SAP ABAP API reference.
-