Application Development and Automation 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 only

Modifying File in App Server

Former Member
0 Likes
580

Hello,

I have textfile in appserver. I want to change some lines in it. Using dataset, how to do this?

Thanks,

Sid

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
535

using open dataset get the file into the internal table modify it and re write to the same path.

to read the file into internal table.

OPEN DATASET p_ufile FOR INPUT IN TEXT MODE.
IF sy-subrc <> 0.
EXIT.
ENDIF.

DO.
READ DATASET p_ufile INTO wa_file.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ASSIGN wa_file TO <wa_table>.
APPEND <wa_table> TO p_table.
CLEAR wa_file.
ENDDO.

CLOSE DATASET p_ufile.
ENDIF.

modify ur p_table as per ur requirement..

to re-write file back to the same path.


OPEN DATASET p_ufile FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
EXIT.
ENDIF.
LOOP AT p_output INTO wa_file.
TRANSFER wa_file TO p_ufile.
CLEAR wa_file.
ENDLOOP.
CLOSE DATASET p_ufile.

3 REPLIES 3
Read only

former_member156446
Active Contributor
0 Likes
536

using open dataset get the file into the internal table modify it and re write to the same path.

to read the file into internal table.

OPEN DATASET p_ufile FOR INPUT IN TEXT MODE.
IF sy-subrc <> 0.
EXIT.
ENDIF.

DO.
READ DATASET p_ufile INTO wa_file.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ASSIGN wa_file TO <wa_table>.
APPEND <wa_table> TO p_table.
CLEAR wa_file.
ENDDO.

CLOSE DATASET p_ufile.
ENDIF.

modify ur p_table as per ur requirement..

to re-write file back to the same path.


OPEN DATASET p_ufile FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
EXIT.
ENDIF.
LOOP AT p_output INTO wa_file.
TRANSFER wa_file TO p_ufile.
CLEAR wa_file.
ENDLOOP.
CLOSE DATASET p_ufile.

Read only

0 Likes
535

Thanks Jay. How do you declare wa_file and p_output. pls.write some example. thanks.

Read only

0 Likes
535

Hi there...


data: wa_field type string.

data: p_output type standard table of string.
or 
data: begin of p_output,
          data(1000) type c,
         end of p_output.

assign points for all useful answers.