‎2007 Oct 04 10:06 AM
Hi,
I am using function GUI_UPLOAD to load data from excel sheet to my internal table.Below is code.Everything works fine.Problem is that when i display the data copied into internal table , the different fields are separated by # .How to remove this # as i don't need it.Please help.
Thanks.
Code -
>
types: begin of ttab,
rec(1000) type c,
end of ttab.
types: begin of tdat,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of tdat.
data: itab type table of ttab with header line.
data: file_str type string.
parameters: p_file type localfile.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = p_file.
start-of-selection.
file_str = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = file_str
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 = itab
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.
Loop at itab.
write : / itab-REC.
endloop.
‎2007 Oct 04 10:10 AM
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = file_str
FILETYPE = 'ASC' " uncomment this line
HAS_FIELD_SEPARATOR = 'X' " uncomment this lineOr else if you are uploading data from excel file its better to use the fm : ALSM_EXCEL_TO_INTERNAL_TABLE
* Data Declarations for uploading excel file into internal table
data : it_data type table of alsmex_tabline initial size 0,
is_data type alsmex_tabline.
* Flatfile internal table.
types : begin of ty_tab,
kunnr type bsid-kunnr, " added on 31-07-2007
zuonr type bsid-zuonr,
end of ty_tab.
data : it_tab type table of ty_tab initial size 0,
is_tab type ty_tab.
* If Input file name is not initial.
if not p_ifname is initial.
* Upload EXCEL data into internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_ifname
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65356
tables
intern = it_data
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endif.
* Append EXCEL Data into a internal table
loop at it_data into is_data.
at new row.
clear is_tab.
endat.
if is_data-col = '001'.
move is_data-value to is_tab-kunnr.
endif.
if is_data-col = '002'.
move is_data-value to is_tab-zuonr.
endif.
at end of row.
append is_tab to it_tab.
endat.
clear : is_data.
endloop.
Regards
Gopi
‎2007 Oct 04 10:10 AM
just check the length of fields in internal table. and if requred extend them.
reward if useful
‎2007 Oct 04 10:10 AM
HI
please do not use gui_upload its for csv and word format
for uploading excel please use
ALSM_EXCEL_TO_INTERNAL_TABLE
reward if helpful
vivekanand
‎2007 Oct 04 10:10 AM
Hi...
What format did you saved the file....
Tab delimited is one quick solution to this....
If the hint is useful Say thanks by reward .
Regards,
Prabhu Rajesh
‎2007 Oct 04 10:10 AM
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = file_str
FILETYPE = 'ASC' " uncomment this line
HAS_FIELD_SEPARATOR = 'X' " uncomment this lineOr else if you are uploading data from excel file its better to use the fm : ALSM_EXCEL_TO_INTERNAL_TABLE
* Data Declarations for uploading excel file into internal table
data : it_data type table of alsmex_tabline initial size 0,
is_data type alsmex_tabline.
* Flatfile internal table.
types : begin of ty_tab,
kunnr type bsid-kunnr, " added on 31-07-2007
zuonr type bsid-zuonr,
end of ty_tab.
data : it_tab type table of ty_tab initial size 0,
is_tab type ty_tab.
* If Input file name is not initial.
if not p_ifname is initial.
* Upload EXCEL data into internal table
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_ifname
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65356
tables
intern = it_data
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endif.
* Append EXCEL Data into a internal table
loop at it_data into is_data.
at new row.
clear is_tab.
endat.
if is_data-col = '001'.
move is_data-value to is_tab-kunnr.
endif.
if is_data-col = '002'.
move is_data-value to is_tab-zuonr.
endif.
at end of row.
append is_tab to it_tab.
endat.
clear : is_data.
endloop.
Regards
Gopi
‎2007 Oct 04 10:11 AM
‎2007 Oct 04 10:13 AM
hI..
Change the Code like this:
<b>types: begin of ttab, "This structure is not required
rec(1000) type c,
end of ttab.</b>
<b>types: begin of tdat, "Declare this structue with the fields in the Excel file
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of tdat.</b>
<b>data: itab type table of TDAT with header line. "Observe the change</b>
data: file_str type string.
parameters: p_file type localfile.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = p_file.
start-of-selection.
file_str = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = file_str
FILETYPE = 'ASC'
<b> HAS_FIELD_SEPARATOR = ' ' "Set to SPACE</b>
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 = itab
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.
reward if Helpful.
‎2007 Oct 04 10:26 AM