我想在abap中使用CL_JAVA_SCRIPT执行一个javascript文件:jQuery.js,我从url获取。 这是我的代码:
REPORT ZCLIENT.
DATA: LV_CLIENT TYPE REF TO IF_HTTP_CLIENT.
DATA:lv_URL TYPE STRING .
lv_URL = 'https://resources/jquery.js'.
* Create client
CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
EXPORTING
URL = lv_URL
IMPORTING
CLIENT = LV_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3
OTHERS = 4.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* LV_CLIENT->REQUEST->SET_CONTENT_TYPE(
* EXPORTING
* CONTENT_TYPE = 'application/javascript; charset=UTF-8'
* ).
CALL METHOD LV_CLIENT->REQUEST->SET_FORMFIELD_ENCODING
EXPORTING
FORMFIELD_ENCODING = LV_CLIENT->REQUEST->CO_ENCODING_URL.
* Get request:
CALL METHOD LV_CLIENT->SEND
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
OTHERS = 4.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Prepare client-receive:
CALL METHOD LV_CLIENT->RECEIVE
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
OTHERS = 4.
* Get HTML:
DATA EV_DATA TYPE STRING.
CONSTANTS co_line_size TYPE i VALUE 150.
TYPES: t_line TYPE c LENGTH co_line_size.
DATA: l_string TYPE string,
lt_lines TYPE TABLE OF t_line.
FIELD-SYMBOLS: <l_line> TYPE t_line.
EV_DATA = LV_CLIENT->RESPONSE->GET_CDATA( ).
" compile js
data GET_VALUE type STRING.
data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.
data SOURCE type STRING.
concatenate EV_DATA SOURCE into SOURCE SEPARATED BY cl_abap_char_utilities=>cr_lf.
JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).
JS_PROCESSOR->COMPILE( SCRIPT_NAME = 'TEST_GET.JS'
SCRIPT = EV_DATA ).
if JS_PROCESSOR->LAST_CONDITION_CODE <> 0.
write: / 'Error in COMPILE',
JS_PROCESSOR->LAST_ERROR_MESSAGE.
else.
write / 'JavaScript was compiled'.
endif.
skip.
JS_PROCESSOR->EXECUTE(
exporting SCRIPT_NAME = 'TEST_GET.JS' ).
if JS_PROCESSOR->LAST_CONDITION_CODE <> 0.
write: / 'Error in EXECUTE',
JS_PROCESSOR->LAST_ERROR_MESSAGE.
else.
write / 'JavaScript was executed'.
endif.
skip.
我的文件编译得很好但是在执行我的代码时我得到了一些错误,例如&#34;窗口没有定义&#34;
如何解决问题
答案 0 :(得分:4)
jQuery是一个JavaScript库,设计用于浏览器的文档对象模型(DOM),它用于UI,动画,客户端逻辑等。它构建在DOM和所有功能之上依赖于此,尝试在ABAP系统上执行jQuery.js文件将无法正常工作,因为没有浏览器,并且没有用于与jQuery交互的DOM。
您可以在SAP网站ABAP Application Server页面上找到有关ABAP服务器的更多信息及其功能和不执行的操作。