当前位置:网站首页>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
边栏推荐
- Online text batch inversion by line tool
- Error reported by Huada MCU Keil_ Weak's solution
- Buzzer experiment based on stm32f103zet6 library function
- 判断一个变量是数组还是对象?
- Golang map 并发读写问题源码分析
- redis集群系列二
- Common shell script commands (III)
- Photoshop layer related concepts layercomp layers move rotate duplicate layer compound layer
- MASS幸运哈希游戏系统开发丨冲突解决方法(代码分析)
- rust 中的结构体
猜你喜欢
crontab的学习随笔
Data intelligence enters the "deep water area", and data governance is the key
数智化进入“深水区”,数据治理是关键
Redis集群
蓄力中台,用友iuap筑牢社会级企业数智化新底座
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
GIS遥感R语言学习看这里
Oracle 获取月初、月末时间,获取上一月月初、月末时间
Summary of submarine cable detection technology
Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance
随机推荐
Rust 所有权进阶 -- 内存管理
从指令交读掌握函数调用堆栈详细过程
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Data intelligence enters the "deep water area", and data governance is the key
流程判断-三目运算-for循环
1028 List Sorting
移动低代码开发专题月 | 可视化开发 一键生成专业级源码
Mathematical derivation from perceptron to feedforward neural network
1025 PAT Ranking
(LC)46. Full Permutation
高收益银行理财产品在哪里看?
MySQL初学者福利
[bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.
Determine whether a variable is an array or an object?
1030 Travel Plan
1024 Palindromic Number
刷题记录:Easy 数组(持续更新)
【debug】平台工程接口调试
数仓的字符截取三胞胎:substrb、substr、substring
Is the account opening QR code given by CICC securities manager safe? Who can I open an account with?