06-21-2010 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
06-21-2010 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.
06-21-2010 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
07-12-2012 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
07-12-2012 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.
05-08-2014 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.