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: 

Column headers to downloaded .xls file on Application server

Former Member
0 Kudos
228

Hi,

I'm downloading a file into Application server in .xls format, need to insert column headers.

Can you suggest me best way to do it.

Thanks,

Kiran Singh

5 REPLIES 5

SantoshKallem
Active Contributor
0 Kudos
82

Check this function module 'EXCEL_OLE_STANDARD_DAT'

0 Kudos
82

Hi Reddy,

The logic implemented here is to download the internal table data into application sever in .xls format. I guess if i can add column header data as a first record of internal table wil work but i'm not sure.

I'll send you the logic implemented in this program with in few minutes.

Thanks,

Kiran

0 Kudos
82

Can you pls check the code below.

*****************************************************

FORM file_transfer.

CLEAR: v_output.

v_output = x_output-vbeln. "First Rec w/o delimiter before

PERFORM out_line USING: x_output-posnr,

x_output-erdat,

x_output-ernam,

x_output-audat,

x_output-auart,

x_output-lifsk,

x_output-vkorg,

x_output-vdatu,

x_output-bstnk,

x_output-abstk,

x_output-lfgsk,

x_output-cmgst,

x_output-spstg,

x_output-gbstk,

x_output-statu_hdr,

x_output-kunwe,

x_output-name1_we,

x_output-land1_we,

x_output-pstlz_we,

x_output-regio_we,

x_output-name1_ag,

x_output-kdgrp,

x_output-inco1,

x_output-inco2,

x_output-bstkd,

x_output-matnr,

x_output-charg,

x_output-arktx,

x_output-pstyv,

x_output-abgru,

x_output-meins,

x_output-werks,

x_output-lgort,

x_output-vstel,

x_output-route.

CLEAR v_char.

WRITE x_output-netpr TO v_char CURRENCY x_output-waerk.

CONCATENATE v_output(*) v_char INTO v_output SEPARATED BY v_htab.

PERFORM out_line USING: x_output-waerk,

x_output-shkzg,

x_output-lfgsa,

x_output-gbsta,

x_output-statu_item,

x_output-etenr,

x_output-edatu,

x_output-wadat.

TRANSFER v_output(*) TO p_file.

ENDFORM. " file_transfer

&----


*& Form out_line

&----


FORM out_line USING l_field.

CONCATENATE v_output(*) l_field INTO v_output SEPARATED BY v_htab.

ENDFORM. " out_line

ferry_lianto
Active Contributor
0 Kudos
82

Hi,

You can manually insert the column names as the first row in your internal table to have them in .xls file as headers. Declare the column name as characters fields.

Regards,

Ferry Lianto

SantoshKallem
Active Contributor
0 Kudos
82

pass the header values to one internal table

and pass it to fields_table parameter in that function module

note: all those fields should be in charecter format.

example program.( this is just downloading the contents to excel in pc)

REPORT zsan_accdoc NO STANDARD PAGE HEADING LINE-SIZE 143.

----


  • TABLE DECLARATION

----


TABLES: bseg.

----


  • INTERNAL TABLE DECLARATION

----


DATA: BEGIN OF tab_gl OCCURS 0,

bukrs(4) TYPE C, "Company code

gjahr(4) TYPE C, "Fiscal Year

belnr(10) TYPE C, "Accounting Document Number

buzei(13) TYPE C, "Number of Line Item Within Accounting Document

koart(11) TYPE C, "Account Type

shkzg(11) TYPE C, "Debit/Credit Indicator

gsber(14) TYPE C, "Business Area

dmbtr like bseg-dmbtr, "Amount in Local Currency

kostl(10) TYPE C, "Cost Center

saknr(10) TYPE C, "G/L Account Number

hkont(10) TYPE C, "General Ledger Account

zlsch(11) TYPE C, "Payment Method

END OF tab_gl.

DATA: BEGIN OF tab_gl1 OCCURS 0,

belnr(10) TYPE C, "Accounting Document Number

buzei(13) TYPE C, "Number of Line Item Within Accounting Document

koart(11) TYPE C, "Account Type

shkzg(11) TYPE C, "Debit/Credit Indicator

gsber(14) TYPE C, "Business Area

dmbtr(20) TYPE c, "Amount in Local Currency

kostl(10) TYPE C, "Cost Center

saknr(10) TYPE C, "G/L Account Number

hkont(10) TYPE C, "General Ledger Account

zlsch(11) TYPE C, "Payment Method

END OF tab_gl1.

data: begin of tab_header occurs 0,

HEAD(12) TYPE C,

end of tab_header.

tab_header-HEAD = 'DOCNUM'.

APPEND tab_header.

tab_header-HEAD = 'LINE ITEM'.

