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: 

Writing in a in file and going to a new line.

Former Member
0 Kudos

Hello.

There's something in a program i am currently writing.

I'm trying to write in 2 files with a format like this :


line1.....
line2.....

In the first file, everything is ok but in the second file, with exactly the same instructions, instead og getting my file like i need it, i've something like that :


line1......               line2....

Here is the code i'm using to write in the file :


  DATA : t_ent_estim like STANDARD TABLE OF ZVOIENT WITH HEADER LINE.

  LOOP AT t_ent_estim.
    TRANSFER t_ent_estim TO p_fici.
  ENDLOOP.

  PERFORM close_file(zvoiform) USING p_fici w_result.

The only difference is that in one case i use an internal table and in the other i use a structure i created myself :


DATA : BEGIN OF tbl_csv_trans OCCURS 0,
        s_csvdata(400),
       END OF tbl_csv_trans.

Anybody can explain to me why with the internal table, the instruction transfer does not write in a new line each occurence of my table ?

Thanks for the help.

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

Hi,

are you using the Open data set in text mode both the places.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

if not change it and see..

where is your open dataset in your coding.

Regards

vijay

4 REPLIES 4

former_member184569
Active Contributor
0 Kudos

Hi Helder,

I have also used a structure, and it works fine for me.

Check whether you have opened the file in text mode.

data : BEGIN OF i_final_file OCCURS 0,

record(300) TYPE c,

END OF i_final_file,

                                    • Open the file for output **********************

OPEN DATASET wa_c_filename FOR OUTPUT IN TEXT MODE.

IF sy-subrc NE 0.

MESSAGE a999 WITH 'The file could not be created'.

ENDIF.

                                • Write line items to file ************************

LOOP AT i_final_file.

TRANSFER i_final_file TO wa_c_filename.

ENDLOOP.

                                          • Close the file ******************************

CLOSE DATASET wa_c_filename.

Regards,

Susmitha

Reward points if helpful

Former Member
0 Kudos

Hi,

1.When you use first case it will automatically adjust according to the entered data length .

2.In the second case , the data will be fit according to the length of the field structure.

<i>Hope This Info Helps YOU.</i>

Regards,

Lakshmi

former_member188685
Active Contributor
0 Kudos

Hi,

are you using the Open data set in text mode both the places.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

if not change it and see..

where is your open dataset in your coding.

Regards

vijay

0 Kudos

Thanks Vijay.

What a silly error i did :-X

I use a form to open the DATASET in text mode, and i forgot to call it just before writing in the file...