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 all the records from the file in Application Server

Former Member
0 Kudos

Hi,

I need to read all the records in a file from the Application server.I have coded and it reads the same record( the first one ) and runs into an infinite loop.

OPEN DATASET w_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.

<b> DO.</b>

READ DATASET w_path INTO i_tab.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

APPEND i_tab.

clear i_tab.

<b> ENDDO.</b>

Please suggest.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi shiva,

give

DO.

READ DATASET w_path INTO i_tab.

IF SY-SUBRC <> 0.

EXIT.

<b>else.</b>

APPEND i_tab.

clear i_tab.

ENDIF.

ENDDO.

5 REPLIES 5

Former Member
0 Kudos

Hi Sivakumar,

Form the code it seems that your i_tab is some internal table . This doesnot get all the records. You should declare it of type <b>tedata-data</b>.

Note : TEDATA-DATA is declared as length 5000(char). You can also use STRING, but using this(TEDATA-DATA ) is the standard practise.

Do it in this way.


DATA : msg(200). "For holding messages during OPEN DATASET

<b>DATA : i_tab LIKE tedata-data.</b>

*Lets assume that <b>i_int</b> is your internal table header line.

OPEN DATASET w_path FOR INPUT IN TEXT MODE ENCODING DEFAULT <b>MESSAGE msg</b>.


IF sy-subrc NE 0.
  MESSAGE w_osmsg TYPE 'S' DISPLAY LIKE 'E'.
  LEAVE LIST-PROCESSING.
ENDIF.

DO.
  READ DATASET w_path INTO i_tab.

<b>  IF sy-subrc EQ 0.</b>
    
    i_int = i_tab.
    APPEND i_int.
    CLEAR  i_int.
    
<b>  ELSE.</b>

    EXIT.
<b>  ENDIF.</b>


ENDDO.

  CLOSE DATASET w_path.

Regards,

Arun Sambargi

Message was edited by: Arun Sambargi

sunilachyut
Contributor
0 Kudos

Try the following:

data: itab type table of string.

data: wa type string.

open dataset d1 for input in text mode.

if sy-subrc = 0.

do.

read dataset d1 into wa.

if sy-subrc <> 0.

exit.

endif.

append wa to itab.

enddo.

endif.

close dataset d1.

hith

Sunil Achyut

Former Member
0 Kudos

hi shiva,

give

DO.

READ DATASET w_path INTO i_tab.

IF SY-SUBRC <> 0.

EXIT.

<b>else.</b>

APPEND i_tab.

clear i_tab.

ENDIF.

ENDDO.

0 Kudos

Thanks Priya. It worked. I 've missed giving it in else part. But I couldnlt understand the reason that the "Do loop" is performed more than n number of times where n = number of recs in the file.

Regards,

Siva

former_member226234
Contributor
0 Kudos

The file may have blank lines appended in the end. check the file