Validasi alamat

Panduan memulai ini menunjukkan cara membuat program yang memvalidasi alamat bisnis yang disimpan dalam database SAP menggunakan Address Validation API, melalui ABAP SDK edisi SAP BTP untuk Google Cloud.

Sebelum memulai

Sebelum menjalankan panduan memulai ini, pastikan Anda atau administrator Anda telah memenuhi prasyarat berikut:

  • Pastikan Address Validation API diaktifkan di project Google Cloud Anda.

    Buka koleksi API

Membuat class ABAP untuk memvalidasi alamat

  1. Buat paket:

    1. Di ADT, buka Project Explorer.
    2. Klik kanan paket ZLOCAL, lalu pilih New > ABAP Package.
    3. Masukkan detail berikut untuk paket Anda:

      • Nama: masukkan ZABAPSDK_TEST.
      • Deskripsi: masukkan ABAP SDK Test Package.
    4. Klik Berikutnya.

    5. Pada dialog Select a Transport Request, centang kotak Create a new request.

    6. Masukkan deskripsi untuk permintaan transpor.

    7. Klik Selesai.

  2. Buat class ABAP untuk memanggil Address Validation API:

    1. Klik kanan paket ABAP, lalu pilih New > ABAP Class.
    2. Masukkan detail berikut untuk class ABAP Anda:

      • Nama: masukkan ZGOOG_CL_QS_ADDRESS_VALIDATION.
      • Deskripsi: masukkan Quick start for Address Validation API.
    3. Klik Berikutnya.

    4. Pilih permintaan transpor, lalu klik Selesai.

  3. Di editor kode, ganti kode default dengan cuplikan kode berikut:

    " --------------------------------------------------------------------
    "  Copyright 2024 Google LLC                                         -
    "                                                                    -
    "  Licensed under the Apache License, Version 2.0 (the "License");   -
    "  you may not use this file except in compliance with the License.  -
    "  You may obtain a copy of the License at                           -
    "      https://www.apache.org/licenses/LICENSE-2.0                   -
    "  Unless required by applicable law or agreed to in writing,        -
    "  software distributed under the License is distributed on an       -
    "  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,      -
    "  either express or implied.                                        -
    "  See the License for the specific language governing permissions   -
    "  and limitations under the License.                                -
    " --------------------------------------------------------------------
    CLASS zcl_qs_validate_address DEFINITION
      PUBLIC FINAL
      CREATE PUBLIC.
    
      PUBLIC SECTION.
        INTERFACES if_oo_adt_classrun.
    ENDCLASS.
    
    
    
    CLASS ZCL_QS_VALIDATE_ADDRESS IMPLEMENTATION.
    
    
      METHOD if_oo_adt_classrun~main.
    
        DATA ls_input             TYPE /goog/cl_addrvaldn_v1=>ty_012.
        DATA lo_address_validator TYPE REF TO /goog/cl_addrvaldn_v1.
    
        TRY.
            " Open HTTP connection
            " The client key DEMO_ADDR_VAL is an example, replace this with actual value
            lo_address_validator = NEW #( iv_key_name = 'DEMO_ADDR_VAL' ).
    
            " Pass the address to be validated
            ls_input-address-region_code = 'US'.
            ls_input-address-locality    = 'Mountain View'.
            APPEND '1600, Amphitheatre, Parkway' TO ls_input-address-address_lines.
    
            " Call the API Method to validate address
            lo_address_validator->validate_address( EXPORTING is_input    = ls_input
                                                    IMPORTING es_output   = DATA(ls_output)
                                                              ev_ret_code = DATA(lv_ret_code)
                                                              ev_err_text = DATA(lv_err_text)
                                                              es_err_resp = DATA(ls_err_resp) ).
    
            IF     lo_address_validator->is_success( lv_ret_code ) = abap_true
               AND ls_output-result-verdict-address_complete       = abap_true.
              out->write( 'Address is complete' ).
            ENDIF.
    
          CATCH /goog/cx_sdk INTO DATA(lo_exception).
            " Handle exception here
        ENDTRY.
      ENDMETHOD.
    ENDCLASS.
    

    Ganti DEMO_ADDR_VAL dengan nama kunci klien.

  4. Simpan dan aktifkan perubahan.

  5. Jalankan aplikasi Anda:

    1. Pilih class ABAP ZGOOG_CL_QS_ADDRESS_VALIDATION.
    2. Klik Jalankan > Jalankan Sebagai > Aplikasi ABAP (Konsol). Atau, tekan F9. Jika berhasil, output berikut akan ditampilkan:
      'Address is complete'
      

Langkah selanjutnya