‎2008 Jan 14 11:20 AM
hi,
I want to know how to read an excel file in the aplication server into an internal table.
if possible send a sample code for the same.
‎2008 Jan 14 11:55 AM
Hi,
Use the function module GUI_UPLOAD for your requirement.
If you want to upload data to the dictionary you can use the concept of LSMW.
Regards,
Renjith Michael.
‎2008 Jan 14 12:00 PM
Hi Krithi,
Use the Open and read dataset to read a file from appln server.
data: filename(120) type c value 'material.xls'.
open dataset filename for output in text mode encodingdefault.
read dataset filename.
Reward point if it s useful.
with regards,
Thasneem
‎2008 Jan 14 12:04 PM
hi
just copy paste this code and check out this in debugging mode.
it will clear all ur doubts
-
REPORT zdosunix LINE-SIZE 255..
&----
& File Transfer Program: Work Station to Application Server &
& Application Server to Work Station &
& &
*& Author: Ram Dindi
&----
PARAMETERS ***
SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME.
PARAMETERS: utod RADIOBUTTON GROUP grp1,
dtou RADIOBUTTON GROUP grp1 DEFAULT 'X'.
SELECTION-SCREEN ULINE.
PARAMETERS: fromf LIKE rlgrap-filename,
tof LIKE rlgrap-filename.
SELECTION-SCREEN ULINE.
PARAMETERS: disp AS CHECKBOX.
SELECTION-SCREEN : END OF BLOCK blk1.
INTERNAL TABLE ***
DATA: BEGIN OF text_lines OCCURS 1,
content(6000),
END OF text_lines.
CONSTANTS & VARIABLES
*----
DATE User ID TR (E1B) Description
*----
30.10.2007 AMANDAKA DEVK933893 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
*DATA: filetype LIKE rlgrap-filetype VALUE 'ASC'.
DATA: filetype type CHAR10 VALUE 'ASC'.
End of change by AMANDAKA for Unicode Compliant
DATA: errors(1).
START-OF-SELECTION.
MAIN PROGRAM ***
CLEAR errors.
IF dtou = 'X'.
PERFORM upload_pc_file USING fromf.
IF errors IS INITIAL.
PERFORM write_unix_file USING tof.
ENDIF.
ELSEIF utod = 'X'.
PERFORM read_unix_file USING fromf.
IF errors IS INITIAL.
PERFORM download_pc_file USING tof.
ENDIF.
ENDIF.
IF disp = 'X' AND errors IS INITIAL.
PERFORM display_input_file.
ENDIF.
REFRESH text_lines. CLEAR text_lines.
************************************************************************
UNIX FORM
&----
*& Form CLOSE_UNIX_FILE
&----
*
----
*----
DATE User ID TR (E1B) Description
*----
2.11.2007 AMANDAKA DEVK933897 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
*FORM close_unix_file USING file_name .
FORM close_unix_file USING file_name LIKE rlgrap-filename.
End of change by AMANDAKA for Unicode Compliant
CLOSE DATASET file_name.
ENDFORM. " CLOSE_UNIX_FILE
&----
*& Form WRITE_UNIX_FILE
&----
*
----
*----
DATE User ID TR (E1B) Description
*----
2.11.2007 AMANDAKA DEVK933897 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
*FORM write_unix_file USING file_name .
FORM write_unix_file USING file_name LIKE rlgrap-filename.
End of change by AMANDAKA for Unicode Compliant
WRITE: / 'Write the UNIX file'.
OPEN DATASET file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*OPEN DATASET file_name IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
OPEN DATASET file_name FOR OUTPUT IN BINARY MODE.
IF sy-subrc <> 0.
WRITE: / 'Error Opening the UNIX file' COLOR 6.
errors = 'X'.
ELSE.
LOOP AT text_lines.
PERFORM write_to_file USING file_name text_lines.
ENDLOOP.
PERFORM close_unix_file USING file_name.
WRITE: / 'UNIX writting done ...'.
ULINE.
ENDIF.
ENDFORM. " WRITE_UNIX_FILE
&----
*& Form READ_UNIX_FILE
&----
*
----
*----
DATE User ID TR (E1B) Description
*----
2.11.2007 AMANDAKA DEVK933897 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
*FORM read_unix_file USING file_name .
FORM read_unix_file USING file_name LIKE rlgrap-filename.
End of change by AMANDAKA for Unicode Compliant
WRITE: / 'Read the UNIX file'.
REFRESH text_lines. CLEAR text_lines.
OPEN DATASET file_name FOR INPUT IN TEXT MODE ENCODING DEFAULT.
OPEN DATASET file_name FOR INPUT IN BINARY MODE.
IF sy-subrc <> 0.
WRITE: / 'Error Opening the UNIX file' COLOR 6.
errors = 'X'.
ELSE.
DO.
READ DATASET file_name INTO text_lines.
IF sy-subrc <> 0. EXIT. ENDIF.
APPEND text_lines.
ENDDO.
PERFORM close_unix_file USING file_name.
WRITE: / 'UNIX reading done...'.
ULINE.
ENDIF.
ENDFORM. " READ_FILE_BACK
&----
*& Form WRITE_TO_FILE
&----
*
----
*----
DATE User ID TR (E1B) Description
*----
2.11.2007 AMANDAKA DEVK933897 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
*FORM write_to_file USING file_name text_line .
FORM write_to_file USING file_name LIKE rlgrap-filename text_line STRUCTURE text_lines.
End of change by AMANDAKA for Unicode Compliant
TRANSFER text_line TO file_name.
IF sy-subrc <> 0.
WRITE: / 'Write Unsuccessful in UNIX file' COLOR 6.
errors = 'X'.
ENDIF.
ENDFORM. " WRITE_TO_FILE
PC FORM
&----
*& Form UPLOAD_PC_FILE
&----
*
----
*----
DATE User ID TR (E1B) Description
*----
2.11.2007 AMANDAKA DEVK933893 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
*FORM upload_pc_file USING file_name .
FORM upload_pc_file USING file_name LIKE rlgrap-filename.
End of change by AMANDAKA for Unicode Compliant
WRITE: / 'Upload of the PC file'.
DATA v_filename TYPE string.
v_filename = file_name.
REFRESH text_lines. CLEAR text_lines.
*----
DATE User ID TR (E1B) Description
*----
30.10.2007 AMANDAKA DEVK933893 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_name
filetype = filetype
TABLES
data_tab = text_lines
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_filename
filetype = 'BIN'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = '8400'
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '$'
CHECK_BOM = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = text_lines
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.
End of change by AMANDAKA for Unicode Compliant
IF sy-subrc NE 0.
WRITE: / 'An error occurs during the PC upload' COLOR 6.
errors = 'X'.
ELSE.
WRITE: / 'PC upload done...'.
ULINE.
ENDIF.
ENDFORM. " UPLOAD_PC_FILE
&----
*& Form DOWNLOAD_PC_FILE
&----
*
----
FORM download_pc_file USING file_name.
DATA: length TYPE i.
DATA v_filename TYPE string.
v_filename = file_name.
WRITE: / 'Download of the PC file'.
*----
DATE User ID TR (E1B) Description
*----
30.10.2007 AMANDAKA DEVK933893 Changes for Unicode Compliance
*----
Begin of change by AMANDAKA for Unicode Compliant
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = file_name
filetype = 'ASC'
IMPORTING
filelength = length
TABLES
data_tab = text_lines
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = v_filename
FILETYPE = 'BIN'
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
IMPORTING
FILELENGTH = length
tables
data_tab = text_lines
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
End of change by AMANDAKA for Unicode Compliant
IF sy-subrc NE 0.
WRITE: / 'An error occurs during the PC download' COLOR 6.
errors = 'X'.
ELSE.
WRITE: / 'PC download done...'.
ULINE.
ENDIF.
ENDFORM. " DOWNLOAD_PC_FILE
&----
*& Form DISPLAY_INPUT_FILE
&----
*
----
FORM display_input_file.
WRITE: / 'Following are the file contents:'.
ULINE.
LOOP AT text_lines.
WRITE: /2 text_lines.
ENDLOOP.
ULINE.
ENDFORM. " DISPLAY_INPUT_FILE
-
regards
vijay
reward points if helpfull
‎2008 Jan 14 12:19 PM
Hi,
You have to use open dataset <file name > for output IN TEXT MODE ENCODING DEFAULT.
loop at itab.
transfer itab into filename.
close dataset.
now use the FM 'Gui_upload' pass the file name and file type -.xls.
it will work.
tahnx.
sunil.
‎2008 Jan 14 12:23 PM
hi
good
go through this link ,hope this would help you to solve your problem.
http://www.sapdev.co.uk/file/file_disall.htm
thanks
mrutyun^
‎2008 Jan 14 1:46 PM
Use this function module. 'UPLOAD_FILES'. You can upload from application server
Regards
Jayan Chembadathil