2005 Jan 03 4:07 AM
I tried to upload .csv file in using GUI upload and it works.
THIS IS MY SAMPLE CODE.
CLEAR w_rawfile.
DESCRIBE TABLE i_rawfile LINES v_read. "Counter for records read
Condense w_rawfile-field.
Separate header record from detail records
LOOP AT i_rawfile INTO w_rawfile.
IF sy-tabix = 1. "header is always the first record
SPLIT w_rawfile-field AT ' ' INTO
w_header_file-name1
w_header_file-name2
w_header_file-name3
w_header_file-cntry
w_header_file-address1
w_header_file-address2.
APPEND w_header_file TO i_header_file.
CLEAR: w_header_file.
ELSE. "succeeding records are detail records
SPLIT w_rawfile-field AT ',' INTO
w_inputfile-nachn
w_inputfile-vorna
w_inputfile-nach2
w_inputfile-land1
w_inputfile-stras
APPEND w_inputfile TO i_inputfile.
ENDIF.
IF i try to replace my file into a .txt format. An error occurs. Please kindly give me the code to do this correctlt. ThanX!
I tried to upload .csv file in using GUI upload and it works.
THIS IS MY SAMPLE CODE.
CLEAR w_rawfile.
DESCRIBE TABLE i_rawfile LINES v_read. "Counter for records read
Condense w_rawfile-field.
Separate header record from detail records
LOOP AT i_rawfile INTO w_rawfile.
IF sy-tabix = 1. "header is always the first record
SPLIT w_rawfile-field AT ' ' INTO
w_header_file-name1
w_header_file-name2
w_header_file-name3
w_header_file-cntry
w_header_file-address1
w_header_file-address2.
APPEND w_header_file TO i_header_file.
CLEAR: w_header_file.
ELSE. "succeeding records are detail records
SPLIT w_rawfile-field AT ',' INTO
w_inputfile-nachn
w_inputfile-vorna
w_inputfile-nach2
w_inputfile-land1
w_inputfile-stras
APPEND w_inputfile TO i_inputfile.
ENDIF.
IF i try to replace my file into a .txt format. An error occurs. Please kindly give me the code to do this correctlt. ThanX!
2005 Jan 03 4:57 AM
Hi Van Walter Federiso,
following parameter you should pass into GUI_UPLOAD FM.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = <FILE NAME> eg. c:\upload.txt
FILETYPE = 'ASC' or <DAT>
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = <TABLE NAME>
it will work fine for txt file upload
Regards,
Parag
2005 Jan 03 6:49 AM
I already use the Function module for GUI Upload. But if i try ro debug the program the uploaded file doesnt read by the SAP program.
2005 Jan 03 6:56 AM
What is the <b>filetype</b> that you use ? As Parag has indicated, you should use 'ASC' filetype for text files.
In the FM <b>GUI_UPLOAD</b>, there is a parameter called <b>FILETYPE</b>. Make sure you are entering the proper filetype.
Secondly, after executing this Function Module, also check the sy-subrc. It usually points you to the mistake.
Regards,
Subramanian V.
Message was edited by: Subramanian Venkateswaran
2005 Jan 03 7:07 AM
This is my code:
CONSTANTS: c_pernr_error(26) VALUE 'PERSONNEL NUMBER NOT FOUND',
c_load_error(21) VALUE 'DATA CANNOT BE LOADED',
c_infty(4) VALUE '0008', "Infotype
c_endda TYPE d VALUE '99991231', "End Date
c_type TYPE char10 VALUE 'ASC', "Filetype
c_filename(50) VALUE 'c:\test data for ARIS to SAP.txt'.
REFRESH: i_rawfile,
i_header_file ,
i_inputfile,
i_err_tab,
i_bdcdata,
i_err_tab2,
i_error2.
v_file = c_filename.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = v_file
filetype = c_type
CHANGING
data_tab = i_rawfile
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.
WRITE: / c_load_error.
ENDIF.
2005 Jan 03 7:14 AM
What is the <b>sy-subrc</b> or <b>exception</b> thrown, while executing the Class method GUI_UPLOAD ?
That should hold the key to your error.
Regards,
Subramanian V.
Message was edited by: Subramanian Venkateswaran
2005 Jan 03 7:24 PM
Hello,
it's long ago that I did such uploads, but I remember me using filetype 'WK1' instead of 'ASC'... (not 100% sure, but perhaps you want to try it ).
Cheers, Ana
2008 Oct 27 6:21 AM
Reading Data from Presentation Server (Dialog)
To read data from the presentation server into an internal table with a user dialog, use the function module UPLOAD. The most important parameters are listed below. For more information, refer to the function module documentation in the Function Builder (Transaction SE37).
Important Import Parameters
Parameters
Function
CODEPAGE
Only for upload under DOS: Value IBM
FILENAME
Filename (default value for user dialog)
FILETYPE
File type (default value for user dialog)
ITEM
Title for dialog box
Use the FILETYPE parameter to specify the transfer mode. Possible values:
BIN
Binary files
ASC
ASCII files: Text files with end of line markers.
DAT
Excel files, saved as text files with columns separated by tabs and lines separated by line breaks.
WK1
Excel and Lotus files saved as WK1 spreadsheets.
Important Export Parameters
Parameters
Function
FILESIZE
Number of bytes transferred
ACT_FILENAME
Filename (as entered in the user dialog)
ACT_FILETYPE
File type (as entered in the user dialog)
Tables Parameters
Parameters
Function
DATA_TAB
Internal table (target for the import)
Exceptions Parameters
Parameters
Function
CONVERSION_ERROR
Error converting data
INVALID_TABLE_WIDTH
Invalid table structure
INVALID_TYPE
Incorrect FILETYPE parameter
Suppose the presentation server is running under Windows NT, and contains the following Excel file:
If this table is saved as a text file "D:\temp\mytable.txt" with tabs between the columns, the following program can read the table:
PROGRAM SAPMZTST.
DATA: FNAME(128), FTYPE(3), FSIZE TYPE I.
TYPES: BEGIN OF LINE,
COL1(10) TYPE C,
COL2(10) TYPE C,
COL3(10) TYPE C,
END OF LINE.
TYPES ITAB TYPE LINE OCCURS 10.
DATA: LIN TYPE LINE,
TAB TYPE ITAB.
CALL FUNCTION 'UPLOAD'
EXPORTING
CODEPAGE = 'IBM'
FILENAME = 'd:\temp\mytable.txt'
FILETYPE = 'DAT'
ITEM = 'Read Test for Excel File'
IMPORTING
FILESIZE = FSIZE
ACT_FILENAME = FNAME
ACT_FILETYPE = FTYPE
TABLES
DATA_TAB = TAB
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3.
WRITE: 'SY-SUBRC:', SY-SUBRC,
/ 'Name :', (60) FNAME,
/ 'Type :', FTYPE,
/ 'Size :', FSIZE.
SKIP.
LOOP AT TAB INTO LIN.
WRITE: / LIN-COL1, LIN-COL2, LIN-COL3.
ENDLOOP.
The program displays the following dialog box:
Here, the user can change the default values. When the user chooses Transfer, the system imports the data from the file D:\temp\mytable.txt into the internal table TAB.
The output appears as follows:
SY-SUBRC: 0
Name : d:\temp\mytable.txt
Type : DAT
Size : 69
Billy the Kid
My Fair Lady
Herman the German
Conan the Barbarian
The contents of the internal table TAB are exactly the same as the contents of the original Excel table.
2005 Jan 03 11:37 AM
Hi,
i had tried and uploaded data from a .txt file using functions i am putting it here just have a look it might help you,
Declare the file name as given below
PARAMETER: d_file TYPE rlgrap-filename MEMORY ID file .
and use this function to get your file name or give the value simply,
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = '.,..'
IMPORTING
filename = d_file.
This will upload the data into the table tl_table.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = d_file
filetype = 'ASC'
TABLES
data_tab = tl_table
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
GUI_UPLOAD can also be used instead of WS_UPLOAD.
I have submitted a sample code for the same, do check that also.
Regards,
Kathir