AWS Glue examples using SDK for SAP ABAP - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

AWS Glue 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 AWS Glue.

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 CreateCrawler.

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. " iv_crawler_name = 'my-crawler' " iv_role_arn = 'arn:aws:iam::123456789012:role/AWSGlueServiceRole-Test' " iv_database_name = 'my-database' " iv_table_prefix = 'test_' " iv_s3_target = 's3://example-bucket/data/' DATA(lt_s3_targets) = VALUE /aws1/cl_glus3target=>tt_s3targetlist( ( NEW /aws1/cl_glus3target( iv_path = iv_s3_target ) ) ). DATA(lo_targets) = NEW /aws1/cl_glucrawlertargets( it_s3targets = lt_s3_targets ). lo_glu->createcrawler( iv_name = iv_crawler_name iv_role = iv_role_arn iv_databasename = iv_database_name iv_tableprefix = iv_table_prefix io_targets = lo_targets ). MESSAGE 'Crawler created successfully.' TYPE 'I'. CATCH /aws1/cx_glualreadyexistsex. MESSAGE 'Crawler already exists.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. CATCH /aws1/cx_gluresrcnumlmtexcdex INTO DATA(lo_limit_ex). DATA(lv_limit_error) = lo_limit_ex->if_message~get_longtext( ). MESSAGE lv_limit_error TYPE 'E'. ENDTRY.
  • For API details, see CreateCrawler in AWS SDK for SAP ABAP API reference.

The following code example shows how to use CreateJob.

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. " iv_job_name = 'my-etl-job' " iv_description = 'ETL job for data transformation' " iv_role_arn = 'arn:aws:iam::123456789012:role/AWSGlueServiceRole-Test' " iv_script_location = 's3://example-bucket/scripts/my-script.py' DATA(lo_command) = NEW /aws1/cl_glujobcommand( iv_name = 'glueetl' iv_scriptlocation = iv_script_location iv_pythonversion = '3' ). lo_glu->createjob( iv_name = iv_job_name iv_description = iv_description iv_role = iv_role_arn io_command = lo_command iv_glueversion = '3.0' ). MESSAGE 'Job created successfully.' TYPE 'I'. CATCH /aws1/cx_glualreadyexistsex. MESSAGE 'Job already exists.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. CATCH /aws1/cx_gluresrcnumlmtexcdex INTO DATA(lo_limit_ex). DATA(lv_limit_error) = lo_limit_ex->if_message~get_longtext( ). MESSAGE lv_limit_error TYPE 'E'. ENDTRY.
  • For API details, see CreateJob in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DeleteCrawler.

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. " iv_crawler_name = 'my-crawler' lo_glu->deletecrawler( iv_name = iv_crawler_name ). MESSAGE 'Crawler deleted successfully.' TYPE 'I'. CATCH /aws1/cx_glucrawlerrunningex. MESSAGE 'Crawler is currently running.' TYPE 'E'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Crawler does not exist.' TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. CATCH /aws1/cx_gluschdrtransingex. MESSAGE 'Scheduler is transitioning.' TYPE 'E'. ENDTRY.
  • For API details, see DeleteCrawler in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DeleteDatabase.

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. " iv_database_name = 'my-database' lo_glu->deletedatabase( iv_name = iv_database_name ). MESSAGE 'Database deleted successfully.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Database does not exist.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see DeleteDatabase in AWS SDK for SAP ABAP API reference.

The following code example shows how to use DeleteJob.

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. " iv_job_name = 'my-etl-job' lo_glu->deletejob( iv_jobname = iv_job_name ). MESSAGE 'Job deleted successfully.' TYPE 'I'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see DeleteJob in AWS 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 AWS Code Examples Repository.

