Created
January 15, 2026 08:03
-
-
Save weiserman/9a135e1da9b0726c26c7431122e7ff1b to your computer and use it in GitHub Desktop.
Check Address Data - ABAP Cloud with Google SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CLASS zgoog_cl_qs_address_validation DEFINITION | |
| PUBLIC FINAL | |
| CREATE PUBLIC. | |
| PUBLIC SECTION. | |
| INTERFACES if_oo_adt_classrun. | |
| ENDCLASS. | |
| CLASS zgoog_cl_qs_address_validation IMPLEMENTATION. | |
| METHOD if_oo_adt_classrun~main. | |
| DATA: ls_input TYPE /goog/cl_addrvaldn_v1=>ty_012, | |
| lo_address_validator TYPE REF TO /goog/cl_addrvaldn_v1, | |
| ls_output TYPE /goog/cl_addrvaldn_v1=>ty_validate_address_response, | |
| lv_ret_code TYPE i, | |
| lv_err_text TYPE string, | |
| ls_err_resp TYPE /goog/err_resp. | |
| TRY. | |
| " Instantiate the Google Cloud Address Validation client using the configured key | |
| lo_address_validator = NEW #( iv_key_name = 'GCP_WE' ). | |
| " Prepare the input address for validation | |
| ls_input = VALUE #( address = VALUE #( region_code = 'US' | |
| locality = 'Mountain View' | |
| address_lines = VALUE #( ( '1600 Amphitheatre Parkway' ) ) ) ). | |
| " Call the API to validate the address | |
| lo_address_validator->validate_address( EXPORTING is_input = ls_input | |
| IMPORTING es_output = ls_output | |
| ev_ret_code = lv_ret_code | |
| ev_err_text = lv_err_text | |
| es_err_resp = ls_err_resp ). | |
| " Check API call success and address completeness | |
| IF lo_address_validator->is_success( lv_ret_code ) = abap_true. | |
| IF ls_output-result-verdict-address_complete = abap_true. | |
| out->write( |Address is complete and valid.| ). | |
| out->write( ls_output ). | |
| ELSE. | |
| out->write( |Address validation succeeded, but address is not complete.| ). | |
| out->write( ls_output ). | |
| ENDIF. | |
| ELSE. | |
| out->write( |Address validation failed with return code { lv_ret_code }.| ). | |
| out->write( |Error text: { lv_err_text }| ). | |
| out->write( ls_err_resp ). | |
| ENDIF. | |
| CATCH /goog/cx_sdk INTO DATA(lx_exception). | |
| out->write( |Exception occurred: { lx_exception->get_text( ) }| ). | |
| ENDTRY. | |
| ENDMETHOD. | |
| ENDCLASS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment