SAP发布HTTP接口
1、创建类
引用标准接口
改写集成的接口方法
此处仅实现POST方法,将传入的JSON报文转为函数传入参数,调用获取物料接口,并将返回的物料信息,转换为JSON报文返回
METHOD if_http_extension~handle_request. DATA:lv_method TYPE string, lv_req_json TYPE string, lv_res_json TYPE string. lv_method = server->request->get_header_field( '~request_method' ). * lv_path = server->request->get_header_field( '~request_uri' ). IF lv_method <> 'POST'. server->response->set_header_field( name = 'Content-Type' value = 'text/html' ). server->response->set_cdata( '请使用POST方法' ). server->response->set_status( code = 200 reason = '' ). RETURN. ENDIF. TYPES:BEGIN OF ty_input, i_matnr TYPE marc-matnr, END OF ty_input. DATA:ls_input TYPE ty_input, lt_marc TYPE TABLE OF ymms_marc. TYPES:BEGIN OF ty_output, t_marc LIKE lt_marc, END OF ty_output. DATA:ls_output TYPE ty_output. lv_req_json = server->request->get_cdata( ). /ui2/cl_json=>deserialize( EXPORTING json = lv_req_json pretty_name = /ui2/cl_json=>pretty_mode-camel_case CHANGING data = ls_input ). CALL FUNCTION 'YLCCTEST01_GETMATNR' EXPORTING i_matnr = ls_input-i_matnr TABLES t_marc = lt_marc. ls_output-t_marc = lt_marc. lv_res_json = /ui2/cl_json=>serialize( data = ls_output )."pretty_name = /ui2/cl_json=>pretty_mode-low_case ). server->response->set_status( code = 200 reason = 'successfully' ). " server->response->set_header_field( name = 'Content-Type' value = 'application/json' ). server->response->set_cdata( lv_res_json ). ENDMETHOD.
2、创建WEB服务
事务代码SICF,创建新节点
处理器清单中填上类名称
3、激活并测试服务
定期更文,欢迎关注