ABAP-FTP-执行

1.界面

 

   

 

 

2.程序 ZFID0004_FTP_EXEC

 主程序:

 1 *&---------------------------------------------------------------------*
 2 *& Report  ZFID0004_FTP_EXEC
 3 *&
 4 *&---------------------------------------------------------------------*
 5 *&
 6 *&
 7 *&---------------------------------------------------------------------*
 8 
 9 report  zfid0004_ftp_exec.
10 
11 include zfid0004_ftp_exec_top.
12 
13 include zfid0004_ftp_exec_scr.
14 
15 include zfid0004_ftp_exec_pro.
16 
17 include zfid0004_ftp_exec_frm.
View Code

 INCLUDE程序:

 1 *&---------------------------------------------------------------------*
 2 *&  包括                ZFID0004_FTP_EXEC_TOP
 3 *&---------------------------------------------------------------------*
 4 
 5 *&---------------------------------------------------------------------*
 6 *&  包括              ZFID0004_FTP_EXEC_TOP
 7 *&---------------------------------------------------------------------*
 8 
 9 data:
10   begin of wa_file,
11   line(4096) type c,
12   end of wa_file.
13 data:
14   gt_file like table of wa_file.
15 
16 data:
17   gv_line type char15.
18 
19 field-symbols:
20   <ft_tab> type standard table,
21   <fs_ftp> type ztfi0037_etl_ftp,
22   <fs_hd>  type ztfi0035_tab_hd,
23   <fs_itm> type ztfi0036_tab_itm,
24   <fs_file> like wa_file,
25   <fs_tab> type any.
26 
27 data:
28   gt_fieldcat_lvc type lvc_t_fcat,  "定义存储alv字段内表
29   gt_style        type lvc_t_styl,
30   gs_fieldcat_lvc type lvc_s_fcat,  "定义存储alv字段工作区
31   gs_layout_lvc   type lvc_s_layo,  "定义alv栏目样式
32   gs_stable_lvc   type lvc_s_stbl,  "ALV刷新
33   gs_style        type lvc_s_styl,
34   gv_repid_lvc    type sy-repid .   "定义当前程序
35 data:
36   go_grid_lvc     type ref to cl_gui_alv_grid. "
37 data:
38   gs_header_lvc   type slis_t_listheader.      "表头信息
39 constants:
40   gv_sign_lvc         type c  value 'X',
41   gv_pf_status_lvc    type slis_formname value 'FRM_ALV_STATUS',  "alv自定义按钮form名称
42   gv_user_command_lvc type slis_formname value 'FRM_ALV_COMMAND', "alv自定义按钮响应事件form名称
43   gv_top_page_lvc     type slis_formname value 'TOP_OF_PAGE'.     "alv抬头
View Code
 1 *&---------------------------------------------------------------------*
 2 *&  包括              ZFID0004_FTP_EXEC_SCR
 3 *&---------------------------------------------------------------------*
 4 
 5 selection-screen begin of block b_block1 with frame title text-001.
 6 parameters:
 7   p_ftpnm type ztfi0037_etl_ftp-ftpnm obligatory,
 8   p_tabnm type ztfi0035_tab_hd-tabnm  obligatory,
 9   p_path  type char64 lower case default ''.
10 selection-screen end of block b_block1.
11 
12 selection-screen begin of block b_block2 with frame title text-002.
13 parameters:
14   c_alv as checkbox.
15 selection-screen end of block b_block2.
View Code
 1 *&---------------------------------------------------------------------*
 2 *&  包括              ZFID0004_FTP_EXEC_PRO
 3 *&---------------------------------------------------------------------*
 4 
 5 initialization.
 6 
 7 at selection-screen on value-request for p_tabnm.
 8   perform frm_help_tabnm.
 9 