APPEND tab_header.

tab_header-HEAD = 'ACC TYPE'.

APPEND tab_header.

tab_header-HEAD = 'INDI'.

APPEND tab_header.

tab_header-HEAD = 'BUSS AREA'.

APPEND tab_header.

TAB_HEADER-HEAD = 'AMOUNT'.

APPEND tab_header.

tab_header-HEAD = 'COST CENTER'.

APPEND tab_header.

tab_header-HEAD = 'G/LACC NO'.

APPEND tab_header.

tab_header-HEAD = 'G/L Account'.

APPEND tab_header.

tab_header-HEAD = 'PAY METHOD'.

APPEND tab_header.

----


  • SELECTION SCREEN

----


SELECT-OPTIONS: acc FOR bseg-belnr.

----


  • START OF SELECTION

----


START-OF-SELECTION.

SELECT bukrs

gjahr

belnr

buzei

koart

shkzg

gsber

dmbtr

kostl

saknr

hkont

zlsch

FROM bseg INTO CORRESPONDING FIELDS OF TABLE tab_gl

WHERE belnr IN acc.

----


  • END OF SELECTION

----


LOOP AT tab_gl.

IF tab_gl-zlsch = ''.

tab_gl-zlsch = '*****'.

MODIFY tab_gl.

ENDIF.

IF tab_gl-kostl = ''.

tab_gl-kostl = '*****'.

MODIFY tab_gl.

ENDIF.

IF tab_gl-gsber = ''.

tab_gl-gsber = '*****'.

MODIFY tab_gl.

ENDIF.

IF tab_gl-saknr = ''.

tab_gl-saknr = '*****'.

MODIFY tab_gl.

ENDIF.

ENDLOOP.

LOOP AT tab_gl.

tab_gl1-belnr = tab_gl-belnr.

tab_gl1-buzei = tab_gl-buzei.

tab_gl1-koart = tab_gl-koart.

tab_gl1-shkzg = tab_gl-shkzg.

tab_gl1-gsber = tab_gl-gsber.

tab_gl1-dmbtr = tab_gl-dmbtr.

tab_gl1-kostl = tab_gl-kostl.

tab_gl1-saknr = tab_gl-saknr.

tab_gl1-hkont = tab_gl-hkont.

tab_gl1-zlsch = tab_gl-zlsch.

APPEND tab_gl1.

ENDLOOP.

SORT tab_gl BY belnr bukrs gjahr .

LOOP AT tab_gl.

WRITE: sy-uline.

AT NEW gjahr.

PERFORM header.

ENDAT.

FORMAT COLOR OFF.

WRITE:/ sy-vline, tab_gl-belnr COLOR 1, sy-vline,

(10) tab_gl-buzei CENTERED, sy-vline,

(10) tab_gl-koart CENTERED, sy-vline,

(10) tab_gl-shkzg CENTERED, sy-vline,

(11) tab_gl-gsber CENTERED, sy-vline,

(16) tab_gl-dmbtr RIGHT-JUSTIFIED, sy-vline,

(12) tab_gl-kostl CENTERED, sy-vline,

(11) tab_gl-saknr CENTERED, sy-vline,

(11) tab_gl-hkont CENTERED, sy-vline,

(11) tab_gl-zlsch CENTERED, sy-vline.

ENDLOOP.

  • ---------------------------------------------------------------------

  • FOR DOWNLOADING TO EXCEL

----


SET PF-STATUS 'ZEXCEL'.

AT USER-COMMAND.

CASE sy-ucomm.

WHEN 'DOWN'.

CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'

EXPORTING

file_name = 'C:\SANNN.DAT'

TABLES

DATA_TAB = TAB_GL1[]

FIELDNAMES = TAB_HEADER[].

ENDIF.

ENDCASE.

----


  • TOP OF PAGE

----


TOP-OF-PAGE.

&----


*& Form header

&----


  • text

----


FORM header.

FORMAT COLOR 6 INVERSE ON.

SKIP 2.

FORMAT COLOR 6 INVERSE OFF.

FORMAT COLOR 4 INVERSE ON.

WRITE:/ 'COMPANY CODE:', tab_gl-bukrs,

88 'FISCAL YEAR:', tab_gl-gjahr.

FORMAT COLOR 4 INVERSE OFF.

ULINE.

LOOP AT tab_header.

write: tab_header.

ENDLOOP.

ULINE.

ENDFORM. "header

check this tcodes..

<b>

Tcode - CG3Y program-RC1TCG3Y to Download file

Tcode - CG3Z program- RC1TCG3Z to Upload file

Tcode- SXDX

</b>

reward if useful

regards.

santhosh

Message was edited by:

santhosh reddy