当前位置:网站首页>ABAP essay - get new crown data through API
ABAP essay - get new crown data through API
2022-06-27 19:58:00 【Tab Zhu】
Title
Fiori Get novel coronavirus API data
Have a whim to use abap Go to get the information posted on a website api, Then show me
Think of it as a recent study NEPTUNE Let's have a little practice
Baidu's website for getting the epidemic situation API, You can go to tianapi apply ,
METHOD init. url = 'http://api.tianapi.com/txapi/ncovabroad/index?key=****************************'. " establish http client CALL METHOD cl_http_client=>create_by_url EXPORTING url = url IMPORTING client = http_client EXCEPTIONS argument_not_found = 1 plugin_not_active = 2 internal_error = 3 OTHERS = 4. " Set up http method by Get * Set the content format and encoding format of the transmission request http_client->request->set_content_type(
content_type = 'application/json; charset=utf-8' ). * Set call service http_client->request->set_method(
if_http_request=>co_request_method_get ). " send out CALL METHOD http_client->send EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 http_invalid_timeout = 4 OTHERS = 5. " receive CALL METHOD http_client->receive EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3. " Get the data returned by the interface DATA(json_result) = http_client->response->get_cdata( ). DATA lr_data TYPE REF TO data. DATA lr_data_t TYPE REF TO data."table FIELD-SYMBOLS: <table> TYPE STANDARD TABLE, <result> TYPE STANDARD TABLE, <data> TYPE data, <struct> TYPE any, <field> TYPE any. DATA lr_struct TYPE REF TO cl_abap_structdescr. DATA lt_comps_wa TYPE abap_compdescr_tab. " adopt /UI2/CL_JSON=>generate() To pass JSON To convert the inner table
lr_data = /ui2/cl_json=>generate( json = json_result ). ASSIGN lr_data->* TO <data>. ASSIGN COMPONENT 'CODE' OF STRUCTURE <data> TO FIELD-SYMBOL(<code_ref>). ASSIGN <code_ref>->* TO FIELD-SYMBOL(<code>). IF <code> NE 200." call api The news failed , " The output message CLEAR wa_message. wa_message-type = 'E'. wa_message-id = 'ZJXZHU'. wa_message-number = 003. wa_message-message_v1 = <code>. ASSIGN COMPONENT 'MSG' OF STRUCTURE <data> TO FIELD-SYMBOL(<msg_ref>). ASSIGN <msg_ref>->* TO FIELD-SYMBOL(<msg>). wa_message-message_v2 = <msg>. CALL METHOD server->api_message_create EXPORTING message = wa_message. RETURN. ENDIF.
* conversion , code = 200 Indicates successful reception ASSIGN COMPONENT 'NEWSLIST' OF STRUCTURE <data> TO FIELD-SYMBOL(<list>). IF sy-subrc EQ 0. lr_data = <list>. ASSIGN lr_data->* TO <table>. READ TABLE <table> INTO lr_data INDEX 1. IF sy-subrc EQ 0. LOOP AT <table> ASSIGNING FIELD-SYMBOL(<table_line>). ASSIGN <table_line>->* TO <data>. APPEND INITIAL LINE TO gt_data ASSIGNING FIELD-SYMBOL(<fs_data>). " obtain typeof lr_struct ?= cl_abap_typedescr=>describe_by_data( <data> ). lt_comps_wa = lr_struct->components. LOOP AT lt_comps_wa INTO DATA(ls_comps_wa). ASSIGN COMPONENT ls_comps_wa-name OF STRUCTURE <fs_data> TO <field>. IF sy-subrc EQ 0. ASSIGN COMPONENT ls_comps_wa-name OF STRUCTURE <data> TO FIELD-SYMBOL(<value_ref>). IF sy-subrc EQ 0. ASSIGN <value_ref>->* TO FIELD-SYMBOL(<value>). IF sy-subrc EQ 0. <field> = <value>. ENDIF. ENDIF. ENDIF. ENDLOOP. ENDLOOP. ENDIF. ENDIF. ENDMETHOD.
When calling this class to execute, you can find :LR_DATA->CODE->* = 200
LR_DATA->MSG->* = success
about NEWSLIST Each row is a structure object
Double click in , It can be seen that the latest data of the COVID-19 in the United States have been obtained , Every line is a country
According to the above structure , We can create global variables GT_DATA
DATA: BEGIN OF gs_data, confirmedcount TYPE i, " Number of confirmed cases confirmedcountrank TYPE i, " The number of confirmed cases continents TYPE string, " Continent countryshortcode TYPE string, " Country code curedcount TYPE i, " The number of people cured currentconfirmedcount TYPE i, " Current confirmed number deadcount TYPE i, " The number of deaths deadcountrank TYPE i, " Death toll ranking deadrate TYPE string, " mortality deadraterank TYPE i, " Mortality ranking locationid TYPE i, " Address location modifytime TYPE i, " Update time provincename TYPE string, " Country name END OF gs_data . DATA: gt_data LIKE TABLE OF gs_data .
Display the acquired data on the mobile phone / Flat side :
You can click the icon at the top right , Get the top ranking of cumulative diagnosis 20 Country bar chart of names :
You can see when we query , The number of confirmed cases in the United States has reached
Is to make a simple data table and chart Let's learn
边栏推荐
- Seven phases of CMS implementation
- qt中文乱码
- 可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹
- # Leetcode 821. 字符的最短距离(简单)
- 1025 PAT Ranking
- Leetcode 989. 数组形式的整数加法(简单)
- 网络上开户买股票是否安全呢?刚接触股票,不懂求指导
- Running lantern experiment based on stm32f103zet6 library function
- redis集群系列二
- Memoirs of actual combat: breaking the border from webshell
猜你喜欢

海底电缆探测技术总结

【bug】联想小新出现问题,你的PIN不可用。

Array exercises follow up

Doctoral Dissertation of the University of Toronto - training efficiency and robustness in deep learning

Connection integration development theme month | drivers of enterprise master data governance

MySQL初学者福利

GIS遥感R语言学习看这里

《第五项修炼》(The Fifth Discipline):学习型组织的艺术与实践

Redis集群

Web APls 阶段——第十四节——本地存储
随机推荐
金鱼哥RHCA回忆录:DO447管理项目和开展作业--创建作业模板并启动作业
Bit. Store: long bear market, stable stacking products may become the main theme
【debug】平台工程接口调试
Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance
Adding, deleting, modifying and querying MySQL tables (basic)
NVIDIA Clara-AGX-Developer-Kit installation
Leetcode 1381. 设计一个支持增量操作的栈
rust 中的结构体
1028 List Sorting
【bug】联想小新出现问题,你的PIN不可用。
【登录界面】
[login interface]
redis集群系列二
Connection integration development theme month | drivers of enterprise master data governance
Buzzer experiment based on stm32f103zet6 library function
数据库日志
Data intelligence enters the "deep water area", and data governance is the key
Mathematical derivation from perceptron to feedforward neural network
谈谈线程安全
# Leetcode 821. 字符的最短距离(简单)