2010 Jun 21 8:52 AM
Hi All,
We have a very typical requirement of uploading attachments for Infotype using both Frontend(Web-Dynpro ABAP) and Backend(SE38 report program).
From frontend it is very simple as we directly get the data in XSTRING format. However, from backend I am facing some difficulty in getting data into XSTRING format.
1st I tried using GUI_UPLOAD in BIN mode and it gives me a dump which points to some SAP standard error in transferring data(frankly i donno what is going on there)...Ok.... dump is due to output table type as string. when i change it to char1024 there is no more error but the output data looks like some weird combination of Chinese characters, # and ~.
2nd I tried GUI upload in ASC mode and then convert the text into XSTRING but i donno if the file structure will remain stable by doing so.... (here GUI upload does not give me any dump or error)
3rd - search for similar blogs but failed finding anything which is quite relevant to the requirement.
Here is the code which I used for BIN mode:
DATA: gt_bin_data TYPE STANDARD TABLE OF char1024.
DATA: gd_file_length TYPE i.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
FILETYPE = 'BIN'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH = gd_file_length
* HEADER =
tables
data_tab = gt_bin_data
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.Any help would be appreciated.
Cheers,
Kunjal
Hi All,
We have a very typical requirement of uploading attachments for Infotype using both Frontend(Web-Dynpro ABAP) and Backend(SE38 report program).
From frontend it is very simple as we directly get the data in XSTRING format. However, from backend I am facing some difficulty in getting data into XSTRING format.
1st I tried using GUI_UPLOAD in BIN mode and it gives me a dump which points to some SAP standard error in transferring data(frankly i donno what is going on there)...Ok.... dump is due to output table type as string. when i change it to char1024 there is no more error but the output data looks like some weird combination of Chinese characters, # and ~.
2nd I tried GUI upload in ASC mode and then convert the text into XSTRING but i donno if the file structure will remain stable by doing so.... (here GUI upload does not give me any dump or error)
3rd - search for similar blogs but failed finding anything which is quite relevant to the requirement.
Here is the code which I used for BIN mode:
DATA: gt_bin_data TYPE STANDARD TABLE OF char1024.
DATA: gd_file_length TYPE i.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
FILETYPE = 'BIN'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH = gd_file_length
* HEADER =
tables
data_tab = gt_bin_data
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.Any help would be appreciated.
Cheers,
Kunjal
2010 Jun 21 9:33 AM
i guess you are uploading some PDF file.. right?
yes.. when it is uploaded with BIN format..it will come in those Chinese and ## type only.. (you try to download the same.. you will find your PDF back)..
you cant read your PDF file data by uploading with GUI_DOWNLOAD.. you need to upload a XML.. then you can use ST to transform data to your required format.
2010 Jun 21 10:25 AM
Hi,
Below is the code for the filetype BIN
DATA : conv1 TYPE REF TO cl_abap_conv_in_ce,
view1 TYPE REF TO cl_abap_view_offlen.
DATA lv_bin TYPE xstring.
DATA: lv_tablenc TYPE i ,
lv_tabnamec(10) TYPE c .
FIELD-SYMBOLS : <gs_upload_table> TYPE STANDARD TABLE,
<gs_upload_wa> TYPE ANY.
DATA : gv_ref TYPE REF TO data,
gv_tab TYPE REF TO data.
CREATE DATA gv_ref TYPE ty_data_tab_bin.
ASSIGN gv_ref->* TO <gs_upload_wa>.
CREATE DATA gv_tab TYPE TABLE OF ty_data_tab_bin.
ASSIGN gv_tab->* TO <gs_upload_table>.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_filename_str
FILETYPE = lv_filetype
tables
data_tab = <gs_upload_table>
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
End UCC
IF sy-subrc <> 0.
RAISE upload_failed.
ENDIF.
Start UCC
REFRESH: t_data_tab_bin[], data_tab[].
CONVERSION binary to char.structure...
LOOP AT <gs_upload_table> ASSIGNING <gs_upload_wa>.
MOVE-CORRESPONDING <gs_upload_wa> TO w_data_tab_bin.
MOVE w_data_tab_bin-raw TO lv_bin. " type string required for class
conv1 = cl_abap_conv_in_ce=>create( input = lv_bin ).
view1 = cl_abap_view_offlen=>create_legacy_view( w_data_tab ).
CALL METHOD conv1->read( EXPORTING view = view1 IMPORTING data = w_data_tab ).
APPEND w_data_tab TO data_tab.
ENDLOOP.
With Regards,
Sumodh.P
2012 Jul 12 7:49 AM
Hi,
CREATE DATA gv_ref TYPE ty_data_tab_bin.
ASSIGN gv_ref->* TO <gs_upload_wa>.
CREATE DATA gv_tab TYPE TABLE OF ty_data_tab_bin.
ASSIGN gv_tab->* TO <gs_upload_table>.
what should be the type of "ty_data_tab_bin" in the above code. I tried using table to type string but it dumps.
Regards,
Dileep
2012 Jul 12 1:21 PM
"DATA: gt_bin_data TYPE STANDARD TABLE OF char1024."
you have an error in your data declarations. The type should be type table of tbl1024.
after the 'BIN' upload use the SCMS_BINARY_TO_XSTRING function module to convert binary table to xstring....very simple process and flawless for me.
BTW, this has been discussed at length in these forums previously. May I suggest a search before posting in the future....will save you a lot of time, since it is unlikely that you will come across a problem that has not been discussed here previously.
2014 May 08 2:28 PM
Hey man,
You did not mentioned what type is ty_data_tab_bin and w_data_tab_bin
and data_tab and w_data_tab and in above given code (Sumodh P Jun 21, 2010 11:25 AM).
Copy same code to your sample program you will get plenty of syntax error.
2025 Sep 19 3:47 PM - edited 2025 Sep 19 3:49 PM
I'm probably late, but there's a solution to this problem. SAP handles the XSTRING, the hexadecimal string, and not the binary string when I try to display content using the various "viewers" available. So the GUI_UPLOAD solution is valid, but the conversion from BINARY to XSTRING is missing. Here's the code:
DATA filename TYPE string.
* DATA FILETYPE TYPE CHAR10.
* DATA HAS_FIELD_SEPARATOR TYPE CHAR01.
* DATA HEADER_LENGTH TYPE I.
* DATA READ_BY_LINE TYPE CHAR01.
* DATA DAT_MODE TYPE CHAR01.
* DATA CODEPAGE TYPE ABAP_ENCODING.
* DATA IGNORE_CERR TYPE ABAP_BOOL.
* DATA REPLACEMENT TYPE ABAP_REPL.
* DATA VIRUS_SCAN_PROFILE TYPE VSCAN_PROFILE.
DATA filelength TYPE i.
* DATA HEADER TYPE XSTRING.
DATA data_tab TYPE STANDARD TABLE OF tdline.
* DATA ISSCANPERFORMED TYPE CHAR01.
MOVE: url TO filename. "In this example i used variable url that contain the fullpath.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = filename
filetype = 'BIN'
* has_field_separator = SPACE
* header_length = 0
* read_by_line = 'X'
* dat_mode = SPACE
* codepage = SPACE
* ignore_cerr = ABAP_TRUE
* replacement = '#'
* virus_scan_profile = virus_scan_profile
IMPORTING
filelength = filelength
* header = header
CHANGING
data_tab = data_tab
* isscanperformed = SPACE
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19
).
CHECK data_tab[] IS NOT INITIAL.
*DATA INPUT_LENGTH TYPE I.
*DATA FIRST_LINE TYPE I.
*DATA LAST_LINE TYPE I.
DATA buffer TYPE xstring.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = filelength
* FIRST_LINE = 0
* LAST_LINE = 0
IMPORTING
buffer = buffer
TABLES
binary_tab = data_tab
EXCEPTIONS
failed = 1.
CHECK buffer IS NOT INITIAL. "This variable contain an xstring that can be used for your purpose
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |