Real Time Exchange Rate with Real Time Data Using Yahoo Finance API

Real Time Exchange Rate with Real Time Data Using Yahoo Finance API

let’s dive into the Real Time Exchange Rate with Real Time Data Using Yahoo Finance API. In the prior posts Google Guide Programming interface in SAP and GPS like apparatus in SAP we perceived how we can use the Google Guide APIs and consume them in SAP. Here, we expand the utilization of comparative APIs to follow the conversion scale continuous. By the constant we mean, it would be invigorated naturally at a decent timespan which we set and it would show the genuine rate for that portion of the time. Why generally Google, this time we would utilize Yippee’s Programming interface. Let’s get into the Real Time Exchange Rate with Real Time Data Using Yahoo Finance API.

Yahoo Finance API: http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote

This, Yahoo’s Money Programming interface has the underneath structure.

Yahoo and SAP

We want to consume it in SAP to show the swapping scale constant and furthermore revive it consequently without the need to stir things up around town button on the screen. Could it be cool, in the event that you are in a Money Association and you project the conversion scale or stock worth on an immense wall from SAP and it gets revived constant for each bystander to see?

Allow us to see what our Application can do.

Give the time span at which you maintain that the outcomes should be revived.

The result is shown for a specific time frame.

Presently, it is revived consequently. The message shows the time at which the information was revived.

Kindly note, there is no invigorate button on the screen. Our Application handles the invigorate.

There is no advanced science. Class Strategy CL_GUI_ALV_GRID->REFRESH_TABLE_DISPLAY is going about our business.

A unique notice of the Class/Connection point CL_GUI_TIMER and Occasion Completed is likewise required.

Really take a look at the Technique TIMER_EVENT in the Class CL_AUTO in the code.

METHODS :display_report,
* Define event handling method for event FINISHED of class CL_GUI_TIMER.
timer_event FOR EVENT finished OF cl_gui_timer.

Conceptually, what is happening?

Occasion Completed of class CL_GUI_TIMER is raised after the Clock has hung tight for the Stretch gave in the choice screen. An audience strategy for Completed occasion is made and the Invigorate rationale is carried out.

Another significant step is to call the Pursue strategy for CL_GUI_TIMER the Invigorate to actuate the time once more.

METHOD timer_event .

DATA: lv_time TYPE char10.

* Get Data
me->get_data( ) .

IF me->ob_grid IS INITIAL .

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ob_grid.
ELSE.

* Refresh the ALV
CALL METHOD ob_grid->refresh_table_display.

ENDIF.

WRITE sy-uzeit TO lv_time USING EDIT MASK '__:__:__'.

CONCATENATE 'Screen refreshed at' lv_time INTO DATA(lv_msg) SEPARATED BY space.

MESSAGE lv_msg TYPE 'S' . " Get the cuuent timE as message

* Call RUN method of CL_GUI_TIMER again to activate timer
me->ob_timer->run( ) .

ENDMETHOD.

This article is a result of exploration done to figure out how to track and follow the vehicle of specialist co-ops like Ola or Uber and so forth. The thought was to utilize the point of interaction/program which we made before where we consumed Google Guide APIs. Be that as it may, tragically, we were unable to sort out any free APIs which would return the specific place of the vehicles constant. Yet, we wound up finding this Programming interface which returned constant stock and conversion scale.

The moves toward consume the Programming interface is the very same as our past articles. Thusly, we have not portrayed them again here. Assuming that you have disarray, if it’s not too much trouble, allude to our prior articles or just put breakpoints in the code and begin troubleshooting. The rationale is clear.

To get such helpful articles straightforwardly to your inbox, kindly Buy in. We regard your security and treat safeguarding it in a serious way.

Do you have anything to add to this article? Have you confronted any issue utilizing Adobe Structures? Would you like to share any genuine task necessity or arrangements? Kindly let it all out. Kindly leave your considerations in the remark area.

Much thanks for your time!!

 

We have characterized a design ‘ZAUTO_EXC’ for the beneath application. You could require this too.

