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 Text file from application server into internal table

Former Member
0 Kudos

Hi all,

I want to read a text file stored on application server into my internal table.

Eg. my text file contains 10 userids i want to read those into my Itab.

how can i do this...................

please provide me sample code for the same.

Thanks in advance

Vinod

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

check this thread,

9 REPLIES 9

Former Member
0 Kudos

Hi,

Use the FM GUI_UPLOAD.

Search SDN for sample code

Former Member
0 Kudos

Hi,

Use OPEN DATASET, READ DATASET



Data : p_file type rlgrap-filename,   " Application Server file path
          lt_input type table of typ_input " Internal table

open dataset p_file for input in text mode encoding default.
      if sy-subrc = 0.
        do.
          read dataset p_file into ls_input-wa_string.
          if sy-subrc eq 0.
            append ls_input to lt_input.
          else.
            exit.
          endif.
        enddo.
      endif.
      close dataset p_file.

Hope it will helps

Former Member
0 Kudos

Hi,

These are so many threads on this .

GUI_DOWNLOAD use this FM.

Rhea.

Former Member
0 Kudos

HI,

For reading a file from Appl server you have to use the statement: Read dataset command.

For writing a file to Appl server, use : Open dataset command.

for eg:in case of reading data from application server:

OPEN DATASET f_name FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET f_name INTO w_data1.

IF sy-subrc NE 0.

EXIT.

ENDIF.

SPLIT w_data1 AT w_char INTO fs_bkpf-bukrs

fs_bkpf-gjahr

fs_bkpf-blart

fs_bkpf-bldat

fs_bkpf-budat

fs_bkpf-monat

fs_bkpf-cpudt.

APPEND fs_bkpf TO t_bkpf. -


> this will be your internal table.

ENDDO.

CLOSE DATASET f_name.

Hope this helps...

Thnaks,

Rashmi.

Former Member
0 Kudos

Hi,

Use OPEN DATASET and READ DATASET keywords.

Go through the F1 Help available for these key words.

Former Member
0 Kudos

hi

check this thread,

0 Kudos

Just one correction to the presented code:

 
open dataset p_file for input in text mode encoding default.
if sy-subrc = 0.
  do.
    read dataset p_file into ls_input-wa_string.
    if sy-subrc eq 0.
      append ls_input to lt_input.
    else.
      exit.
    endif.
  enddo.
  close dataset p_file. "NEW LOCATION TO CLOSE  
endif.
"PREVIOUS LOCATION TO CLOSE

If you try to close the file without success in open file, you'll get a short dump.

Regards,

Valter Oliveira.

0 Kudos

Thanks Venu,

now i am able to read the terx file into internal table my internal table has only one field userid.

now i have one problem regarding formating of that data. while reading the data from applaction server # sign is coming after every record how can i eliminate that sign. i have also applied that shifting code but still it is not working

can you give me the solution

following is my code

DATA: BEGIN OF unlk_tab OCCURS 0, " with header line,

username LIKE xu200-xuser,

END OF unlk_tab.

OPEN DATASET dsn FOR INPUT IN TEXT MODE ENCODING DEFAULT.

*loop at dsn.

DO.

READ DATASET dsn INTO unlk_tab-username.

IF sy-subrc EQ '0'.

shift unlk_tab-username right deleting trailing l_tab.

APPEND unlk_tab.

ELSE.

EXIT.

ENDIF.

ENDDO.

Former Member
0 Kudos

hi

from the same thread try this code using field symbols concept

it will work

data: l_tab(1) type c value cl_abap_char_utilities=>horizontal_tab.

data: T_FIELD(1000) TYPE C OCCURS 0.

data: <fs> type any.

open dataset wk_filepath for input in text mode encoding default.

do .

read dataset wk_filepath into wk_file.

if sy-subrc = 0.

*split wk_file at l_tab into l_h_tbl_upload-fld1 l_h_tbl_upload-fld2....

SPLIT wk_file at l_tab INTO TABLE T_FIELD.

LOOP AT T_FIELD.

ASSIGN COMPONENT SY-TABIX OF STRUCTURE l_h_tbl_upload to <FS>.

<FS> = T_FIELD.

ENDLOOP.

append l_h_tbl_upload to fc_tbl_upload.

endif.

enddo.

close dataset l_wk_filepath.