Skip to Content
0
Former Member
Jul 02, 2007 at 07:59 AM

Displaying header in excel horizontally using FM GUI_DOWNLOAD

25 Views

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