09-21-2007 10:25 AM
hi experts,
i am getting splitting error wile uploading the file from local drive from teh below code.
could any on ehelp me how to solve that error.
form upload_file.
data: w_matnr like mara-matnr,
w_datum like sy-datum.
data:
w_file1 type zppiforecast.
move p_file to w_line.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = W_LINE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
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 =
HEADER =
TABLES
DATA_TAB = I_FILE
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.
message w005(z1) with 'File ' p_file ' cannot be opened'.
ENDIF.
loop at i_file into w_file1.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = w_file1-matnr
importing
output = w_matnr
exceptions
length_error = 1
others = 2.
i_file-index = sy-index.
*Check that the date is in the correct format.
call function 'CONVERT_DATE_TO_INTERN_FORMAT'
exporting
datum = w_file1-datum
dtype = 'DATS'
importing
error = w_error
idate = w_file1-datum
messg = w_messg
msgln = w_msgln.
*If an error has occurred write entry to error table, otherwise append
*record list
if not w_error is initial.
t_exception = i_file.
t_exception-message = text-006.
append t_exception.
else.
check i_file-datum in so_datum.
modify i_file from w_file1 index sy-tabix.
endif.
endloop.
endform. " upload_file
09-21-2007 11:31 AM
You have not Splitted Values into different fields, and that's why the Error.
You got all values from the flat file into Internal Table i_file. But this Internal table will store values just like flat file does, without any fieldnames supporting the values. So, after you get the data in i_file using GUI_UPLOAD, you need to Split values available in each record of i_file, and put it into some Internal Table of type final structure.
Please see code below to understand better:
-
*Structure to get data from input file.
TYPES : BEGIN OF ty_inputfile,
line TYPE char255,
END OF ty_inputfile.
*Structure to hold data of input file.
TYPES : BEGIN OF ty_input,
kunnr TYPE kunnr,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
parvw TYPE parvw,
ktonr TYPE ktonr,
END OF ty_input.
DATA : i_inputfile TYPE STANDARD TABLE OF ty_inputfile,
i_input TYPE STANDARD TABLE OF ty_input,
DATA : wa_inputfile TYPE ty_inputfile,
wa_input TYPE ty_input,
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_v_inputfile
filetype = k_asc
has_field_separator = k_x
CHANGING
data_tab = i_inputfile
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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE l_k_i NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
LEAVE LIST-PROCESSING.
ENDIF.
LOOP AT i_inputfile INTO wa_inputfile.
SPLIT wa_inputfile-line AT '|' INTO : wa_input-kunnr
wa_input-vkorg
wa_input-vtweg
wa_input-spart
wa_input-parvw
wa_input-ktonr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_input-kunnr
IMPORTING
output = wa_input-kunnr.
APPEND wa_input TO i_input.
CLEAR : wa_input,
wa_inputfile.
ENDLOOP.
-
You can now upload data using the Internet Table i_input.
Let me know if you require further info.
<b>Reward points if useful.</b>