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

Re:files

Former Member
0 Likes
535

Hi,

the below code is getting error already file open, i have tried in many ways plz any one check the code

DATA: lv_lines TYPE i, l_do_counter(3) type n value '1'.

data: dummy_file like ifile occurs 0 with header line, flag(1).

loop at ifile.

move-corresponding ifile to dummy_file.

append dummy_file.

COMPUTE lv_LINES = SY-TABIX MOD 500.

IF lv_lines EQ 0.

concatenate '/home/sapifc/custrept/roles_trans' 'l_do_counter' '.csv' into p_OUTFIL.

loop at dummy_file.

*if flag eq ' '.

*OPEN DATASET P_OUTFIL FOR OUTPUT IN TEXT MODE encoding default.

*else

if flag eq 'X'.

OPEN DATASET P_OUTFIL FOR APPENDING IN TEXT MODE encoding default.

IF SY-SUBRC = 0.

TRANSFER dummy_file TO P_OUTFIL.

else.

message e001 with ' file not transfered'.

endif.

ENDIF.

ENDLOOP.

l_do_counter = l_do_counter + 1.

FLAG = 'X'.

refresh dummy_file.

CLOSE DATASET P_OUTFIL.

endif.

endloop.

if dummy_file[] is not initial.

concatenate '/home/sapifc/custrept/roles_trans' 'l_do_counter' '.csv' into p_OUTFIL.

loop at dummy_file.

OPEN DATASET P_OUTFIL FOR APPENDING IN TEXT MODE encoding default.

IF SY-SUBRC = 0.

TRANSFER dummy_file TO P_OUTFIL.

else.

message e001 with ' file not transfered'.

endif.

ENDLOOP.

endif.

refresh dummy_file.

CLOSE DATASET P_OUTFIL.

2 REPLIES 2
Read only

former_member196280
Active Contributor
0 Likes
460

Problem is you are using open dataset inside loop and you are reopening it once again before closing it. Try to place it above LOOP at ifile. It will work.

Reward points.

Regards,

SaiRam

Read only

Former Member
0 Likes
460

Hi sravanthigopal,

OPEN DATASET p_file2 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE text-015 TYPE 'E'.

ENDIF.

LOOP AT it_main1 INTO x_main1.

TRANSFER x_main1 TO p_file2.

ENDLOOP.

CLOSE DATASET p_file2.

Here p_file2 is a parameter where we pass the path of the file. And it puts the file on to the application server.

it_main1 is an internal table.

Check my piece of code and it works.

Reward Points.

Thanks,

Tej..