TRY. " iv_database_name = 'my-database' " iv_table_name = 'my-table' lo_glu->deletetable( iv_databasename = iv_database_name iv_name = iv_table_name ). MESSAGE 'Table deleted successfully.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Table or database does not exist.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see DeleteTable in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetCrawler.

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. " iv_crawler_name = 'my-crawler' oo_result = lo_glu->getcrawler( iv_name = iv_crawler_name ). DATA(lo_crawler) = oo_result->get_crawler( ). MESSAGE 'Crawler information retrieved.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Crawler does not exist.' TYPE 'I'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see GetCrawler in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetDatabase.

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. " iv_database_name = 'my-database' oo_result = lo_glu->getdatabase( iv_name = iv_database_name ). DATA(lo_database) = oo_result->get_database( ). MESSAGE 'Database information retrieved.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Database does not exist.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see GetDatabase in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetJobRun.

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. " iv_job_name = 'my-etl-job' " iv_run_id = 'jr_abcd1234567890abcdef1234567890abcdef12345678' oo_result = lo_glu->getjobrun( iv_jobname = iv_job_name iv_runid = iv_run_id ). DATA(lo_job_run) = oo_result->get_jobrun( ). MESSAGE 'Job run information retrieved.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Job or job run does not exist.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see GetJobRun in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetJobRuns.

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. " iv_job_name = 'my-etl-job' oo_result = lo_glu->getjobruns( iv_jobname = iv_job_name ). DATA(lt_job_runs) = oo_result->get_jobruns( ). MESSAGE 'Job runs retrieved successfully.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Job does not exist.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see GetJobRuns in AWS SDK for SAP ABAP API reference.

The following code example shows how to use GetTables.

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. " iv_database_name = 'my-database' oo_result = lo_glu->gettables( iv_databasename = iv_database_name ). DATA(lt_tables) = oo_result->get_tablelist( ). MESSAGE 'Tables retrieved successfully.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Database does not exist.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see GetTables in AWS SDK for SAP ABAP API reference.

The following code example shows how to use ListJobs.

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. oo_result = lo_glu->listjobs( ). DATA(lt_job_names) = oo_result->get_jobnames( ). MESSAGE 'Job list retrieved successfully.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'No jobs found.' TYPE 'I'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see ListJobs in AWS SDK for SAP ABAP API reference.

The following code example shows how to use StartCrawler.

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. " iv_crawler_name = 'my-crawler' lo_glu->startcrawler( iv_name = iv_crawler_name ). MESSAGE 'Crawler started successfully.' TYPE 'I'. CATCH /aws1/cx_glucrawlerrunningex. MESSAGE 'Crawler is already running.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Crawler does not exist.' TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • For API details, see StartCrawler in AWS SDK for SAP ABAP API reference.

The following code example shows how to use StartJobRun.

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. " iv_job_name = 'my-etl-job' " iv_input_database = 'my-database' " iv_input_table = 'my-table' " iv_output_bucket_url = 's3://example-output-bucket/' DATA lt_arguments TYPE /aws1/cl_glugenericmap_w=>tt_genericmap. lt_arguments = VALUE #( ( VALUE /aws1/cl_glugenericmap_w=>ts_genericmap_maprow( key = '--input_database' value = NEW /aws1/cl_glugenericmap_w( iv_value = iv_input_database ) ) ) ( VALUE /aws1/cl_glugenericmap_w=>ts_genericmap_maprow( key = '--input_table' value = NEW /aws1/cl_glugenericmap_w( iv_value = iv_input_table ) ) ) ( VALUE /aws1/cl_glugenericmap_w=>ts_genericmap_maprow( key = '--output_bucket_url' value = NEW /aws1/cl_glugenericmap_w( iv_value = iv_output_bucket_url ) ) ) ). DATA(oo_result) = lo_glu->startjobrun( iv_jobname = iv_job_name it_arguments = lt_arguments ). ov_job_run_id = oo_result->get_jobrunid( ). MESSAGE 'Job run started successfully.' TYPE 'I'. CATCH /aws1/cx_gluconcurrentrunsex00. MESSAGE 'Maximum concurrent runs exceeded.' TYPE 'E'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Job does not exist.' TYPE 'E'. CATCH /aws1/cx_gluinvalidinputex INTO DATA(lo_invalid_ex). DATA(lv_invalid_error) = lo_invalid_ex->if_message~get_longtext( ). MESSAGE lv_invalid_error TYPE 'E'. CATCH /aws1/cx_gluinternalserviceex INTO DATA(lo_internal_ex). DATA(lv_internal_error) = lo_internal_ex->if_message~get_longtext( ). MESSAGE lv_internal_error TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. CATCH /aws1/cx_gluresrcnumlmtexcdex INTO DATA(lo_limit_ex). DATA(lv_limit_error) = lo_limit_ex->if_message~get_longtext( ). MESSAGE lv_limit_error TYPE 'E'. ENDTRY.
  • For API details, see StartJobRun in AWS SDK for SAP ABAP API reference.