Calling an External
API in SAP RAP
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
1. Creating the HTTP Client
The program creates an HTTP destination using the communication arrangement
Z_API_OVERPASS_CSCEN_000 and the outbound service
Z_API_OVERPASS_OB_000_REST.
Then it creates an HTTP client based on that destination.
It retrieves a request object and sets the Overpass API query inside it (to search for
beer gardens in Heidelberg).
It sends the request using the HTTP GET method and stores the XML response text
in lv_xml_results.
If any error occurs, the exception text is displayed.
2. Preparing Structures for XML Transformation
Structures are defined to store:
o individual tags (ts_tag)
o node information (ts_node)
o metadata (ts_metadata)
o the main OSM structure (ts_osm)
A variable ls_osm is created to store the transformed XML data.
3. XML → ABAP Structure Transformation
The XML returned by Overpass API is transformed using the
z_overpass_xml_st_000 transformation.
The <osm> XML root is mapped into the ls_osm ABAP structure.
If the mapping fails, the exception text is displayed.
4. Output to Console
A message is shown describing that beer garden names in Heidelberg are being
listed.
The API generator name is printed.
For each OSM node, the program loops through its tags.
If a tag named "name" exists, that beer garden name is printed.
Then the raw XML response is printed.
5. Preparing Data for Database Insert
An internal table lt_api is created to store final database records.
For each node and its tags:
o node ID, latitude, longitude, tag name, and tag value are captured
o a row is appended to lt_api
6. Database Insert
Old records in table ZAPI_DB are deleted.
All new records from the XML are inserted into ZAPI_DB.
A message shows the number of inserted records.
Step 2
Create outbound service
1. Select your ABAP package and choose New > Other Repository Object from the
context menu; then enter Outbound Service, then choose Next.
2. Enter the following and choose Next.
o Outbound service: Z_API_OVERPASS_OB_000_REST
o Description: Get data from Overpass map service
o Service type: HTTP Service
4. Enter the Default Path Prefix /api/interpreter.
Step 3
Create communication scenario in ADT
1. Again, choose New > Other Repository Object from the context menu; then
enter Communication Scenario.
Create communication system in Fiori Launchpad
Now, you need to create the necessary communication artifacts in Fiori Launchpad, starting
with the Communication System. This artifact specifies hostname and port of the targeted
remote API.
In the Fiori Launchpad home page, choose Communication System, then choose New.
Create communication arrangement
A communication arrangement establishes a specific communication route by combining one
communication scenario and one communication system.
1. Go back to the Fiori Launchpad home page and choose Communication
Arrangement, then choose New.
Step 6
Create transformation (XML only)
Run class in ABAP Console
After this I have created a database to insert external API data into the database