1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
CONCATENATE: '' ' ' ' ' ' ' ' ' IV_INPUT-ACCNO '' ' ' IV_INPUT-PROV '' ' ' IV_INPUT-BDATUM '' INTO L_INPUT. CONCATENATE: L_INPUT ' ' IV_INPUT-EDATUM '' ' ' ' ' '' INTO L_INPUT. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
FUNCTION ZFM_ABC_YQZL. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" REFERENCE(IV_URL) TYPE STRING *" REFERENCE(IV_INPUT) TYPE STRING *" EXPORTING *" REFERENCE(EV_OUTPUT) TYPE STRING *" VALUE(EV_MSGTX) TYPE MSGTX *" VALUE(EV_SUCC) TYPE FLAG *"---------------------------------------------------------------------- *http://10.0.18.100:8080/abcAP/services/SendAndReceive_CQRA10 DATA: LV_CODE TYPE I, LV_REASON TYPE STRING. TYPES: BEGIN OF XML_LINE, DATA(256) TYPE X, END OF XML_LINE. DATA: XML_TABLE TYPE TABLE OF XML_LINE. DATA: LV_XINPUT TYPE XSTRING . DATA: LV_LEN_CONV TYPE I, "转码后的xml长度 LV_HTTP_RETURN_CDATA TYPE STRING, "http 调用返回的xml (cdata) LV_HTTP_RETURN_DATA TYPE XSTRING, "http调用返回的data LV_HTTP_RETURN_CONV TYPE STRING. "http调用返回的xml转码后的内容 DATA: HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT. "调用的http对象 DATA: L_URL TYPE STRING . EV_MSGTX = ''. EV_SUCC = 'X'. L_URL = IV_URL. IF L_URL = ''. L_URL = 'http://10.0.18.100:8080/abcAP/services/SendAndReceive_CQRA10'. ENDIF. * STRING 转换XSTRING CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING TEXT = IV_INPUT * MIMETYPE = ' ' * ENCODING = IMPORTING BUFFER = LV_XINPUT * EXCEPTIONS * FAILED = 1 * OTHERS = 2 . IF SY-SUBRC 0. * Implement suitable error handling here ENDIF. CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL EXPORTING URL = L_URL IMPORTING CLIENT = HTTP_CLIENT EXCEPTIONS ARGUMENT_NOT_FOUND = 1 PLUGIN_NOT_ACTIVE = 2 INTERNAL_ERROR = 3 OTHERS = 4. "Available API Endpoints IF SY-SUBRC 0. "error handling ENDIF. LV_LEN_CONV = STRLEN( IV_INPUT ). *设置抬头字段 CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD EXPORTING NAME = '~request_method' VALUE = 'POST'. CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD EXPORTING NAME = 'Content-Type' VALUE = 'text/xml; charset=UTF-8'. " CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD EXPORTING NAME = 'SOAPAction' VALUE = ''. CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD EXPORTING NAME = 'User-Agent' VALUE = 'Apache-HttpClient/4.1.1 (java 1.5)'. CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD EXPORTING NAME = 'Accept-Encoding' VALUE = 'gzip,deflate'. CALL METHOD HTTP_CLIENT->REQUEST->SET_DATA EXPORTING DATA = LV_XINPUT OFFSET = 0. * length = lv_len_conv. *发送报文 CALL METHOD HTTP_CLIENT->SEND EXCEPTIONS HTTP_COMMUNICATION_FAILURE = 1 HTTP_INVALID_STATE = 2. *接受报文的返回 CALL METHOD HTTP_CLIENT->RECEIVE EXCEPTIONS HTTP_COMMUNICATION_FAILURE = 1 HTTP_INVALID_STATE = 2 HTTP_PROCESSING_FAILED = 3. *获取返回的保温 CLEAR LV_HTTP_RETURN_CDATA. LV_HTTP_RETURN_CDATA = HTTP_CLIENT->RESPONSE->GET_CDATA( ). LV_HTTP_RETURN_DATA = HTTP_CLIENT->RESPONSE->GET_DATA( ). * CONDENSE lv_http_return_cdata NO-GAPS. CLEAR:LV_CODE , LV_REASON . CALL METHOD HTTP_CLIENT->RESPONSE->GET_STATUS IMPORTING CODE = LV_CODE "200 REASON = LV_REASON. "OK_CODE *关闭http连接 CALL METHOD HTTP_CLIENT->CLOSE. IF LV_CODE = '500'. EV_SUCC = ''. CONCATENATE '连接地址' L_URL '失败,请确认银行前置机服务已开启' INTO EV_MSGTX. ELSEIF LV_CODE '200'. EV_SUCC = ''. CONCATENATE '连接地址' L_URL '失败,请确认服务已开启' INTO EV_MSGTX. ENDIF. *转换 lv_http_return_data DATA:L_R_CONVERTER TYPE REF TO CL_ABAP_CONV_IN_CE. TRY. CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE EXPORTING ENCODING = '8400' * endian = 'B' * replacement = '#' * ignore_cerr = ABAP_FALSE INPUT = LV_HTTP_RETURN_DATA RECEIVING CONV = L_R_CONVERTER. CALL METHOD L_R_CONVERTER->READ IMPORTING DATA = EV_OUTPUT. REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>NEWLINE IN EV_OUTPUT WITH '' IN CHARACTER MODE. CATCH CX_SY_CODEPAGE_CONVERTER_INIT. * 处理错误 CATCH CX_ROOT. * 处理错误 ENDTRY. ENDFUNCTION. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
FUNCTION ZFM_XML2TABLE2. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" REFERENCE(IV_INPUT) TYPE STRING *" EXPORTING *" REFERENCE(EV_NODES) TYPE ANY *" REFERENCE(EV_ERROR_MSG) TYPE STRING *" TABLES *" ET_TABLE TYPE TABLE *"---------------------------------------------------------------------- * IV_INPUT-需要转换为内表的XML字符串 * EV_NODES-除内表外其他节点,需在主程序中定义好结构类型,字段和XML中节点名称一致 * ET_TABLE-XML转换后内表格式,需在主程序中定义好表类型,字段和XML中节点名称一致 * Global data declarations DATA: LC_NODE TYPE REF TO IF_IXML_NODE, LC_LINE TYPE I. DATA: LIT_NAMES TYPE TABLE OF ABAP_COMPDESCR, LWA_NAMES TYPE ABAP_COMPDESCR. DATA: LC_TABLEDESC TYPE REF TO CL_ABAP_TABLEDESCR, LC_STRUCTDESC TYPE REF TO CL_ABAP_STRUCTDESCR, LC_NAME TYPE CHAR30. CLEAR: EV_ERROR_MSG, ET_TABLE[]. LC_TABLEDESC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( ET_TABLE[] ). LC_STRUCTDESC ?= LC_TABLEDESC->GET_TABLE_LINE_TYPE( ). LIT_NAMES[] = LC_STRUCTDESC->COMPONENTS. DESCRIBE TABLE LIT_NAMES LINES LC_LINE. READ TABLE LIT_NAMES INTO LWA_NAMES INDEX LC_LINE. LC_NAME = LWA_NAMES-NAME. PERFORM FRM_XML_CONVERT USING IV_INPUT CHANGING EV_ERROR_MSG. CHECK EV_ERROR_MSG IS INITIAL. LC_NODE = GC_NODE. PERFORM FRM_XML_PARSE_TO_TABLE TABLES ET_TABLE USING LC_NODE LC_NAME EV_NODES. ENDFUNCTION. |