当前位置:网站首页>[SAP ABAP] call API interface instance
[SAP ABAP] call API interface instance
2022-06-23 20:34:00 【Jeff Wei】
FUNCTION zhri_rfc_uim_creat_id .
*"----------------------------------------------------------------------
*"*" Local interface :
*" IMPORTING
*" VALUE(IT_DATA) TYPE ZHRS_UIM_CREAT_T
*" EXPORTING
*" REFERENCE(OT_MSG) TYPE ZHRS_UIM_CREAT_MSG_T
*"----------------------------------------------------------------------
*--------------------------------------------------------------------*
* Definition json My watch
DATA: lt_data TYPE TABLE OF zhrs_uim_creat,
ls_data TYPE zhrs_uim_creat.
DATA: lrf_descr TYPE REF TO cl_abap_typedescr,
lv_json TYPE /ui2/cl_json=>json.
DATA: len TYPE i, " Send message length
len_string TYPE string,
url TYPE string, " Address of the interface
host TYPE string,
http_client TYPE REF TO if_http_client, "http client
post_string TYPE string,
result TYPE string.
DATA:lv_name_password TYPE string,
lv_md5 TYPE md5_fields-hash,
lv_str_md5 TYPE string.
DATA:lv_code TYPE sysubrc,
lv_message TYPE string.
DATA: it_header TYPE tihttpnvp.
DATA:iv_name TYPE string, " user name
iv_password TYPE string. " password
TYPES:BEGIN OF ty_token,
token TYPE string,
code TYPE string,
description TYPE string,
END OF ty_token.
DATA:ls_token TYPE ty_token.
TYPES:BEGIN OF ty_result,
code TYPE string,
description TYPE string,
result TYPE zhrs_uim_result,
END OF ty_result.
DATA:ls_result TYPE ty_result.
DATA:ls_result_d TYPE zhrs_uim_result_s." Detailed results
DATA: lv_tokentype TYPE char1,
lv_tokenmsg TYPE string.
DATA:ls_msg TYPE zhrs_uim_creat_msg.
DATA:ls_t004 TYPE zhrt_004.
"URL Address
SELECT SINGLE * INTO ls_t004 FROM zhrt_004
WHERE sysid = sy-sysid
AND type = 'UIM'.
MOVE ls_t004-url TO host." Address
MOVE ls_t004-uname TO iv_name." user name
MOVE ls_t004-password TO iv_password." password
IF host IS NOT INITIAL.
*************************** Log ************************************
zlylog 'ZHRI_RFC_UIM_CREAT_ID' '01' ''."# Log
************************** Address acquisition account password acquisition **************************
**********************************************************************
*1 obtain token start
**********************************************************************
CONCATENATE host '/api/Auth/GetToken' INTO url.
" 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.
* Create the type and format of the transmitted content
http_client->request->set_content_type( content_type = 'application/json; charset=utf-8' ).
* http_client->request->set_method( if_http_request=>co_request_method_post ).
http_client->request->set_method( if_http_request=>co_request_method_get )."yong get Method
* Encrypt user name and password ~~MD5 encryption
CONCATENATE iv_name ':' iv_password INTO lv_name_password .
CALL FUNCTION 'MD5_CALCULATE_HASH_FOR_CHAR'
EXPORTING
data = lv_name_password
length = 0
IMPORTING
hash = lv_md5.
MOVE lv_md5 TO lv_str_md5 .
** Set the request head
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Authorization'
value = lv_str_md5.
" 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.
IF sy-subrc <> 0.
lv_tokentype = 'E'.
lv_tokenmsg = ' obtain UIMtoken Failure , Please check the incoming account password and connection status '.
ELSE.
result = http_client->response->get_cdata( ).
*** Parsing returns json To internal table
/ui2/cl_json=>deserialize(
EXPORTING json = result
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
CHANGING data = ls_token ).
IF ls_token-token IS INITIAL.
lv_tokentype = 'E'.
MOVE ls_token-description TO lv_tokenmsg.
ENDIF.
ENDIF.
**********************************************************************
* obtain token end
**********************************************************************
**********************************************************************
* Call the create function to start
**********************************************************************
IF ls_token-token IS NOT INITIAL.
CLEAR url.
** Splice creation address
CONCATENATE host '/api/ADUser/CreateADUser' INTO url.
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.
*** Setup method
http_client->request->set_method( if_http_request=>co_request_method_post ).
*** Set up head
http_client->request->set_header_field( name = 'Content-Type' value = 'application/json' ).
http_client->request->set_header_field( name = 'Authorization' value = ls_token-token ).
* APPEND iv_data TO lt_data.
**** Set the request body
lv_json = /ui2/cl_json=>serialize( data = it_data
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
compress = abap_true
).
*** Set length
len = strlen( lv_json ).
*** Set up the data
CALL METHOD http_client->request->set_cdata
EXPORTING
data = lv_json
offset = 0
length = len.
*** send data
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4.
ENDIF.
*** Get message
CALL METHOD http_client->get_last_error
IMPORTING
code = lv_code
message = lv_message.
*** Return results
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
*** Capture the return message
CALL METHOD http_client->get_last_error
IMPORTING
code = lv_code
message = lv_message.
CLEAR result .
result = http_client->response->get_cdata( ).
*** Resolve to inner table
/ui2/cl_json=>deserialize(
EXPORTING json = result
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
CHANGING data = ls_result ).
* MOVE ls_result-description TO ov_msg .
LOOP AT it_data INTO ls_data.
MOVE ls_data-_sam_account_name TO ls_msg-perid.
CLEAR ls_result_d.
READ TABLE ls_result-result INTO ls_result_d
WITH KEY samaccountname = ls_data-_sam_account_name.
IF sy-subrc = 0.
ls_msg-ov_msgty = 'S'.
ls_msg-ov_msg = ' Generate successfully '.
ELSE.
IF lv_tokentype = 'E'.
ls_msg-ov_msgty = 'E'.
MOVE lv_tokenmsg TO ls_msg-ov_msg.
ELSE.
ls_msg-ov_msgty = 'E'.
ls_msg-ov_msg = ' Create failure '.
ENDIF.
ENDIF.
APPEND ls_msg TO ot_msg.
CLEAR ls_msg.
ENDLOOP.
* IF ls_result-code NE '000000'.
* ov_msgty = 'E'.
* ELSE.
* ov_msgty = 'S'.
* ENDIF.
zlylog 'ZHRI_RFC_UIM_CREAT_ID' '02' ''."# Log
ENDIF.
ENDFUNCTION.边栏推荐
- 35岁危机?内卷成程序员代名词了…
- Is it safe for flush to open an account online? Is the Commission high
- Kinsoku Jikou Desu Sina stock interface change
- Zabbix监控- Aruba AP运行数据
- SQL联合查询(内联、左联、右联、全联)的语法
- CPS 22 January additional incentive rules
- SAP实施项目上的内部顾问与外部顾问,相互为难还是相互成就?
- LeetCode 473. Match to square
- UGeek大咖说 | 可观测之超融合存储系统的应用与设计
- How is the picture mosaic clear? What is mosaic for?
猜你喜欢

