SDK for SAP ABAP를 사용한 Amazon Redshift 예제 - AWS SDK for SAP ABAP

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

SDK for SAP ABAP를 사용한 Amazon Redshift 예제

다음 코드 예제에서는 Amazon Redshift와 함께 AWS SDK for SAP ABAP를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

각 예시에는 전체 소스 코드에 대한 링크가 포함되어 있으며, 여기에서 컨텍스트에 맞춰 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있습니다.

주제

작업

다음 코드 예시는 CreateCluster의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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 세부 정보는 AWS SDK for SAP ABAP API 참조CreateCluster를 참조하세요.

다음 코드 예시는 DeleteCluster의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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.

다음 코드 예시는 DescribeClusters의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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 세부 정보는 AWS SDK for SAP ABAP API 참조DescribeClusters를 참조하세요.

다음 코드 예시는 DescribeStatement의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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 세부 정보는 AWS SDK for SAP ABAP API 참조DescribeStatement를 참조하세요.

다음 코드 예시는 ExecuteStatement의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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 세부 정보는 AWS SDK for SAP ABAP API 참조ExecuteStatement를 참조하세요.

다음 코드 예시는 GetStatementResult의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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 세부 정보는 AWS SDK for SAP ABAP API 참조GetStatementResult를 참조하세요.

다음 코드 예시는 ListDatabases의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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 세부 정보는 AWS SDK for SAP ABAP API 참조ListDatabases를 참조하세요.

다음 코드 예시는 ModifyCluster의 사용 방법을 보여 줍니다.

SDK for SAP ABAP API
참고

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 세부 정보는 AWS SDK for SAP ABAP API 참조ModifyCluster을 참조하세요.