2007 Jul 24 5:31 AM
Hi all,
How to read data from a file which is in application server.The file which i have in application server is excel file ...and what delimiter we have to use to separate the columns in excel...
2007 Jul 24 5:37 AM
Hi Hemavathi,
To read data from a file on the application server, use the READ DATASET statement:
Syntax
READ DATASET <dsn> INTO <f> [LENGTH <len>].
This statement reads data from the file <dsn> into the variable <f>. In order to determine into which variable you should read data from a file, you need to know the structure of the file.
You can specify the transfer mode in the OPEN DATASET statement. If you have not already opened the file for reading, the system tries to open it either in binary mode, or using the additions from the last OPEN DATASET statement. However, it is good practice only to open files using the OPEN DATASET statement.
If the system was able to read data successfully, SY-SUBRC is set to 0. When the end of the file is reached, SY-SUBRC is set to 4. If the file could not be opened, SY-SUBRC is set to 8.
2007 Jul 24 5:38 AM
use
OPEN DATASET <filename> for input in text mode.
READ DATASET into <var>
CLOSE DATASET.
2007 Jul 24 5:38 AM
Hello,
Better upload the file from Apll. server to internal table and make the modification.
Sample code:
Retrieve Data file from Application server(Upload from Unix)
DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
OPEN DATASET i_file FOR INPUT IN TEXT MODE.
IF sy-subrc NE 0.
MESSAGE e999(za) WITH 'Error opening file' i_file.
ENDIF.
DO.
Reads each line of file individually
READ DATASET i_file INTO wa_datatab.
Perform processing here
.....
ENDDO.
Refer this link
2007 Jul 24 5:39 AM
Hi,
Hi
U need to ask a little help to your basis in order to transfer the file from pc to Server SAP.
Usually there are some paths defined to place the file for BI.
The easy solution is to convert the excel file in CSV format and transfer it to SAP Server, in this way you'll be able to work on ASCII file.
Now you need to change your program in order to replace the fm to upload the file with statament OPEN DATASET/READ DATASET and CLOSE DATASET.
Probably now you're using fm like GUI_UPLOAD, this fm inserts the data into an internal table, so your program should become:
OPEN DATASET <FILE> IN TEXT MODE.
DO.
READ DATASET <FILE> TO ITAB.
IF SY-SUBRC <> 0. EXIT. ENDIF.
APPEND ITAB.
ENDDO.
CLOSE DATASET <FILE>.
U can use fm TEXT_CONVERT_CSV_TO_SAP in order to transfer the data in CSV format in your internal table.
Reward if useful!
2007 Jul 24 5:39 AM
Here is full code.
data:begin of itab occurs 0,
data(500),
end of itab.
open dataset <file name> for input in text mode.
if sy-subrc = 0.
do .
read dataset <filename> into itab-data.
if sy-subrc = 0.
append itab.
else.
exit.
endif.
enddo.
close dataset <filename>.
endif.
Regards,
2007 Jul 24 5:39 AM