图扑软件数字孪生智慧水务,突破海绵城市发展困境

SQL聯合查詢(內聯、左聯、右聯、全聯)的語法

FPGA based electromagnetic ultrasonic pulse compression detection system paper + source file

Implementation of microblog system based on SSM

Syntaxe des requêtes fédérées SQL (inline, left, right, full)

Development of block hash quiz game system (DAPP)

80% of people will be wrong about the three counter intuitive questions?

The evolution of the "Rainbow Bridge" middleware platform for the acquisition database based on shardingsphere

小程序开发框架推荐

ElastricSearch第二弹之分片原理
随机推荐
Emmet语法规范
如何利用数仓创建时序表
图扑软件数字孪生智慧水务,突破海绵城市发展困境
Why is only one value displayed on your data graph?
CPS 22 January additional incentive rules
SQL聯合查詢(內聯、左聯、右聯、全聯)的語法
WinDbg loads mex DLL analysis DMP file
Syntax of SQL union query (inline, left, right, and full)
Development of block hash quiz game system (DAPP)
【Golang】在Go语言的角度重新审视闭包
Which is better for securities companies? I don't understand. Is it safe to open an account online?
同花顺网上开户安全吗,佣金高不高
MySQL时间函数的运用,简单问题
Stochastic process -- Markov chain
Official announcement. Net 7 preview 5
How to deal with unclear pictures? How to deal with color balance?
20省市公布元宇宙路线图
基于SSM实现微博系统
【Golang】快速复习指南QuickReview(四)——函数
Cloudbase init considerations