我正在做一个SAP接口项目,其中标准调用通常是Internet Explorer。我试图收集IE中HTML处理的信息,并使用以下代码将其发送到SAP:
REPORT demo_html_input.
INCLUDE: ZCAS_TEXT_POST_HTML_SRC.
TYPES: typ_html_code TYPE TABLE OF char255 WITH EMPTY KEY,
typ_source TYPE TABLE OF string.
CLASS html_start DEFINITION.
PUBLIC SECTION.
METHODS: constructor,
txt_html RETURNING VALUE(lt_codigo) TYPE string.
PRIVATE SECTION.
data: lv_html_code type string.
METHODS: get_source,
descomented
IMPORTING
lt_source TYPE typ_source
EXPORTING
lv_html_code TYPE string.
ENDCLASS.
CLASS html_start IMPLEMENTATION.
METHOD constructor.
get_source( ).
endmethod.
METHOD txt_html.
lt_codigo = lv_html_code.
ENDMETHOD.
METHOD get_source.
DATA: lt_source TYPE TABLE OF string.
CALL METHOD cl_reca_rs_services=>get_source
EXPORTING
id_objtype = 'PROG'
id_objname = 'ZCAS_TEXT_POST_HTML_SRC'
IMPORTING
et_source = lt_source.
descomented( EXPORTING
lt_source = lt_source
IMPORTING
lv_html_code = lv_html_code ).
ENDMETHOD.
METHOD descomented.
DATA: ls_html_code TYPE char255.
DATA: ls_source TYPE string.
DATA: lv_len_data TYPE i,
lv_len_source TYPE i,
lv_len_total TYPE i,
lv_str_max type i,
lv_string TYPE string.
LOOP AT lt_source INTO ls_source.
TRY .
ls_source = ls_source+1.
CATCH cx_sy_range_out_of_bounds.
ENDTRY.
SHIFT ls_source RIGHT DELETING TRAILING ' '.
SHIFT ls_source LEFT DELETING LEADING ' '.
lv_string = ls_source .
CONCATENATE lv_html_code lv_string INTO lv_html_code.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
CLASS-METHODS handle_sapevent
FOR EVENT sapevent
OF cl_abap_browser
IMPORTING action
query_table.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA error_list TYPE cl_abap_browser=>html_table.
SET HANDLER handle_sapevent.
DATA: retorncode TYPE REF TO html_start.
CREATE OBJECT retorncode.
DATA(html_str) = retorncode->txt_html( ).
cl_abap_browser=>show_html(
EXPORTING
html_string = html_str
title = 'Input Demo'
IMPORTING
html_errors = error_list ).
IF error_list IS NOT INITIAL.
MESSAGE 'Error in HTML' TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDMETHOD.
METHOD handle_sapevent.
BREAK-POINT.
DATA(out) = cl_demo_output_stream=>open( ).
SET HANDLER cl_demo_output_html=>handle_output FOR out.
out->write_data( iv_name = 'ACTION' ia_value = action ).
out->write_data( iv_name = 'QUERY_TABLE' ia_value = query_table ).
out->close( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
字符串
在ABAP调用中,发送到带有前缀SAPEVENT:的URL的任何信息都被重定向到handle_sapevent方法。
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenhtml_input_abexa.htm
我使用了这个HTML:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<title>Document</title>
</head>
<body>
<input type="button" id="btn" onclick="">
</body>
<script>
document.getElementById('btn').addEventListener('click', function sendTOAbap(ev) {
var oOutput = document.querySelector("div"),
oData = {
campo: "sucesso",
field: "insucesso"
};
oData.append("CustomField", "This is some extra data");
var oReq = new XMLHttpRequest();
oReq.open("POST", "SAPEVENT:SAPEVENT", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
console.log("Uploaded!");
} else {
console.log("Error " + oReq.status + " occurred when trying to upload your file.");
}
};
oReq.send(oData);
ev.preventDefault();
}, false);
</script>
</html>
型
问题是,当我试图运行它专门使用Internet Explorer,它返回一个“访问被拒绝”或“未传输”错误。我不能改变浏览器版本,因为它是SAP标准。Tankyou帮助我。
我试着改变访问策略,改变发布方法,改变正文。
1条答案
按热度按时间chy5wohz1#
ok,我用这个脚本解决了这个问题
字符串
是简单使用de sapevent像一个API,使用这个任何参数来sap。