Exchange Rate in SAP

The total working code piece for this subject. Kindly reproduce it in your SAP climate and have a great time.

**---------------------------------------------------------------------*
** Date : 12/11/2016 *
** Author : Varad (elearningsolutions) *
** Title : Auto Refresh the Screen Output *
**---------------------------------------------------------------------*
REPORT elearningsolutions MESSAGE-ID zma.

*&---------------------------------------------------------------------*
*& CLASS DEFINATION FOR ADDTING AUTO REFRESH
*&---------------------------------------------------------------------*
CLASS cl_auto DEFINITION .

PUBLIC SECTION .
*&---------------------------------------------------------------------*
*& TYPE-POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS: truxs, slis.

DATA : ob_timer TYPE REF TO cl_gui_timer .

METHODS :display_report,
* Define event handling method for event FINISHED of class CL_GUI_TIMER.
timer_event FOR EVENT finished OF cl_gui_timer.
PRIVATE SECTION .

*&---------------------------------------------------------------------*
*& Types and Data
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_dest,
time_date TYPE zauto_exc-time_date,
ex_type TYPE zauto_exc-ex_type,
rate TYPE zauto_exc-rate,
time_stamp TYPE zauto_exc-time_stamp,
END OF ty_dest.

DATA: gt_dest TYPE STANDARD TABLE OF ty_dest.
DATA : ob_grid TYPE REF TO cl_gui_alv_grid . "DISPLAY DATA
DATA : gt_dest1 TYPE STANDARD TABLE OF ty_dest.

*&---------------------------------------------------------------------*
*& Methods
*&---------------------------------------------------------------------*
METHODS :
get_data,

create_http_client IMPORTING ip_url TYPE string
EXPORTING ex_http_client TYPE REF TO if_http_client,

http_client_request_get_method
IMPORTING ip_http_client TYPE REF TO if_http_client,

http_client_send IMPORTING ip_http_client TYPE REF TO if_http_client,

http_client_receive IMPORTING ip_http_client TYPE REF TO if_http_client
EXPORTING ex_content TYPE string,

get_data_ex IMPORTING ip_content TYPE string.

ENDCLASS.

CLASS cl_auto IMPLEMENTATION.

* Method 1
METHOD create_http_client.

* Get client from url
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = ip_url " 'http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote'.
IMPORTING
client = ex_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.

ENDMETHOD.

* Method 2
METHOD http_client_request_get_method.
* Request and Get
ip_http_client->request->set_header_field( name = '~request_method' value = 'GET' ).
ENDMETHOD.

* Method 3
METHOD http_client_send.
* Send the request
ip_http_client->send( ).
ENDMETHOD.

* Method 4
METHOD http_client_receive.
* Reterive the result
CALL METHOD ip_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
ex_content = ip_http_client->response->get_cdata( ).

ENDMETHOD.

* Method 5
METHOD get_data_ex.

* Local data declaration
DATA: lv_url TYPE c LENGTH 255,
ls_dest TYPE ty_dest,
moff TYPE syst-tabix,
moff1 TYPE syst-tabix,
lv_len TYPE syst-tabix,
lv_ex_type TYPE c LENGTH 20,
lv_rate TYPE c LENGTH 20,
lv_time_date TYPE c LENGTH 40.

*&---------------------------------------------------------------------*
*& Find exchange
*&---------------------------------------------------------------------*
DO .
* Find <location> text in the content string
FIND '<field name="name">' IN SECTION OFFSET moff OF ip_content IGNORING CASE MATCH OFFSET moff .

IF sy-subrc = 0 .

moff = moff + 19 .

FIND '</field>' IN SECTION OFFSET moff OF ip_content IGNORING CASE MATCH OFFSET moff1 .

lv_len = moff1 - moff .

lv_ex_type = ip_content+moff(lv_len) .

