NextTables Knowledge Base

How to implement the Google API in NextTables

Written by Sebastian | Sep 29, 2020 3:50:20 PM

In the article "Effective data analysis using geodata" you have learned how to enrich your data in NextTables with spatial information. Using a BAdI, it is possible to read geodata, such as longitude and latitude or formatted addresses, from existing addresses. Geodata is automatically added when saving. In this article you will learn how to do it.

We use the META Exit to lock the columns. This exit is described in detail in the Knowledge Base article “Table Maintenance - How to Implement a BAdI. You can use the following code in the exit.


LOOP AT ch_t_fields_info ASSIGNING FIELD-SYMBOL(<ls_fields_info>).
CASE <ls_fields_info>-fname.
WHEN 'LONGITUDE'
OR 'LATITUDE'
OR 'ADDRESS_FORMATTED'
OR 'GEO_MSG'
OR 'DATE_PROCESSED'
OR 'TIME_PROCESSED'.
<ls_fields_info>-editable = '1'.
ENDCASE.
ENDLOOP.

However, only if the amount of data to be processed contains less than 500 data records. If there are more than 500 data records, the derivation is executed via a process chain.

DATA: lt_table TYPE STANDARD TABLE OF /bic/azdrgeodt2 WITH EMPTY KEY,
l_tabix TYPE sytabix,
ls_validation TYPE /nly/ts_validation.

FIELD-SYMBOLS:
<fs_t_table> TYPE ANY TABLE,
<ls_table> TYPE /bic/azdrgeodt2.

ASSIGN co_table->* TO <fs_t_table>.

CASE i_type.

WHEN /nly/cl_table_rest_v3=>co_type_update
OR /nly/cl_table_rest_v3=>co_type_insert
OR /nly/cl_table_rest_v3=>co_type_delete.

CASE i_step.
WHEN /nly/cl_table_rest_v3=>co_step_before_update.

DESCRIBE TABLE <fs_t_table> LINES DATA(l_lines).

IF l_lines LE 500.

LOOP AT <fs_t_table> ASSIGNING <ls_table>. "For each inserted/edited record we do write in the table the system user, date and time in order to keep track on changes
zcl_google_geo_api=>get_geodata(
EXPORTING
i_address = <ls_table>-address
* i_api_key =
IMPORTING
es_result = DATA(ls_result)
).

<ls_table>-address_formatted = ls_result-formatted_address.
<ls_table>-latitude = ls_result-lat.
<ls_table>-longitude = ls_result-lng.
<ls_table>-geo_msg = ls_result-status.
<ls_table>-date_processed = sy-datum.
<ls_table>-time_processed = sy-timlo.


ENDLOOP.

ELSE.
ct_messages = VALUE #( BASE ct_messages
( type = /nly/cl_table_rest_v3=>co_msg_type_info
visu_type = /nly/cl_table_rest_v3=>co_visu_type_modal
hdr = 'More than 500 Records'
msg = 'Ad Hoc Geo encoding is disabled for more than 500 records. Please run process chain via button to start encoding.') ).

ENDIF.

ENDCASE.
WHEN /nly/cl_table_rest_v3=>co_type_validate.
CASE i_step.

WHEN /nly/cl_table_rest_v3=>co_step_before_update.

WHEN /nly/cl_table_rest_v3=>co_step_after_update.

ENDCASE.
ENDCASE.

ENDMETHOD.

Summary

As you can see, NextTables can be enhanced with new features in a variety of ways. Do you have any questions about the implementation? Please do not hesitate to contact us.

Which License is needed for this feature Professional | Enterprise