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

How to align the heading with data?

Former Member
0 Likes
1,248

Please see this sample program. How do you make the heading alignment with the data AUTOMATICALLY without manually count the spaces?

Thanks,

Helen

REPORT z_test9.

DATA: BEGIN OF itab OCCURS 0,

fld1(10) TYPE c,

fld2(10) TYPE c,

fld3(10) TYPE c,

END OF itab.

DATA: ifn TYPE TABLE OF string WITH HEADER LINE.

TYPES:BEGIN OF t_head,

column(20) TYPE c,

END OF t_head.

DATA:i_header TYPE STANDARD TABLE OF t_head WITH HEADER LINE.

*i_header = 'Mat num'. APPEND i_header.

*i_header = 'Plant'. APPEND i_header.

CONCATENATE 'Mat num' 'Plant' 'Field3'

INTO i_header

SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

APPEND i_header.

  • Add the data

itab-fld1 = 'AAAAAAAAAA'.

itab-fld2 = 'BBBBBBBBBB'.

itab-fld3 = 'CCCCCCCCCC'.

APPEND itab.

itab-fld1 = '1111111111'.

itab-fld2 = '2222222222'.

itab-fld3 = '3333333333'.

APPEND itab.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

TABLES

data_tab = i_header.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

append = 'X'

write_field_separator = 'X'

TABLES

data_tab = itab

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
710

Make the highlighted changes

REPORT z_test9.

DATA: BEGIN OF itab OCCURS 0,

fld1(10) TYPE c,

fld2(10) TYPE c,

fld3(10) TYPE c,

END OF itab.

DATA: ifn TYPE TABLE OF string WITH HEADER LINE.

DATA:i_header TYPE STANDARD TABLE OF t_head WITH HEADER LINE.

<b>i_header-fld1 = 'Mat num'.

i_header-fld2 = 'Plant'.

i_header-fld2 = 'Field3'.

APPEND i_header.

clear i_header.</b>

  • Add the data

itab-fld1 = 'AAAAAAAAAA'.

itab-fld2 = 'BBBBBBBBBB'.

itab-fld3 = 'CCCCCCCCCC'.

APPEND itab.

itab-fld1 = '1111111111'.

itab-fld2 = '2222222222'.

itab-fld3 = '3333333333'.

APPEND itab.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

<b>write_field_separator = 'X'</b>

TABLES

data_tab = i_header.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

append = 'X'

write_field_separator = 'X'

TABLES

data_tab = itab

Please see this sample program. How do you make the heading alignment with the data AUTOMATICALLY without manually count the spaces?

Thanks,

Helen

REPORT z_test9.

DATA: BEGIN OF itab OCCURS 0,

fld1(10) TYPE c,

fld2(10) TYPE c,

fld3(10) TYPE c,

END OF itab.

DATA: ifn TYPE TABLE OF string WITH HEADER LINE.

TYPES:BEGIN OF t_head,

column(20) TYPE c,

END OF t_head.

DATA:i_header TYPE STANDARD TABLE OF t_head WITH HEADER LINE.

*i_header = 'Mat num'. APPEND i_header.

*i_header = 'Plant'. APPEND i_header.

CONCATENATE 'Mat num' 'Plant' 'Field3'

INTO i_header

SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

APPEND i_header.

  • Add the data

itab-fld1 = 'AAAAAAAAAA'.

itab-fld2 = 'BBBBBBBBBB'.

itab-fld3 = 'CCCCCCCCCC'.

APPEND itab.

itab-fld1 = '1111111111'.

itab-fld2 = '2222222222'.

itab-fld3 = '3333333333'.

APPEND itab.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

TABLES

data_tab = i_header.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

append = 'X'

write_field_separator = 'X'

TABLES

data_tab = itab

3 REPLIES 3
Read only

Former Member
0 Likes
710

Hi helen,

1. Its already aligned.

2. If u open the file in excel,

it will open perfectly fine,

with column headings,

and appropriate data beneath it.

3. Since you are using TAB as a file separator,

it won't look aligned in NOTEPAD.

(bcos the field length of data is more than

the heading)

4. In excel it would look perfectly fine.

regards,

amit m.

Read only

Former Member
0 Likes
711

Make the highlighted changes

REPORT z_test9.

DATA: BEGIN OF itab OCCURS 0,

fld1(10) TYPE c,

fld2(10) TYPE c,

fld3(10) TYPE c,

END OF itab.

DATA: ifn TYPE TABLE OF string WITH HEADER LINE.

DATA:i_header TYPE STANDARD TABLE OF t_head WITH HEADER LINE.

<b>i_header-fld1 = 'Mat num'.

i_header-fld2 = 'Plant'.

i_header-fld2 = 'Field3'.

APPEND i_header.

clear i_header.</b>

  • Add the data

itab-fld1 = 'AAAAAAAAAA'.

itab-fld2 = 'BBBBBBBBBB'.

itab-fld3 = 'CCCCCCCCCC'.

APPEND itab.

itab-fld1 = '1111111111'.

itab-fld2 = '2222222222'.

itab-fld3 = '3333333333'.

APPEND itab.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

<b>write_field_separator = 'X'</b>

TABLES

data_tab = i_header.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'c:\a\download2.txt'

filetype = 'ASC'

append = 'X'

write_field_separator = 'X'

TABLES

data_tab = itab

Read only

Former Member
0 Likes
710

You could append the headings in a header structure and pass it along with the GUI_DOWNLOAD function.

I do not have access to SAP right now, but if you look at the function module, you should be able to find an internal table to store headers.