10 at selection-screen.
11   perform frm_tabhd_check.
12 
13 start-of-selection.
14   "动态数据表结构
15   perform frm_dynamic_stru.
16   "查询界面
17   perform frm_query_screen.
18   "ALV显示
19   if c_alv is not initial.
20     perform frm_alv_display.
21   else.
22     perform frm_frp_send.
23   endif.
View Code
  1 *&---------------------------------------------------------------------*
  2 *&  包括              ZFID0004_FTP_EXEC_FRM
  3 *&---------------------------------------------------------------------*
  4 *&---------------------------------------------------------------------*
  5 *&      Form  frm_help_tabnm
  6 *&---------------------------------------------------------------------*
  7 *       text
  8 *----------------------------------------------------------------------*
  9 *  -->  p1        text
 10 *  <--  p2        text
 11 *----------------------------------------------------------------------*
 12 form frm_help_tabnm .
 13   data:
 14     lv_ftpnm type ztfi0035_tab_hd-ftpnm.
 15   data:
 16     lt_tabhd like table of ztfi0035_tab_hd,
 17     lt_dfies like table of dfies,
 18     lt_ddshr like table of ddshretval,
 19     lt_dselc like table of dselc,
 20     lt_dynpf like table of dynpread.
 21   field-symbols:
 22     <fs_dynpf> like dynpread.
 23 
 24   append initial line to lt_dynpf assigning <fs_dynpf>.
 25   <fs_dynpf>-fieldname = 'P_FTPNM'.
 26   unassign <fs_dynpf>.
 27 
 28   call function 'DYNP_VALUES_READ'
 29     exporting
 30       dyname               = sy-repid
 31       dynumb               = sy-dynnr
 32       translate_to_upper   = 'X'
 33     tables
 34       dynpfields           = lt_dynpf
 35     exceptions
 36       invalid_abapworkarea = 1
 37       invalid_dynprofield  = 2
 38       invalid_dynproname   = 3
 39       invalid_dynpronummer = 4
 40       invalid_request      = 5
 41       no_fielddescription  = 6
 42       invalid_parameter    = 7
 43       undefind_error       = 8
 44       double_conversion    = 9
 45       stepl_not_found      = 10
 46       others               = 11.
 47   if sy-subrc <> 0.
 48 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 49 *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 50   else.
 51     read table lt_dynpf assigning <fs_dynpf> index 1.
 52     if sy-subrc = 0.
 53       lv_ftpnm = <fs_dynpf>-fieldvalue.
 54     endif.
 55   endif.
 56 
 57   if lv_ftpnm is initial.
 58     select *
 59     into table lt_tabhd
 60     from ztfi0035_tab_hd.
 61   else.
 62     select *
 63     into table lt_tabhd
 64     from ztfi0035_tab_hd
 65     where ftpnm = lv_ftpnm.
 66   endif.
 67 
 68   call function 'F4IF_INT_TABLE_VALUE_REQUEST'
 69     exporting
 70       retfield        = 'TABNM'
 71       dynpprog        = sy-repid
 72       dynpnr          = sy-dynnr
 73       dynprofield     = 'P_TABNM'
 74       value_org       = 'S'
 75     tables
 76       value_tab       = lt_tabhd
 77       field_tab       = lt_dfies
 78       return_tab      = lt_ddshr
 79       dynpfld_mapping = lt_dselc
 80     exceptions
 81       parameter_error = 1
 82       no_values_found = 2
 83       others          = 3.
 84   if sy-subrc <> 0.
 85 * Implement suitable error handling here
 86   endif.
 87 endform.                    " frm_help_tabnm
 88 *&---------------------------------------------------------------------*
 89 *&      Form  frm_query_screen
 90 *&---------------------------------------------------------------------*
 91 *       text
 92 *----------------------------------------------------------------------*
 93 *  -->  p1        text
 94 *  <--  p2        text
 95 *----------------------------------------------------------------------*
 96 form frm_query_screen .
 97   data:
 98     lv_subrc type sy-subrc.
 99   data:
