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: 

Downloading ALV REport

Former Member
0 Kudos

HI.

i need to download the alv report to a file which i given (either Text or Excel file ) and proper colomns and i need colomn headings also is it possible give me some sample code .

NOTE : i used ws_download but the coloumns r not coming in proper order .

so can any one pls help me regarding this ..........

THX

2 REPLIES 2

Former Member
0 Kudos

The FM ws_download is not obsolute. use GUI_DOWNLOAD instead. Pass the output table to the alv to the FM.

Former Member
0 Kudos

am sending a sample code for normal report.Plz check the below code that will solve ur problem.ok..

code:

&----


*& Report YITAB_XLS *

*& *

&----


*& DEVELOPER : KIRAN KUMAR.G.A *

*& PURPOSE : DOWNLOAD INTERNAL TABLE DATA TO XLS FILE *

*& CREATION DT : 31/12/2007 *

*& REQUEST : ERPK900035 *

&----


REPORT YITAB_XLS.

-


Internal Table

-


data: begin of gt_data occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

netpr like vbap-netpr,

end of gt_data.

-


Global Variables

-


data: t_vbeln type vbeln.

-


Global Structures

-


data: gv_file type string.

-


Selection Screen

-


selection-screen: begin of block b1 with frame title text-001.

parameters : p_file(90).

selection-screen: end of block b1.

selection-screen: begin of block b2 with frame title text-002.

select-options : s_vbeln for t_vbeln.

selection-screen: end of block b2.

*For Path Selection

at selection-screen on value-request for p_file.

perform path_directory.

*Initilization

initialization.

perform initial.

start-of-selection.

*Fetching data from the Database Table

perform fetch_data.

end-of-selection.

*Download Data to XLS file

perform download_data.

&----


*& Form initial

&----


text

-


--> p1 text

<-- p2 text

-


form initial .

s_vbeln-sign = 'I'.

s_vbeln-option = 'BT'.

s_vbeln-low = '4969'.

s_vbeln-high = '5000'.

append s_vbeln.

endform. " initial

&----


*& Form fetch_data

&----


text

-


--> p1 text

<-- p2 text

-


form fetch_data .

select vbeln

posnr

netpr

from vbap

into table gt_data

where vbeln in s_vbeln.

endform. " fetch_data

&----


*& Form path_directory

&----


text

-


--> p1 text

<-- p2 text

-


form path_directory .

CALL METHOD cl_gui_frontend_services=>directory_browse

EXPORTING

WINDOW_TITLE = 'SELECT THE PATH'

INITIAL_FOLDER = 'C:/'

CHANGING

selected_folder = gv_file

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

NOT_SUPPORTED_BY_GUI = 3

others = 4

.

IF sy-subrc 0.

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

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

ENDIF.

CALL METHOD cl_gui_cfw=>flush

EXCEPTIONS

CNTL_SYSTEM_ERROR = 1

CNTL_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.

p_file = gv_file.

endform. " path_directory

&----


*& Form download_data

&----


text

-


--> p1 text

<-- p2 text

-


form download_data .

gv_file = p_file.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE =

filename = gv_file

FILETYPE = 'ASC'

APPEND = ' '

WRITE_FIELD_SEPARATOR = '~'

HEADER = '00'

TRUNC_TRAILING_BLANKS = ' '

WRITE_LF = 'X'

COL_SELECT = ' '

COL_SELECT_MASK = ' '

DAT_MODE = ' '

IMPORTING

FILELENGTH =

tables

data_tab = gt_data

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.

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

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

ENDIF.

endform. " download_data