当前位置:网站首页>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
边栏推荐
- Batch insert data using MySQL bulkloader
- 数据库优化
- Rust 所有权进阶 -- 内存管理
- One to one relationship
- Enumeration and control flow operation in rust
- 数仓的字符截取三胞胎:substrb、substr、substring
- Connection integration development theme month | drivers of enterprise master data governance
- 循环遍历及函数基础知识
- 1025 PAT Ranking
- [help] troubleshooting of JVM's high CPU resource consumption
猜你喜欢

字典树(复习)

Mathematical derivation from perceptron to feedforward neural network

Function key input experiment based on stm32f103zet6 Library

Bit. Store: long bear market, stable stacking products may become the main theme

拥抱云原生:江苏移动订单中心实践

Data intelligence enters the "deep water area", and data governance is the key

数智化进入“深水区”,数据治理是关键

连接集成开发专题月 | 企业主数据治理的驱动因素

爬取国家法律法规数据库

可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹
随机推荐
Buzzer experiment based on stm32f103zet6 library function
UE4-Actor基础知识
实战回忆录:从Webshell开始突破边界
MySQL beginner benefits
C# 二维码生成、识别,去除白边、任意颜色
Rust advanced ownership - memory management
1025 PAT Ranking
Redis cluster Series III
Kotlin微信支付回调后界面卡死并抛出UIPageFragmentActivity WindowLeaked
【云驻共创】 什么是信息化?什么是数字化?这两者有什么联系和区别?
[debug] platform engineering interface debugging
What is ssr/ssg/isr? How do I host them on AWS?
Talk about graduation season
数据库优化
Accumulating power in the middle stage, UFIDA IUAP builds a new base for digital intelligence of social enterprises
Character interception triplets of data warehouse: substrb, substr, substring
Mobile low code development theme month | visual development one click generation of professional source code
UE4:Build Configuration和Config的解释
数组练习 后续补充
Erreur Keil de Huada Single Chip Computer La solution de Weak