今天在写农业银行的CQRA10交易 (交易明细查询)时,农行使用的是SOCKET,所以做了SOCKET转WEBService的JAVA服务(细节参看过里)。但返回的报文中记录的是文件名(此文件在农行前置机的\detail目录下),并没有返回交易记录的数据,所以需要再次读取此文件,解决办法是把此目录建立 为WEB服务,或者FTP目录,之前使用的是WEB服务的方式,感觉WEB服务搞起来更简单直接些,但当前项目由于是历史 代码,所以不想修改太多就使用了FTP方式,在前置服务器上搭建好后,在ABAP代码中先从报文中得到返回的文件名,然后再读取文件内容,
注:
1.使用FTP时,需要先SM30对表SAPFTP_SERVERS_V进行维护,增加外部可用的FTP服务器地址及端口,为了方便,可以直接把地址设置为*,这样所有的FTP地址都可以使用了。
2.在代码中由于有中文,所以需先得到BIN的内表,再使用SCMS_BINARY_TO_TEXT把BIN的二进制 值 转换为GB2312,如直接在FTP_SERVER_TO_R3中取得文件字符 文本到内表的话,有中文时会出现乱码。
以下代码是农行在接收到报文后的数据处理代码,
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
*****从农行前置机获取明细交易数据 TYPES: BEGIN OF T_TEXT, TEXT(2000) TYPE C, END OF T_TEXT. DATA: I_TEXT TYPE TABLE OF T_TEXT, I_TEXT2 TYPE TABLE OF T_TEXT, MX TYPE TABLE OF T_TEXT, MX1 TYPE TABLE OF T_TEXT, MXS LIKE LINE OF MX, WA_TEXT TYPE T_TEXT, i_bintab TYPE w3mimetabtype . DATA:LV_HDL TYPE I, LV_KEY TYPE I VALUE 26101957, LV_SLEN TYPE I, LV_CMD(120), LV_PWD TYPE TEXT30, LI_RESULT TYPE TABLE OF TEXT256 , "WITH HEADER LINE, LS_RESULT TYPE TEXT256, RESULT TYPE TABLE OF TEXT256, LV_DEST TYPE RFCDES-RFCDEST, LV_FTPNAME TYPE TEXT150, LN TYPE I, bLEN TYPE I. SELECT SINGLE * INTO @DATA(FTP) FROM ****_CN_FTP WHERE BANK_IND = 'ABC'. LV_DEST = FTP-DEST. * IF sy-batch IS INITIAL. * lv_dest = 'SAPFTP'. * ELSE. * lv_dest = 'SAPFTPA'. * ENDIF. SET EXTENDED CHECK OFF. * Connect to server LV_SLEN = STRLEN( FTP-PASSWD ). CALL FUNCTION 'HTTP_SCRAMBLE' "获取加密密码 EXPORTING SOURCE = FTP-PASSWD "'abc@123!' SOURCELEN = LV_SLEN KEY = LV_KEY IMPORTING DESTINATION = LV_PWD. *lv_pwd = ftp-passwd . DO 3 TIMES. CALL FUNCTION 'FTP_CONNECT' "连接ftp服务器 EXPORTING USER = FTP-UESR "'abc' "p_user PASSWORD = LV_PWD HOST = FTP-HOST "'172.18.4.127' "p_host RFC_DESTINATION = FTP-DEST IMPORTING HANDLE = LV_HDL "连接的句柄 EXCEPTIONS NOT_CONNECTED = 1 OTHERS = 2. IF SY-SUBRC = 0. EXIT. ENDIF. ENDDO. " DATA(wrkdir) = ftp-wrkdir." ''\PROGRAM Files (x86)\中国农业银行\中国农业银行银企通平台\detail'. CONCATENATE 'cd' FTP-WRKDIR INTO LV_CMD SEPARATED BY SPACE. CALL FUNCTION 'FTP_COMMAND' "打开目标文件夹 EXPORTING HANDLE = LV_HDL COMMAND = LV_CMD TABLES DATA = LI_RESULT EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3. CLEAR: LI_RESULT. REFRESH LI_RESULT. LV_CMD = 'ls'. CALL FUNCTION 'FTP_COMMAND' "获取文件夹文件目录 EXPORTING HANDLE = LV_HDL COMMAND = LV_CMD TABLES DATA = LI_RESULT EXCEPTIONS TCPIP_ERROR = 1 COMMAND_ERROR = 2 DATA_ERROR = 3. LOOP AT LI_RESULT INTO LS_RESULT. SEARCH LS_RESULT FOR FILE . IF SY-SUBRC = 0. " PERFORM ftp_reconnect. * CALL FUNCTION 'FTP_COMMAND' * EXPORTING * HANDLE = LV_HDL * COMMAND = 'BIN' "'ASCII' * TABLES * DATA = RESULT * EXCEPTIONS * TCPIP_ERROR = 1 * COMMAND_ERROR = 2 * DATA_ERROR = 3. * CLEAR: RESULT. * REFRESH RESULT. LV_FTPNAME = FILE. REFRESH I_TEXT. CALL FUNCTION 'FTP_SERVER_TO_R3' EXPORTING HANDLE = LV_HDL FNAME = LV_FTPNAME * CHARACTER_MODE = 'X' IMPORTING BLOB_LENGTH = bLEN TABLES * TEXT = I_TEXT BLOB = i_bintab . CALL FUNCTION 'SCMS_BINARY_TO_TEXT' EXPORTING INPUT_LENGTH = BLEN ENCODING = '8400' "4110:UTF8,8400:GB2312 IMPORTING OUTPUT_LENGTH = BLEN TABLES BINARY_TAB = i_bintab TEXT_TAB = I_TEXT EXCEPTIONS FAILED = 1 OTHERS = 2. IF I_TEXT[] IS NOT INITIAL. CLEAR:LN. REFRESH MX1. LOOP AT I_TEXT INTO WA_TEXT ."FROM 1. REFRESH MX. SPLIT WA_TEXT AT '|' INTO TABLE MX. IF LN IS INITIAL. LN = LINES( MX ) ."明细交易的字段数量 ENDIF. APPEND LINES OF MX[] TO MX1[]. ENDLOOP. ENDIF. ENDIF. ENDLOOP. CALL FUNCTION 'FTP_DISCONNECT' EXPORTING HANDLE = LV_HDL. CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING DESTINATION = LV_DEST EXCEPTIONS OTHERS = 1. **********从农行前置机获取明细交易数据 DATA(LS_SENDING_FILE) = GET_CURRENT_SENDING_FILE( ). ASSIGN SENDING_DATA_REFERENCE->* TO <FT_SENDING_DATA>. READ TABLE <FT_SENDING_DATA> INTO DATA(LS_SENDING_DATA) WITH KEY SEQNUMBER = CURRENT_SENDING_SEQUENCE. DATA: TB_FT_BANK_ENTRIES TYPE TABLE OF ZTRT_ABC_TRNS. DATA: TS_FT_BANK_ENTRIES TYPE ZTRT_ABC_TRNS. DATA: IK TYPE I. IK = 0. LOOP AT MX1 INTO MXS. IK = IK + 1. * CASE IK. WHEN 1. TS_FT_BANK_ENTRIES-DBPROV = MXS-TEXT. WHEN 2. TS_FT_BANK_ENTRIES-ACCNO = MXS-TEXT. WHEN 3. TS_FT_BANK_ENTRIES-DBCUR = MXS-TEXT. WHEN 4. TS_FT_BANK_ENTRIES-TRDATE = MXS-TEXT. WHEN 5. TS_FT_BANK_ENTRIES-TIMESTAB = MXS-TEXT. WHEN 6. TS_FT_BANK_ENTRIES-JRNNO = MXS-TEXT. WHEN 7. TS_FT_BANK_ENTRIES-TRTYPE = MXS-TEXT. WHEN 8. TS_FT_BANK_ENTRIES-BANKNO = MXS-TEXT. WHEN 9. TS_FT_BANK_ENTRIES-ACCNAME = MXS-TEXT. WHEN 10. TS_FT_BANK_ENTRIES-AMTINDEX = MXS-TEXT. WHEN 11. TS_FT_BANK_ENTRIES-OPPPROV = MXS-TEXT. WHEN 12. TS_FT_BANK_ENTRIES-OPPACCNO = MXS-TEXT. WHEN 13. TS_FT_BANK_ENTRIES-OPPCUR = MXS-TEXT. WHEN 14. TS_FT_BANK_ENTRIES-OPPNAME = MXS-TEXT. WHEN 15. TS_FT_BANK_ENTRIES-OPPBKNAME = MXS-TEXT. WHEN 16. TS_FT_BANK_ENTRIES-CSHINDEX = MXS-TEXT. WHEN 17. TS_FT_BANK_ENTRIES-ERRDATE = MXS-TEXT. WHEN 18. TS_FT_BANK_ENTRIES-ERRVCHNO = MXS-TEXT. WHEN 19. TS_FT_BANK_ENTRIES-AMT = MXS-TEXT. WHEN 20. TS_FT_BANK_ENTRIES-BAL = MXS-TEXT. WHEN 21. TS_FT_BANK_ENTRIES-PREAMT = MXS-TEXT. WHEN 22. TS_FT_BANK_ENTRIES-TOTCHG = MXS-TEXT. WHEN 23. TS_FT_BANK_ENTRIES-VOUCHERTYPE = MXS-TEXT. WHEN 24. TS_FT_BANK_ENTRIES-VOUCHERPROV = MXS-TEXT. WHEN 25. TS_FT_BANK_ENTRIES-VOUCHERBAT = MXS-TEXT. WHEN 26. TS_FT_BANK_ENTRIES-VOUCHERNO = MXS-TEXT. WHEN 27. TS_FT_BANK_ENTRIES-CUSTREF = MXS-TEXT. WHEN 28. TS_FT_BANK_ENTRIES-TELLER = MXS-TEXT. WHEN 29. TS_FT_BANK_ENTRIES-TRANSCODE = MXS-TEXT. WHEN 30. TS_FT_BANK_ENTRIES-VCHNO = MXS-TEXT. WHEN 31. TS_FT_BANK_ENTRIES-ABS = MXS-TEXT. WHEN 32. TS_FT_BANK_ENTRIES-POSTSCRIPT = MXS-TEXT. WHEN 33. TS_FT_BANK_ENTRIES-TRFROM = MXS-TEXT. *******预留三个明细字段,防止农行增加字段 WHEN 34. TS_FT_BANK_ENTRIES-YL1 = MXS-TEXT. WHEN 35. TS_FT_BANK_ENTRIES-YL2 = MXS-TEXT. WHEN 36. TS_FT_BANK_ENTRIES-YL3 = MXS-TEXT. ENDCASE. IF IK = LN."33. MOVE-CORRESPONDING LS_SENDING_DATA-SAP_FIELDS TO TS_FT_BANK_ENTRIES-SAP_FIELDS. TS_FT_BANK_ENTRIES-DBACCNO = TS_FT_BANK_ENTRIES-DBPROV && TS_FT_BANK_ENTRIES-ACCNO. APPEND TS_FT_BANK_ENTRIES TO TB_FT_BANK_ENTRIES . IK = 0. ENDIF. ENDLOOP. |