Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

reading file in application sever

Former Member
0 Kudos
130

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...

6 REPLIES 6

Former Member
0 Kudos
77

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.

Former Member
0 Kudos
77

use

OPEN DATASET <filename> for input in text mode.

READ DATASET into <var>

CLOSE DATASET.

Former Member
0 Kudos
77

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

http://www.sapdevelopment.co.uk/file/file_updown.htm

Former Member
0 Kudos
77

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!

Former Member
0 Kudos
77

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,

Former Member
0 Kudos
77