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

tab delimited

Former Member
0 Likes
641

I need to create a tab delimited file. I am creating file using open dataset

How do i create a tab delimited file

create structure of filecontents 

open dataset file for output 

move values to filecontents 

transfer filecontents to file 

close dataset 

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
591

Check this example.



report zrich_0001.

parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: str type string.

constants: con_tab type x value '09'.

* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection.

itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.

itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.

  open dataset d1 for output in text mode.
  loop at itab.
    concatenate itab-field1 itab-field2 itab-field2 into str
                  separated by con_tab.
    transfer str to d1.
  endloop.
  close dataset d1.

Regards,

Rich Heilman

I need to create a tab delimited file. I am creating file using open dataset

How do i create a tab delimited file

create structure of filecontents 

open dataset file for output 

move values to filecontents 

transfer filecontents to file 

close dataset 

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
592

Check this example.



report zrich_0001.

parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: str type string.

constants: con_tab type x value '09'.

* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection.

itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.

itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.

  open dataset d1 for output in text mode.
  loop at itab.
    concatenate itab-field1 itab-field2 itab-field2 into str
                  separated by con_tab.
    transfer str to d1.
  endloop.
  close dataset d1.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
591

constants: con_tab type x will not work as concatenate needs separated by to be followed by character

constants: con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

does not work either . it simply displays a hash

Read only

0 Likes
591

<i>it simply displays a hash</i>

This is an internal representation of the tab, in the file there will be a tab and not a #

Regards,

RIch Heilman

Read only

Former Member
0 Likes
591

Thank you