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: 

read file from application server

Former Member
0 Kudos

Hi guru,

i am reading file from application server which is seprated by semicolumn.

How can i read this file.

Thnaks

Neo

3 REPLIES 3

Former Member
0 Kudos

Declare an itab with one field of type string. Read the file into this itab using OPEN DATASET statement.. then loop at this itab & SPLIT the <fld> at ';' into diff fields of a work area.. append that work area to another itab of the desired structure.. get it?

Arya

Former Member
0 Kudos

OPEN DATASET LV_FILENAME FOR INPUT IN TEXT MODE MESSAGE MSG.

DO.

*-- Read Dataset and Populate Input file data to Internal Table

READ DATASET LV_FILENAME INTO IT_DATA2.

IF SY-SUBRC EQ 0.

*-- Append and Initialize table

APPEND IT_DATA2.

CLEAR IT_DATA2.

ELSE.

*-- Exit Out of DO loop if READ is unsuccess

EXIT.

ENDIF.

ENDDO.

*-- Close Dataset

close datset lv_filename.

loop at it_data2.

split it_data2-line at ';' into it_data-field1 it_data-field2....

append it_data.

endloop.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You are going to want to do something like this.



report zrich_0001.

data: str type string.

data: begin of itab occurs 0,
      fld1(10) type c,
      fld2(10) type c,
      fld3(10) type c,
      end   of itab.

data:
      dsn(500) value '/usr/sap/TST/sys/test.txt'.

clear itab.  refresh itab.

* Read the data.
open dataset dsn for input in binary mode.
do.
  read dataset dsn into str.
  if sy-subrc = 0.
   split str at ';' into itab-fld1 itab-fld2 itab-fld3.
    append itab.
  else.
    exit.
  endif.
enddo.
close dataset dsn.


Loop at itab.
  write:/ itab-fld1, itab-fld2, itab-fld3.
endloop.

Regards,

Rich Heilman