100     lc_seprate type c value ','.
101   data:
102     lt_tabit type table of ztfi0036_tab_itm,
103     lt_tabs type table of rsdstabs,
104     lt_flds type table of rsdsfields,
105     lt_mesg type table of bapiret2,
106     lt_tab_where   type table of rsdswhere,
107     lt_tab_express type table of rsdsexpr.
108   field-symbols:
109     <fs_flds> type rsdsfields,
110     <fs_tabs> type rsdstabs,
111     <fs_any>  type any,
112     <fs_fld>  type any.
113 
114   select *
115   into table lt_tabit
116   from ztfi0036_tab_itm
117   where ftpnm = p_ftpnm
118     and tabnm = p_tabnm.
119 
120   sort lt_tabit by ftpnm tabnm fldno.
121 
122   "
123   append initial line to lt_tabs assigning <fs_tabs>.
124   <fs_tabs>-prim_tab = p_tabnm.
125   unassign <fs_tabs>.
126 
127   "字段
128   loop at lt_tabit assigning <fs_itm>
129   where fg_qry = 'X'.
130     append initial line to lt_flds assigning <fs_flds>.
131     <fs_flds>-tablename = <fs_itm>-tabnm.
132     <fs_flds>-fieldname = <fs_itm>-fldnm.
133     unassign <fs_flds>.
134   endloop.
135 
136   call function 'ZAP_01_DYNAMICSELECTION'
137     exporting
138       tabtitle    = '选择查询字段'
139       i_wind      = ''
140       i_tree      = 'X'
141     importing
142       e_subrc     = lv_subrc
143     tables
144       it_tabs     = lt_tabs
145       it_flds     = lt_flds
146       tab_where   = lt_tab_where
147       tab_express = lt_tab_express
148       zmesg       = lt_mesg.
149 
150   if lv_subrc = 0.
151     clear:wa_file,gt_file.
152 
153     select *
154     into corresponding fields of table <ft_tab>
155     from (p_tabnm)
156     where (lt_tab_where).
157 
158     describe table <ft_tab>[] lines gv_line.
159 
160     loop at <ft_tab> assigning <fs_any>.
161       clear:wa_file.
162       loop at lt_tabit assigning <fs_itm>
163       where fg_exp = 'X'.
164         assign component <fs_itm>-fldnm of structure <fs_any> to <fs_fld>.
165         if sy-subrc = 0.
166           if wa_file is initial.
167             wa_file-line = <fs_fld>.
168           else.
169             concatenate wa_file-line lc_seprate <fs_fld> into wa_file-line.
170           endif.
171         endif.
172         unassign <fs_fld>.
173       endloop.
174       append wa_file to gt_file.
175     endloop.
176   endif.
177 endform.                    " frm_query_screen
178 *&---------------------------------------------------------------------*
179 *&      Form  frm_dynamic_stru
180 *&---------------------------------------------------------------------*
181 *       text
182 *----------------------------------------------------------------------*
183 *  -->  p1        text
184 *  <--  p2        text
185 *----------------------------------------------------------------------*
186 form frm_dynamic_stru .
187   data:
188     lt_tabit like table of ztfi0036_tab_itm.
189   data:
190     struct_type type ref to cl_abap_structdescr,
191     struct_styl type ref to cl_abap_structdescr,
192     ztab_type   type ref to cl_abap_tabledescr,
193     styl_type   type ref to cl_abap_tabledescr,
194     elem_type   type ref to cl_abap_elemdescr,
195     comp_type   type cl_abap_structdescr=>component_table,
196     comp_styl   type cl_abap_structdescr=>component_table,
197     comp_field  type cl_abap_structdescr=>component,
198     comp_line   like line of comp_type,
199     dref        type ref to data,
200     dline       type ref to data.
201   field-symbols:
202     <fs_comp> like line of comp_type.
203 
204   select *
205   into table lt_tabit
206   from ztfi0036_tab_itm
207   where ftpnm = p_ftpnm
208     and tabnm = p_tabnm
209     and fg_exp = 'X'.
210 
211   struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnm ).
212   comp_type = struct_type->get_components( ).
213 
214   loop at comp_type assigning <fs_comp>.
215     read table lt_tabit assigning <fs_itm>
216     with key fldnm = <fs_comp>-name.
217     if sy-subrc <> 0.
218       delete comp_type.
219     endif.
220   endloop.
221 
222   struct_type = cl_abap_structdescr=>create( comp_type ).
223   ztab_type = cl_abap_tabledescr=>create( struct_type ).
224 
225   create data dref type handle ztab_type.
226   assign dref->* to <ft_tab>.
227 endform.                    " frm_dynamic_stru
228 *&---------------------------------------------------------------------*
229 *&      Form  frm_alv_display
230 *&---------------------------------------------------------------------*
231 *       text
232 *----------------------------------------------------------------------*
233 *  -->  p1        text
234 *  <--  p2        text
235 *----------------------------------------------------------------------*
236 form frm_alv_display .
237   data:
238     lt_tabit    type table of ztfi0036_tab_itm,
239     lt_fieldcat type slis_t_fieldcat_alv.
240   data:
241     ls_fieldcat type slis_fieldcat_alv.
242 
243   call function 'REUSE_ALV_FIELDCATALOG_MERGE'
244     exporting
245       i_program_name         = sy-repid     "调用当前方法的程序名
246       i_structure_name       = p_tabnm      "数据字典ddic定义的结构名称,一定要有
247     changing
248       ct_fieldcat            = lt_fieldcat[] "系统自动生成的fieldcat文件
249     exceptions
250       inconsistent_interface = 1
251       program_error          = 2
252       others                 = 3.
253   if sy-subrc <> 0.
254     message id sy-msgid type sy-msgty number sy-msgno
255             with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
256   endif.
257 
258   select *
259   into table lt_tabit
260   from ztfi0036_tab_itm
261   where ftpnm = p_ftpnm
262     and tabnm = p_tabnm
263     and fg_exp = 'X'.
264 
265   loop at lt_fieldcat into ls_fieldcat.
266     read table lt_tabit assigning <fs_itm>
267     with key fldnm = ls_fieldcat-fieldname.
268     if sy-subrc <> 0.
269       delete lt_fieldcat.
270     endif.
271   endloop.
272 
273   loop at lt_fieldcat into ls_fieldcat
274   where seltext_l = ''.
275     select single ddtext
276       into ls_fieldcat-seltext_l
277       from dd03t
278      where tabname    = p_tabnm
279        and ddlanguage = sy-langu
280        and fieldname  = ls_fieldcat-fieldname.
281     modify lt_fieldcat from ls_fieldcat.
282     clear:ls_fieldcat.
283   endloop.
284 
285   loop at lt_fieldcat into ls_fieldcat.
286     move-corresponding ls_fieldcat to gs_fieldcat_lvc.
287     gs_fieldcat_lvc-scrtext_m = ls_fieldcat-seltext_l.
288     append gs_fieldcat_lvc to gt_fieldcat_lvc.
289     clear:ls_fieldcat,gs_fieldcat_lvc.
290   endloop.
291 
292   perform frm_alv_layout.                 "设置布局
293   perform frm_alv_fields.                 "设置显示字段
294   perform frm_alv_header using gs_header_lvc. "添加表头
295 
296   "ALV输出
297   call function 'REUSE_ALV_GRID_DISPLAY_LVC'
298     exporting
299       i_callback_program       = sy-repid
300       i_callback_pf_status_set = gv_pf_status_lvc
301       i_callback_user_command  = gv_user_command_lvc
302       i_callback_top_of_page   = gv_top_page_lvc
303       is_layout_lvc            = gs_layout_lvc
304       it_fieldcat_lvc          = gt_fieldcat_lvc
305       i_save                   = 'A'
306     tables
307       t_outtab                 = <ft_tab>[]
308     exceptions
309       program_error            = 1
310       others                   = 2.
311   if sy-subrc <> 0.
312     message id sy-msgid type sy-msgty number sy-msgno
313     with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
314   endif.
315 endform.                    " frm_alv_display
316 
317 *&---------------------------------------------------------------------*
318 *&      Form  FRM_ALV_LAYOUT
319 *&---------------------------------------------------------------------*
320 *       text
321 *----------------------------------------------------------------------*
322 *  -->  p1        text
323 *  <--  p2        text
324 *----------------------------------------------------------------------*
325 form frm_alv_layout .
326   gs_layout_lvc-zebra      = 'X'.           "设置行颜色变化
327   gs_layout_lvc-cwidth_opt = 'X'.           "列宽自适应
328   gs_layout_lvc-stylefname = 'FIELD_STYLE'. "设置样式输出控制结构的stylename字段内容为单元格状态控制字段名
329 endform.                    "frm_alv_layout
330 *&---------------------------------------------------------------------*
331 *&      Form  FRM_ALV_FIELDS
332 *&---------------------------------------------------------------------*
333 *       text
334 *----------------------------------------------------------------------*
335 *  -->  p1        text
336 *  <--  p2        text
337 *----------------------------------------------------------------------*
338 form frm_alv_fields .
339 
340 endform.                    "frm_alv_fields
341 *&---------------------------------------------------------------------*
342 *&      Form  FRM_ALV_HEADER
343 *&---------------------------------------------------------------------*
344 *       text
345 *----------------------------------------------------------------------*
346 *      -->P_I_HEADER  text
347 *----------------------------------------------------------------------*
348 form frm_alv_header using fs_header type slis_t_listheader.
349   data:ls_line type slis_listheader.
350 
351   check fs_header[] is initial.
352   ls_line-typ = 'H'.
353   select single ddtext
354     into ls_line-info
355     from dd02t
356    where tabname = p_tabnm
357      and ddlanguage = sy-langu.
358   shift gv_line left deleting leading space.
359   concatenate ls_line-info '-' gv_line into ls_line-info.
360   append ls_line to fs_header.
361 endform.                    "frm_alv_header
362 *&---------------------------------------------------------------------*
363 *&      Form  top_of_page
364 *&---------------------------------------------------------------------*
365 *       text
366 *----------------------------------------------------------------------*
367 form top_of_page.
368 * 如果是alv grid 显示,调用此fm初始化表头;
369   call function 'REUSE_ALV_COMMENTARY_WRITE'
370     exporting
371       it_list_commentary = gs_header_lvc.      " 把header的值传入
372 endform.                    "top_of_page
373 *&---------------------------------------------------------------------*
374 *&      Form  frm_alv_status
375 *&---------------------------------------------------------------------*
376 *       text
377 *----------------------------------------------------------------------*
378 *  -->  rt_extab        slis_t_extab
379 *----------------------------------------------------------------------*
380 form frm_alv_status using rt_extab type slis_t_extab.
381   data:lt_gui type slis_t_extab with header line.
382   set pf-status 'ST_1000' excluding lt_gui.
383 endform.                    "frm_alv_status
384 
385 *&---------------------------------------------------------------------*
386 *&      Form  frm_alv_command
387 *&---------------------------------------------------------------------*
388 *       text
389 *----------------------------------------------------------------------*
390 *  -->  p1        text
391 *  <--  p2        text
392 *----------------------------------------------------------------------*
393 form frm_alv_command using fv_ucomm like sy-ucomm
394                            fs_selfield type slis_selfield.
395 
396   data:lt_return type table of bapiret2.
397 
398   "ALV数据修改
399   perform frm_alv_change.
400 
401   case fv_ucomm.
402     when 'FTP'.
403       perform frm_frp_send.
404 
405     when others.
406   endcase.
407   "ALV格式刷新
408   perform frm_alv_refresh.
409 endform.                    "frm_alv_command
410 
411 *&---------------------------------------------------------------------*
412 *&      Form  frm_alv_change
413 *&---------------------------------------------------------------------*
414 *       text
415 *----------------------------------------------------------------------*
416 *  -->  p1        text
417 *  <--  p2        text
418 *----------------------------------------------------------------------*
419 form frm_alv_change.
420   call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
421     importing
422       e_grid = go_grid_lvc.
423 
424   call method go_grid_lvc->check_changed_data.
425 
426 endform.                    "frm_alv_change
427 
428 *&---------------------------------------------------------------------*
429 *&      Form  frm_alv_refresh
430 *&---------------------------------------------------------------------*
431 *       text
432 *----------------------------------------------------------------------*
433 *  -->  p1        text
434 *  <--  p2        text
435 *----------------------------------------------------------------------*
436 form frm_alv_refresh.
437   gs_stable_lvc-row = 'X'.
438   gs_stable_lvc-col = 'X'.
439 
440   call method go_grid_lvc->refresh_table_display
441     exporting
442       is_stable = gs_stable_lvc
443     exceptions
444       finished  = 1
445       others    = 2.
446 endform.                    "frm_alv_refresh
447 *&---------------------------------------------------------------------*
448 *&      Form  frm_frp_send
449 *&---------------------------------------------------------------------*
450 *       text
451 *----------------------------------------------------------------------*
452 *  -->  p1        text
453 *  <--  p2        text
454 *----------------------------------------------------------------------*
455 form frm_frp_send .
456   data:
457     lt_return type table of bapiret2,
458     lt_data like table of wa_file.
459   data:
460     lv_ftpds  type char30,
461     lv_handle type i,
462     lv_outlen type i.
463   field-symbols:
464     <fs_return> like bapiret2.
465 
466   "连接FTP服务器
467   perform frm_connect_ftp tables lt_return lt_data using lv_handle lv_outlen lv_ftpds.
468   "传输文件至FTP服务器
469   perform frm_export_to_ftp tables lt_return lt_data using lv_handle lv_outlen.
470   "断开FTP服务器连接
471   perform frm_disconnect_ftp tables lt_return using lv_handle lv_ftpds.
472   "错误日志
473   perform frm_log_display tables lt_return.
474 endform.                    " frm_frp_send
475 *&---------------------------------------------------------------------*
476 *&      Form  frm_connect_ftp
477 *&---------------------------------------------------------------------*
478 *       text
479 *----------------------------------------------------------------------*
480 *  -->  p1        text
481 *  <--  p2        text
482 *----------------------------------------------------------------------*
483 form frm_connect_ftp tables ft_return structure bapiret2
484                             ft_data  structure wa_file
485                      using fv_handle fv_outlen fv_ftpds.
486   data:
487     lv_key  type i value '26101957',
488     lv_slen type i,
489     lv_handle type i,
490     lv_command type char100,
491     lv_codepage(4) type n,
492     lv_encoding(20).
493   data:
494     lt_data type table of text.
495   data:
496     ls_return type bapiret2,
497     ls_ftp like ztfi0037_etl_ftp.
498 
499   select single *
500     into ls_ftp
501     from ztfi0037_etl_ftp
502    where ftpnm = p_ftpnm.
503 
504   lv_slen = strlen( ls_ftp-ftppw ).
505 
506   call function 'HTTP_SCRAMBLE'
507     exporting
508       source      = ls_ftp-ftppw
509       sourcelen   = lv_slen
510       key         = lv_key
511     importing
512       destination = ls_ftp-ftppw.
513 
514   call function 'SAPGUI_PROGRESS_INDICATOR'
515     exporting
516       text = 'Connect to FTP Server'.
517 
518   call function 'FTP_CONNECT'
519     exporting
520       user            = ls_ftp-ftpur
521       password        = ls_ftp-ftppw
522       host            = ls_ftp-ftpip
523       rfc_destination = ls_ftp-ftpds
524     importing
525       handle          = lv_handle.
526   if sy-subrc = 0.
527     perform frm_message_info   using ls_return 'ZFI_00' 'S' '010' ls_ftp-ftpip ls_ftp-ftpds space space.
528     perform frm_message_handle tables ft_return using ls_return.
529   else.
530     perform frm_message_info   using ls_return sy-msgid sy-msgty sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
531     perform frm_message_handle tables ft_return using ls_return.
532     exit.
533   endif.
534 
535   fv_handle = lv_handle.
536   fv_ftpds = ls_ftp-ftpds.
537 
538   clear:lt_data.
539 
540   if p_path is not initial.
541     concatenate 'cd' p_path into lv_command separated by space.
542 
543     call function 'FTP_COMMAND'
544       exporting
545         handle        = lv_handle
546         command       = lv_command
547       tables
548         data          = lt_data
549       exceptions
550         tcpip_error   = 1
551         command_error = 2
552         data_error    = 3.
553     if sy-subrc = 0.
554       perform frm_message_info   using ls_return 'ZFI_00' 'S' '011' lv_command space space space.
555       perform frm_message_handle tables ft_return using ls_return.
556     else.
557       perform frm_message_info   using ls_return  sy-msgid sy-msgty sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
558       perform frm_message_handle tables ft_return using ls_return.
559       exit.
560     endif.
561   endif.
562 
563   call function 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
564     exporting
565       external_name = 'GB2312'
566     importing
567       sap_codepage  = lv_codepage.
568   lv_encoding = lv_codepage.
569 
570   call function 'SCMS_TEXT_TO_BINARY'
571 *    exporting
572 *      encoding      = lv_encoding
573     importing
574       output_length = fv_outlen
575     tables
576       text_tab      = gt_file
577       binary_tab    = ft_data
578     exceptions
579       failed        = 1
580       others        = 2.
581   if sy-subrc = 0.
582     perform frm_message_info   using ls_return 'ZFI_00' 'S' '012' space space space space.
583     perform frm_message_handle tables ft_return using ls_return.
584   else.
585     perform frm_message_info   using ls_return sy-msgid sy-msgty sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
586     perform frm_message_handle tables ft_return using ls_return.
587     exit.
588   endif.
589 
590   clear:lt_data.
591 
592   call function 'FTP_COMMAND'
593     exporting
594       handle        = lv_handle
595       command       = 'binary'
596     tables
597       data          = lt_data
598     exceptions
599       tcpip_error   = 1
600       command_error = 2
601       data_error    = 3.
602   if sy-subrc = 0.
603     perform frm_message_info   using ls_return 'ZFI_00' 'S' '013' 'binary' space space space.
604     perform frm_message_handle tables ft_return using ls_return.
605   else.
606     perform frm_message_info   using ls_return sy-msgid sy-msgty sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
607     perform frm_message_handle tables ft_return using ls_return.
608     exit.
609   endif.
610 
611 endform.                    " frm_connect_ftp
612 *&---------------------------------------------------------------------*
613 *&      Form  frm_export_to_ftp
614 *&---------------------------------------------------------------------*
615 *       text
616 *----------------------------------------------------------------------*
617 *  -->  p1        text
618 *  <--  p2        text
619 *----------------------------------------------------------------------*
620 form frm_export_to_ftp tables ft_return structure bapiret2
621                               ft_data structure wa_file
622                        using  fv_handle
623                               fv_outlen.
624   data:
625     ls_return type bapiret2.
626   data:
627     lv_filename type char50.
628 
629   read table ft_return into ls_return with key type = 'E'.
630   if sy-subrc = 0.
631     exit.
632   endif.
633 
634   concatenate p_tabnm '_' sy-datum '_' sy-uzeit '.txt' into lv_filename.
635 
636   if gt_file[] is not initial.
637     call function 'FTP_R3_TO_SERVER'
638       exporting
639         handle        = fv_handle
640         fname         = lv_filename
641         blob_length   = fv_outlen
642       tables
643         blob          = ft_data
644       exceptions
645         tcpip_error   = 1
646         command_error = 2
647         data_error    = 3
648         others        = 4.
649     if sy-subrc = 0.
650       call function 'BAPI_TRANSACTION_COMMIT'.
651       perform frm_message_info   using ls_return 'ZFI_00' 'S' '014' lv_filename gv_line space space.
652       perform frm_message_handle tables ft_return using ls_return.
653     else.
654       call function 'BAPI_TRANSACTION_ROLLBACK'.
655       perform frm_message_info   using ls_return sy-msgid sy-msgty sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
656       perform frm_message_handle tables ft_return using ls_return.
657       exit.
658     endif.
659   else.
660     perform frm_message_info   using ls_return 'ZFI_00' 'E' '015' p_tabnm space space space.
661     perform frm_message_handle tables ft_return using ls_return.
662     exit.
663   endif.
664 
665 endform.                    " frm_export_to_ftp
666 *&---------------------------------------------------------------------*
667 *&      Form  frm_disconnect_ftp
668 *&---------------------------------------------------------------------*
669 *       text
670 *----------------------------------------------------------------------*
671 *  -->  p1        text
672 *  <--  p2        text
673 *----------------------------------------------------------------------*
674 form frm_disconnect_ftp tables ft_return structure bapiret2
675                         using fv_handle fv_ftpds.
676   data:
677     ls_return type bapiret2.
678 
679   call function 'FTP_DISCONNECT'
680     exporting
681       handle = fv_handle.
682   if sy-subrc = 0.
683     call function 'BAPI_TRANSACTION_COMMIT'.
684     perform frm_message_info   using ls_return 'ZFI_00' 'S' '016' p_ftpnm space space space.
685     perform frm_message_handle tables ft_return using ls_return.
686   else.
687     call function 'BAPI_TRANSACTION_ROLLBACK'.
688     perform frm_message_info   using ls_return sy-msgid sy-msgty sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
689     perform frm_message_handle tables ft_return using ls_return.
690     exit.
691   endif.
692 
693   call function 'RFC_CONNECTION_CLOSE'
694     exporting
695       destination = fv_ftpds
696     exceptions
697       others      = 1.
698   if sy-subrc = 0.
699     call function 'BAPI_TRANSACTION_COMMIT'.
700     perform frm_message_info   using ls_return 'ZFI_00' 'S' '017' fv_ftpds space space space.
701     perform frm_message_handle tables ft_return using ls_return.
702   else.
703     call function 'BAPI_TRANSACTION_ROLLBACK'.
704     perform frm_message_info   using ls_return sy-msgid sy-msgty sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
705     perform frm_message_handle tables ft_return using ls_return.
706     exit.
707   endif.
708 endform.                    " frm_disconnect_ftp
709 *&---------------------------------------------------------------------*
710 *&      Form  frm_tabhd_check
711 *&---------------------------------------------------------------------*
712 *       text
713 *----------------------------------------------------------------------*
714 *  -->  p1        text
715 *  <--  p2        text
716 *----------------------------------------------------------------------*
717 form frm_tabhd_check .
718   if p_tabnm is not initial
719   and p_ftpnm is not initial.
720     select single count(*)
721     from ztfi0035_tab_hd
722     where ftpnm = p_ftpnm
723     and tabnm = p_tabnm
724     and fg_ftp = 'X'.
725     if sy-subrc <> 0.
726       message e009(zfi_00) with p_ftpnm p_tabnm.
727     endif.
728   endif.
729 endform.                    " frm_tabhd_check
730 
731 *&---------------------------------------------------------------------*
732 *&      Form  frm_message_handle
733 *&---------------------------------------------------------------------*
734 *       text
735 *----------------------------------------------------------------------*
736 *      -->FT_RETURN  text
737 *      -->FS_RETURN  text
738 *----------------------------------------------------------------------*
739 form frm_message_handle tables ft_return structure bapiret2
740                          using fs_return type bapiret2.
741   message id fs_return-id
742         type fs_return-type
743       number fs_return-number
744         with fs_return-message_v1
745              fs_return-message_v2
746              fs_return-message_v3
747              fs_return-message_v4
748         into fs_return-message.
749 
750   move-corresponding fs_return to ft_return.
751   append ft_return.
752   clear:fs_return.
753 endform.                    "frm_message_handle
754 *&---------------------------------------------------------------------*
755 *&      Form  frm_message_info
756 *&---------------------------------------------------------------------*
757 *       text
758 *----------------------------------------------------------------------*
759 *      <--P_LS_RETURN  text
760 *      -->P_1125   text
761 *      -->P_1126   text
762 *      -->P_1127   text
763 *      -->P_LS_FTP_FTPIP  text
764 *      -->P_LS_FTP_FTPDS  text
765 *      -->P_SPACE  text
766 *      -->P_SPACE  text
767 *----------------------------------------------------------------------*
768 form frm_message_info  using    fs_return type bapiret2
769                                 fv_msgid
770                                 fv_msgty
771                                 fv_msgno
772                                 fv_msgv1
773                                 fv_msgv2
774                                 fv_msgv3
775                                 fv_msgv4.
776   clear:fs_return.
777   fs_return-id         = fv_msgid.
778   fs_return-type       = fv_msgty.
779   fs_return-number     = fv_msgno.
780   fs_return-message_v1 = fv_msgv1.
781   fs_return-message_v2 = fv_msgv2.
782   fs_return-message_v3 = fv_msgv3.
783   fs_return-message_v4 = fv_msgv4.
784   fs_return-parameter  = space.
785   fs_return-log_no     = space.
786   fs_return-system     = space.
787 endform.                    " frm_message_info
788 *&---------------------------------------------------------------------*
789 *&      Form  frm_log_display
790 *&---------------------------------------------------------------------*
791 *       text
792 *----------------------------------------------------------------------*
793 *      -->P_LT_RETURN  text
794 *----------------------------------------------------------------------*
795 *&---------------------------------------------------------------------*
796 *&--错误日志多条MESSAGE显示
797 *&
798 *&---------------------------------------------------------------------*
799 
800 form frm_log_display  tables ft_zmesg structure bapiret2.
801 
802   data:lt_smesg type tsmesg.
803   field-symbols:<fs_msg> type smesg,
804                 <fs_bap> type bapiret2.
805 
806   loop at ft_zmesg assigning <fs_bap>.
807     append initial line to lt_smesg assigning <fs_msg>.
808     <fs_msg>-zeile = sy-tabix.
809     <fs_msg>-msgty = <fs_bap>-type.
810     <fs_msg>-text  = <fs_bap>-message.
811     <fs_msg>-arbgb = <fs_bap>-id.
812     <fs_msg>-txtnr = <fs_bap>-number.
813     <fs_msg>-msgv1 = <fs_bap>-message_v1.
814     <fs_msg>-msgv2 = <fs_bap>-message_v2.
815     <fs_msg>-msgv3 = <fs_bap>-message_v3.
816     <fs_msg>-msgv4 = <fs_bap>-message_v4.
817   endloop.
818 
819   call function 'FB_MESSAGES_DISPLAY_POPUP'
820     exporting
821       it_smesg        = lt_smesg
822 *     id_smesg_zeile  =
823 *     it_return       =
824 *     id_send_if_one  =
825     exceptions
826       no_messages     = 1
827       popup_cancelled = 2
828       others          = 3.
829   if sy-subrc <> 0.
830   endif.
831 endform.                    "frm_log_display
View Code

3.FTP传输问题

 调用FTP_COMMAND执行 'cd /' 打开路径,后续调用FTP_R3_TO_SERVER执行出现COMMAND_ERROR问题:E209(04)-FTP 子命令: 服务器报表错误

 将FTP_COMMAND执行 'cd /' 代码注释后执行成功,若是默认'/'路径下,则可以不用FTP_COMMAND执行。

原文地址:https://www.cnblogs.com/ricoo/p/10654360.html