ls_dest-ex_type = lv_ex_type.
*--------------------------------------------------------------------*
* ---------------Find rate
*--------------------------------------------------------------------*
FIND '<field name="price">' IN SECTION OFFSET moff OF ip_content IGNORING CASE MATCH OFFSET moff .

IF sy-subrc = 0 .

moff = moff + 20 .

FIND '</field>' IN SECTION OFFSET moff OF ip_content IGNORING CASE MATCH OFFSET moff1 .

lv_len = moff1 - moff .

lv_rate = ip_content+moff(lv_len) .

ls_dest-rate = lv_rate.

ENDIF.

*==============================================================
* Find date and time stamp from api
*==============================================================

FIND '<field name="utctime">' IN SECTION OFFSET moff OF ip_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .

moff = moff + 22 .
FIND '</field>' IN SECTION OFFSET moff OF ip_content IGNORING CASE MATCH OFFSET moff1 .
lv_len = moff1 - moff .
lv_time_date = ip_content+moff(lv_len) .
ls_dest-time_date = lv_time_date.

ENDIF.

* GET TIME form system for verfication .
ls_dest-time_stamp = sy-uzeit.

APPEND ls_dest TO gt_dest.

ELSE.

EXIT.

ENDIF.

ENDDO .

ENDMETHOD.

METHOD get_data .

CLEAR: gt_dest.

DATA: lv_http_client TYPE REF TO if_http_client,
lv_content TYPE string,
lv_url TYPE string.

* Prepare the url of the address
lv_url = 'http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote'.

create_http_client( EXPORTING ip_url = lv_url
IMPORTING ex_http_client = lv_http_client ).

http_client_request_get_method( EXPORTING ip_http_client = lv_http_client ).

http_client_send( EXPORTING ip_http_client = lv_http_client ).

http_client_receive( EXPORTING ip_http_client = lv_http_client
IMPORTING ex_content = lv_content ).

get_data_ex( EXPORTING ip_content = lv_content ).

* Updating data every time
CLEAR:gt_dest1.

me->gt_dest1 = gt_dest.

ENDMETHOD.

METHOD timer_event .

DATA: lv_time TYPE char10.

me->get_data( ) .

IF me->ob_grid IS INITIAL .

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ob_grid.
ELSE.

CALL METHOD ob_grid->refresh_table_display.

ENDIF.

WRITE sy-uzeit TO lv_time USING EDIT MASK '__:__:__'.

CONCATENATE 'Screen refreshed at' lv_time INTO DATA(lv_msg) SEPARATED BY space.

MESSAGE lv_msg TYPE 'S' . " Get the cuuent timE as message

* Call RUN method of CL_GUI_TIMER again to activate timer
me->ob_timer->run( ) .

ENDMETHOD.

METHOD display_report . " Only call for first display

me->get_data( ) .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'ZAUTO_EXC'
TABLES
t_outtab = me->gt_dest1.
ENDMETHOD.

ENDCLASS.

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
DATA : ob_auto TYPE REF TO cl_auto,
ob_timer TYPE REF TO cl_gui_timer.

*--------------------------------------------------------------------*
* Selection Screen Parameters
*--------------------------------------------------------------------*
PARAMETERS : p_refres TYPE char01 AS CHECKBOX,
p_int TYPE i.

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.

* Create main object
CREATE OBJECT ob_auto .

IF p_refres IS NOT INITIAL .

CREATE OBJECT ob_auto->ob_timer .
SET HANDLER ob_auto->timer_event FOR ob_auto->ob_timer .

* Set interval for timer
ob_auto->ob_timer->interval = p_int .

* Call method RUN of CL_GUI_TIMER.
ob_auto->ob_timer->run( ) .

ENDIF.

*--------------------------------------------------------------------*
* End of Selection
*--------------------------------------------------------------------*
END-OF-SELECTION.

* display dat first time
ob_auto->display_report( ) .

 

YOU MAY BE INTERESTED

Future of APIs in SAP: Gazing into the Crystal Ball

SAP API Landscape

Why is it called rapid prototyping?

SAP API Development

 

 

X
WhatsApp WhatsApp us