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: 

Displaying header in excel horizontally using FM GUI_DOWNLOAD

Former Member
0 Kudos

Dear Experts,

I'm exporting my data to an excel file using GUI_DOWNLOAD. The problem is that I'm having problems with exporting the headings of my excel. I can export the heading but the problem is that it is displayed vertically and not horizontally.

Is there a way I could display the heading horizontally? Hope you could help me.

Below is my program.

DATA: BEGIN OF itab OCCURS 0,

DVNO TYPE ZPFHEADER-DVNO,

EMPNO(8),

EMPNAME LIKE PA0002-CNAME,

LTYPE LIKE it_header-wtype,

LCODE LIKE it_header-dkond,

MA(6) TYPE p DECIMALS 2,

APRVDATE(15),

DTL LIKE ZPFHEADER-DVNO,

END OF itab.

DATA: BEGIN OF header OCCURS 0,

head1(15) TYPE c,

head2(15) TYPE c,

END OF header.

PERFORM DISPLAY_DATA.

----


  • FORM DISPLAY_DATA *

----


  • ........ *

----


FORM DISPLAY_DATA.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid

I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

it_events = gt_events[]

TABLES

t_outtab = jtab.

ENDFORM.

&----


*& FORM USER_COMMAND

&----


  • COMMAND for ALV Grid Buttons

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

PERFORM write_header.

CASE r_ucomm.

WHEN 'XCEL'.

CONCATENATE: 'C:\' fname sy-datum INTO fname.

CONCATENATE: fname '.XLS' INTO FILENAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = FILENAME

HEADER = '00'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = header

FIELDNAMES = header.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = FILENAME

APPEND = 'X'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = jtab

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22.

IF sy-subrc <> 0.

ELSEIF sy-subrc = 0.

MESSAGE S000(38) WITH 'File ' fname 'saved in Drive C.'.

ENDIF.

ENDCASE.

ENDFORM.

&----


*& Form write_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_header.

DATA: ctr(2) TYPE N.

DO 6 TIMES.

ADD 1 TO ctr.

CASE ctr.

WHEN 1. header-head1 = 'EMPLOYEE'.

header-head2 = ' NO '.

WHEN 2. header-head1 = 'EMPLOYEE'.

header-head2 = ' NAME '.

WHEN 3. header-head1 = 'LOAN'.

header-head2 = 'TYPE'.

WHEN 4. header-head1 = 'APPROVAL'.

header-head2 = ' DATE '.

WHEN 5. header-head1 = 'LOAN'.

header-head2 = 'CODE'.

WHEN 6. header-head1 = ' MONTHLY '.

header-head2 = 'AMORTIZATION'.

ENDCASE.

APPEND header.

CLEAR: header.

ENDDO.

----


The output should be something like this as shown below:

Employee Employee Loan Approval

Number Name Type Date

6633 ABAD, JUSTINA DVP1 2-Apr-07

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

before Inserting the Rows to Internal table, first Insert the Headings then start filling the Internal table, so the first reocrd will become the header

Regards

Sudheer

5 REPLIES 5

Former Member
0 Kudos

Hi,

before Inserting the Rows to Internal table, first Insert the Headings then start filling the Internal table, so the first reocrd will become the header

Regards

Sudheer

0 Kudos

Hi Sudheer,

THanks for your reply. But my problem is, not all the columns in the excel file are of type character. Some are numeric. Is there any other way? Thanks in advance.

0 Kudos

first have a itab with just one row (all characters fields) with the same no. of columns as the data itab. fill the row with desired header text.

now download this itab to say file C:....abc.xls

then again call gui_download pointing to the same download location with gui_download parameter APPEND = 'X'

with data itab

Raja

Former Member
0 Kudos

Hi

One quick solution (provided all your columns of internal table are of character type)

Have a record (as 1st record in your internal table), with the desired headings

Regards

Raj

Former Member
0 Kudos

Hi,

Check this sample code:

REPORT ZSW_DOWNLOAD_HEADER.

DATA : itab LIKE TABLE OF t001 WITH HEADER LINE.

*----


SELECT * FROM t001 INTO TABLE itab.

PERFORM mydownload TABLES itab USING 'C:\t001.txt'.

FORM mydownload TABLES ptab USING filename.

*----


DAta

*DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

DATA: dfies_tab LIKE dfies OCCURS 0 WITH HEADER LINE.

DATA : allfields(300) TYPE c.

DATA : fld(100) TYPE c.

DATA : BEGIN OF htab OCCURS 0,

allfields(300) TYPE c,

END OF htab.

CALL FUNCTION 'DDIF_FIELDINFO_GET'

EXPORTING

tabname = 'T001'

  • FIELDNAME = ' '

  • LANGU = SY-LANGU

  • LFIELDNAME = ' '

  • ALL_TYPES = ' '

  • GROUP_NAMES = ' '

  • UCLEN = UCLEN

  • IMPORTING

  • X030L_WA = X030L_WA

  • DDOBJTYPE = DDOBJTYPE

  • DFIES_WA = DFIES_WA

  • LINES_DESCR = LINES_DESCR

TABLES

dfies_tab = dfies_tab

  • FIXED_VALUES = FIXED_VALUES

  • EXCEPTIONS

  • NOT_FOUND = 1

  • INTERNAL_ERROR = 2

  • OTHERS = 3

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT dfies_tab.

CONCATENATE dfies_tab-fieldtext

cl_abap_char_utilities=>horizontal_tab INTO fld.

CONCATENATE allfields fld INTO allfields .

ENDLOOP.

htab-allfields = allfields.

APPEND htab.

*----


download first field list

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = 'c:\t001.xls'

filetype = 'DAT'

write_field_separator = 'X'

TABLES

data_tab = htab.

*----


then download file data

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = 'c:\t001.xls'

filetype = 'DAT'

append = 'X'

write_field_separator = 'X'

TABLES

data_tab = ptab.

ENDFORM. "mydownload