‎2009 Mar 25 12:42 PM
hi experts,
iam using gui -upload function with text delimited file but if i use field separator = x and file type = 'asc'
it gives dump error related with unicode " Data objects in a Unicode program are not convertible" . if i use it without giving separotor it says it can not interpret the file but does not give dump , could u please suggest way out
‎2009 Mar 25 12:46 PM
‎2009 Mar 25 1:03 PM
Hi Saurabh,
Here iam giving example code for your reference,
DATA L_P_FILE TYPE STRING.
L_P_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_P_FILE
FILETYPE = u2018ASCu2019
HAS_FIELD_SEPARATOR = u2018Xu2019
TABLES
DATA_TAB = P_I_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.
Else.
(OR)
DATA L_P_FILE TYPE STRING.
L_P_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_P_FILE
FILETYPE = u2018ASCu2019
TABLES
DATA_TAB = P_I_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 NE 0.
MESSAGE E033 WITH P_FILE ' could not be opened'(E03).
ENDIF.
Regards
Arani Bhaskar
‎2009 Mar 25 1:13 PM
Hi Pls Comapre this
FORM upload_file.
DATA : l_file TYPE string.
IF NOT ( p_filep IS INITIAL ).
l_file = p_filep.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = LT_FILEP
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 TEXT-003 TYPE 'S'.
ENDIF.
SORT LT_FILEP BY belnr_d.
DELETE LT_FILEP WHERE belnr_d IS INITIAL.
ENDIF.
ENDFORM. " upload_file
Regards
‎2009 Mar 25 1:14 PM
Hi,
Open the report in change mode and in the ATTRIBUTES tab just UNCHECK the Unicode box.
and than execute the report.
also pls check in the flat file that the fields are seperated by a TAB space.
this would work..
thanks
ravi aswani
‎2009 Mar 26 1:26 PM
Hi Saurabh
I Suggest to use Capital lattrs in single quate i.e. separator = 'X' and file type = 'ASC'
and For the unicode you can use the class CL_GUI_FRONTEND_SERVICES=> GUI_UPLOAD instead of funaction module here is the test report:
************************************************************************
Minimal demo report for Virus Scan Interface.
For a functionally more complete example see report RSVSCANTEST.
************************************************************************
REPORT zvscandemo.
************************************************************************
Selection screen
************************************************************************
PARAMETERS:
profile TYPE vscan_prof-profile,
file TYPE localfile.
************************************************************************
Events
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file.
PERFORM file_f4.
START-OF-SELECTION.
PERFORM main.
************************************************************************
Main program
************************************************************************
FORM main.
IF file IS INITIAL.
MESSAGE s058(vscan) DISPLAY LIKE 'E'.
EXIT. " =================== EXIT =====================
ENDIF.
Access file and create XSTRING
TYPES:
ty_xline(1024) TYPE x.
DATA:
lf_file TYPE string,
lf_filelength TYPE i,
lt_datatab TYPE STANDARD TABLE OF ty_xline.
lf_file = file.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lf_file
filetype = 'BIN'
IMPORTING
filelength = lf_filelength
CHANGING
data_tab = lt_datatab
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT. " =================== EXIT =====================
ENDIF.
Recombine binary data
DATA:
lf_tabline TYPE ty_xline,
lf_data TYPE xstring.
LOOP AT lt_datatab INTO lf_tabline.
CONCATENATE
lf_data
lf_tabline
INTO
lf_data
IN BYTE MODE.
ENDLOOP.
lf_data = lf_data(lf_filelength).
Get scanner instance
DATA:
lo_vsi TYPE REF TO cl_vsi.
CALL METHOD cl_vsi=>get_instance
EXPORTING
if_profile = profile
IMPORTING
eo_instance = lo_vsi
EXCEPTIONS
configuration_error = 1
profile_not_active = 2
internal_error = 3
OTHERS = 4.
CASE sy-subrc.
No error.
WHEN 0.
" Nothing to do
Profile not active. For this report, this is an information message.
WHEN 2.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
DISPLAY LIKE 'I'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT. " =================== EXIT =====================
All other exceptions are issued as errors.
WHEN OTHERS.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT. " =================== EXIT =====================
ENDCASE.
Perform virus scan
DATA:
lf_scanrc TYPE vscan_scanrc.
CALL METHOD lo_vsi->scan_bytes
EXPORTING
if_data = lf_data
IMPORTING
ef_scanrc = lf_scanrc
EXCEPTIONS
not_available = 1
configuration_error = 2
internal_error = 3
OTHERS = 4.
All exceptions here are errors
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT. " =================== EXIT =====================
ENDIF.
Print return code and text
DATA:
lf_text TYPE string.
lf_text = cl_vsi=>get_scanrc_text( lf_scanrc ).
WRITE: / 'Result of virus scan: ', lf_scanrc, '(', lf_text, ')'.
IF lf_scanrc = cl_vsi=>con_scanrc_ok.
WRITE: / 'File is clean'.
ELSE.
WRITE: / 'File was either infected',
'or could not be scanned',
'or was ignored'.
'Or another problem occurred'.
ENDIF.
ENDFORM.
************************************************************************
F4-help for filename
************************************************************************
FORM file_f4.
DATA:
lt_filetable TYPE filetable,
lf_rc TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
multiselection = abap_false
CHANGING
file_table = lt_filetable
rc = lf_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
DISPLAY LIKE 'E'
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
Number of selected filed must be equal to one.
CHECK lf_rc = 1.
Access selected file
DATA:
ls_file TYPE file_table.
READ TABLE lt_filetable INTO ls_file INDEX 1.
CHECK sy-subrc = 0.
file = ls_file-filename.
ENDFORM.
Regard
Dhirendra Pandit