2007 Jul 17 8:02 AM
Can any one guide me for how to upload excel spread sheet using function gui_upload.
2007 Jul 17 8:06 AM
Hello,
Try this way and reward if found helpfull.
Regards,
Rakesh.
parameters: pa_fname type rlgrap-filename.
move pa_fname to dataset.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = dataset
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 =
* IMPORTING
* FILELENGTH =
* HEADER =
tables
data_tab = it_record
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.
Message was edited by:
RAKESH S R
2007 Jul 17 8:10 AM
Use the FM gui_upload.
TYPES : BEGIN OF tp_data,
line(4096),
END OF tp_data.
DATA: l_filename_ip TYPE string,
tl_data TYPE STANDARD TABLE OF tp_data WITH HEADER LINE.
l_filename_ip = p_input.
*--Upload Data
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_filename_ip
filetype = 'ASC'
has_field_separator = ''
TABLES
data_tab = tl_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.
File name is string type so convert it into string as shown above. Now give the path of the required file and give the required extension. Extension is necessary. Give EXL fr excel sheet and TXT for notepad file etc. Call the FM and u will get all the data in the internal table tl_data.
Now once u get all the data in tl_data u can split it into ure required internal table as shown below.
Write the below logic after calling the above FM.
LOOP AT tl_data .
*--Taking the contents of the input file leaving the header part
PERFORM split_and_save USING tl_data-line.
ENDLOOP.
ENDIF.
ENDFORM. " gui_upload
&----
*& Form split_and_save
&----
Splitting the contents from the input file and saving them into
an internal table
----
-->P_TL_DATA_LINE text
----
FORM split_and_save USING fp_data.
*--Local data declaration
DATA : tl_data TYPE STANDARD TABLE OF tp_data WITH HEADER LINE,
l_type TYPE c,
c_comma(1) TYPE c VALUE ','.
*--Split at the Comma
SPLIT fp_data AT c_comma INTO TABLE tl_data.
CLEAR inputtab.
*--Move it to the target fields
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE inputtab TO <fs_field>.
IF NOT sy-subrc IS INITIAL.
EXIT.
ENDIF.
*--Extract source data
CLEAR tl_data.
READ TABLE tl_data INDEX sy-index.
*--Populate the target
<fs_field> = tl_data-line.
ENDDO.
*--Append this record
APPEND inputtab.
ENDFORM. " split_and_save
The above code will give u the required internal table.
Reward if helpful..
Cheers,
Sharadendu