cancel
Showing results for 
Search instead for 
Did you mean: 

Inseting tabs when using open dataset statement

Former Member
0 Kudos

I need to write a file to application server, and i wanted it to be a excel file.

I tried binary mode, text mode but i am not able to print the tab charater in the file.

any suggestions to print the tab charater?

thanks,

Gopi.

CODE:

v_file = "/usr/test.xls".

OPEN DATASET v_file FOR OUTPUT in binary mode.

LOOP AT i_hr.

  • move-corresponding i_hr to i_out.

  • TRANSFER i_out TO v_file.

transfer i_out-pernr to v_file.

transfer '\t' to v_file.

transfer i_out-nachn to v_file.

transfer '\t' to v_file.

transfer i_out-vorna to v_file.

TRANSFER '\n' TO v_file.

ENDLOOP.

CLOSE DATASET v_file.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Gopi,

You can do it by declaring another variable with a length that can accommodate your internal table fields and the tabs in between. Change your code as follows(in bold).


<b><i>data: v_filerecord(1000) type c.
constants: c_tab_delimiter type x value '09'.</i></b>

v_file = "/usr/test.xls".

OPEN DATASET v_file FOR OUTPUT in binary mode.
LOOP AT i_hr.
<b><i>
concatenate i_hr-field1
            i_hr-field2
....... and so on for all fields
       into v_filerecord separated by c_tab_delimiter.
transfer v_filerecord to v_file.
</i></b>
* move-corresponding i_hr to i_out.
* TRANSFER i_out TO v_file.
*transfer i_out-pernr to v_file.
*transfer 't' to v_file.
*transfer i_out-nachn to v_file.
*transfer 't' to v_file.
*transfer i_out-vorna to v_file.

*TRANSFER 'n' TO v_file.
ENDLOOP.
CLOSE DATASET v_file.

Please let me know if you need any further help in this regard. If it solves your problem, please reward and close the issue.

Regards,

Srinivas

Former Member
0 Kudos

its giving syntax error.

"c_tab_delimiter" must be a character-tye data object (data type C, N, D, T or string).

same issue with Forberger's suggestion.

i tried to write the tab directly to the file in binary mode and its fine.

transfer c_tab_delimiter to v_file.

this ones gives the tab. but i am not able to get the new line. tried to uses these seperately and together. but didn't work.

constants: con_newline TYPE x VALUE '13'.

constants: con_linefeed TYPE x VALUE '10'.

if i use text mode, i need to use the concatenate statement and thats giving syntax error.

Former Member
0 Kudos

Hi Gopi,

I have used it several times and it didn't give me any syntax error. I knew it works in 46c. Which version are you in?

I know that the strings to be concatenated need to be of type character, but I don't think 'Separated by' field needs to be a character.

Please share your code again with the changes including the definition of your internal table.

Regards,

Srinivas

Former Member
0 Kudos

I found out that the concatenate statement which has 2 different datatypes works in 4.6C but not in 4.7.

I am working on 4.7

Former Member
0 Kudos

I had to uncheck the "unicode checks active" checkbos in the program attributes and its working fine.

thanks.

G.

Former Member
0 Kudos

Hi Gopi,

Glad to see that your issue has been resolved. If not, I was about to suggest that you define another internal table as follows and use that for download.

begin itab

field1

tabseparator1

field2

tabseparator2

end itab.

and so on...

Now that you resolved your issue, could you please reward and close the issue?

Thanks,

Srinivas

Answers (2)

Answers (2)

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Gopi,

unchecked unicode is just a workaround. If you are interested in a solution, have a look at

In short: define a separator as char1 and fill in value like this:


CLASS cl_abap_char_utilities DEFINITION LOAD.
wa_line-sep01 = l_abap_char_utilities=>horizontal_tab.

Regards,

Christian

Former Member
0 Kudos

Try this piece of coding. I think it will work for you.

REPORT ZTAB_IN_FILE .

data: separator type x value '09'.

data: field1(10) type c,

field2(8) type c,

field3(6) type c.

data: wa_ausgabe(30) type c.

data: lv_file type rlgrap-filename value 'tab_test.xls'.

start-of-selection.

field1 = 'Schmitt'.

field2 = 'Ludwig'.

field3 = 'Firma'.

concatenate field1 separator

field2 separator

field3

into wa_ausgabe.

open dataset lv_file for output in text mode.

transfer wa_ausgabe to lv_file.

transfer wa_ausgabe to lv_file.

close dataset lv_file.

    • I know, coding needs a little more for being cute