首页 > 其他分享 >ABAP-文件的上传下载以及存表

ABAP-文件的上传下载以及存表

时间:2023-02-20 09:33:25浏览次数:36  
标签:存表 string DATA 上传下载 pic ABAP tab error TYPE

  1 REPORT zfile.
  2 
  3 DATA : lv_url TYPE string.
  4 
  5 CALL METHOD cl_gui_frontend_services=>execute
  6   EXPORTING
  7 *   document = 'https://123.sogou.com/'
  8     document = 'C:\Users\HP\Desktop\接口测试.doc'
  9   EXCEPTIONS
 10     OTHERS   = 1.
 11 *data:code TYPE i .
 12 *CALL METHOD cl_gui_frontend_services=>file_delete
 13 *  EXPORTING
 14 *    filename = 'C:\Users\HP\Desktop\接口测试.doc'
 15 *  CHANGING
 16 *    rc       = code.
 17 
 18 DATA: it_data   TYPE xstring,
 19       it_string TYPE string,
 20       fichero   TYPE string.
 21 fichero = 'C:\Users\HP\Desktop\神功增强.xlsx'.
 22 
 23 TYPES: BEGIN OF ty_pic,
 24          pic_data(1024) TYPE x,
 25        END OF ty_pic.
 26 
 27 DATA: pic_tab TYPE TABLE OF ty_pic.
 28 
 29 DATA: wa_pic TYPE ztest.
 30 
 31 **zpictable为自定义table,设置一个主键字段,再设置一个或者多个RAWSTRING类型的字段存储图片数据
 32 
 33 DATA: c_pic  TYPE REF TO cl_gui_custom_container,
 34       go_pic TYPE REF TO cl_gui_picture.
 35 
 36 DATA: len         TYPE i,
 37       url(256),
 38       resu        TYPE i VALUE 123,
 39       path_string TYPE string.
 40 
 41 DATA lv_content TYPE xstring.
 42 
 43 * 上载PIC文件
 44 CALL FUNCTION 'GUI_UPLOAD'
 45   EXPORTING
 46     filename   = fichero
 47     filetype   = 'BIN'
 48   IMPORTING
 49     filelength = len
 50   TABLES
 51     data_tab   = pic_tab[].
 52 
 53 CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
 54   EXPORTING
 55     input_length = len
 56   IMPORTING
 57     buffer       = lv_content
 58   TABLES
 59     binary_tab   = pic_tab[]
 60   EXCEPTIONS
 61     failed       = 1
 62     OTHERS       = 2.
 63 
 64 wa_pic-key1    = '20221114'.
 65 wa_pic-field1 = lv_content.
 66 MODIFY ztest FROM wa_pic.
 67 IF sy-subrc = 0 .
 68   COMMIT WORK .
 69 ELSE .
 70   ROLLBACK WORK .
 71 ENDIF .
 72 
 73 SELECT SINGLE *
 74   FROM ztest
 75   INTO @DATA(gs_file)
 76   WHERE key1 = '20221205'.
 77 REFRESH pic_tab .
 78 CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
 79   EXPORTING
 80     buffer     = gs_file-field1
 81   TABLES
 82     binary_tab = pic_tab.
 83 
 84 CALL FUNCTION 'GUI_DOWNLOAD'
 85   EXPORTING
 86 *   BIN_FILESIZE            =
 87     filename                = 'C:\Users\HP\Desktop\接口测试.doc'
 88     filetype                = 'BIN'
 89 *   APPEND                  = ' '
 90 *   WRITE_FIELD_SEPARATOR   = ' '
 91 *   HEADER                  = '00'
 92 *   TRUNC_TRAILING_BLANKS   = ' '
 93 *   WRITE_LF                = 'X'
 94 *   COL_SELECT              = ' '
 95 *   COL_SELECT_MASK         = ' '
 96 *   DAT_MODE                = ' '
 97 *   CONFIRM_OVERWRITE       = ' '
 98 *   NO_AUTH_CHECK           = ' '
 99 *   CODEPAGE                = ' '
100 *   IGNORE_CERR             = ABAP_TRUE
101 *   REPLACEMENT             = '#'
102 *   WRITE_BOM               = ' '
103 *   TRUNC_TRAILING_BLANKS_EOL       = 'X'
104 *   WK1_N_FORMAT            = ' '
105 *   WK1_N_SIZE              = ' '
106 *   WK1_T_FORMAT            = ' '
107 *   WK1_T_SIZE              = ' '
108 *   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
109 *   SHOW_TRANSFER_STATUS    = ABAP_TRUE
110 *   VIRUS_SCAN_PROFILE      = '/SCET/GUI_DOWNLOAD'
111 * IMPORTING
112 *   FILELENGTH              =
113   TABLES
114     data_tab                = pic_tab
115 *   FIELDNAMES              =
116   EXCEPTIONS
117     file_write_error        = 1
118     no_batch                = 2
119     gui_refuse_filetransfer = 3
120     invalid_type            = 4
121     no_authority            = 5
122     unknown_error           = 6
123     header_not_allowed      = 7
124     separator_not_allowed   = 8
125     filesize_not_allowed    = 9
126     header_too_long         = 10
127     dp_error_create         = 11
128     dp_error_send           = 12
129     dp_error_write          = 13
130     unknown_dp_error        = 14
131     access_denied           = 15
132     dp_out_of_memory        = 16
133     disk_full               = 17
134     dp_timeout              = 18
135     file_not_found          = 19
136     dataprovider_exception  = 20
137     control_flush_error     = 21
138     OTHERS                  = 22.

标签:存表,string,DATA,上传下载,pic,ABAP,tab,error,TYPE
From: https://www.cnblogs.com/TigerMan/p/17136263.html

相关文章