本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用适用于 SAP 的软件开发工具包的 Amazon Redshift 示例
以下代码示例向您展示了如何使用适用于 SAP ABAP 的 AWS 软件开发工具包和 Amazon Redshift 来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示了如何使用 CreateCluster。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 创建集群。
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.-
有关 API 的详细信息,请参阅适用CreateCluster于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 DeleteCluster。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 请删除集群。
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.-
有关 API 的详细信息,请参阅适用DeleteCluster于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 DescribeClusters。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 描述集群。
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.-
有关 API 的详细信息,请参阅适用DescribeClusters于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 DescribeStatement。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用DescribeStatement于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 ExecuteStatement。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用ExecuteStatement于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 GetStatementResult。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 检查语句结果。
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.-
有关 API 的详细信息,请参阅适用GetStatementResult于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 ListDatabases。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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.-
有关 API 的详细信息,请参阅适用ListDatabases于 S AP 的AWS SDK ABAP API 参考。
-
以下代码示例演示了如何使用 ModifyCluster。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 修改集群。
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.-
有关 API 的详细信息,请参阅适用ModifyCluster于 S AP 的AWS SDK ABAP API 参考。
-