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: 

alv report( when click on execl button data downloading)

Former Member
0 Kudos

Hi,

I need a alv report when i execute this report its show the out put in alv display and when i click on the execl button its auto matically down load the data.

i already done a report which display alv grid then if i click the print overview button and then execl button its downloaded.

but i need a functinallity if i directly click on the execl button and data is down loaded.

pls help me regarding this, send me some coding for this.

Thanks

5 REPLIES 5

Former Member
0 Kudos

Hi Vipin,

Check the code. it will helps u.

REPORT zb_alvoops .

DATA gi_sflight TYPE STANDARD TABLE OF sflight.

DATA wa_sflight LIKE sflight.

DATA ok_code TYPE sy-ucomm.

DATA go_grid TYPE REF TO cl_gui_alv_grid.

DATA go_custom_container TYPE REF TO cl_gui_custom_container.

DATA : lt_fieldcat TYPE lvc_t_fcat,

ls_fieldcat LIKE LINE OF lt_fieldcat.

DATA ls_layout TYPE lvc_s_layo .

START-OF-SELECTION.

SET SCREEN '100'.

*----


  • MODULE STATUS_0100 OUTPUT

*----


MODULE status_0100 OUTPUT .

SET PF-STATUS 'ZB_MYMENU'.

SET TITLEBAR 'ZB_MYMENU'.

IF go_custom_container IS INITIAL.

CREATE OBJECT go_custom_container

EXPORTING container_name = 'ALV_CONTAINER'.

CREATE OBJECT go_grid

EXPORTING

i_parent = go_custom_container.

PERFORM load_data_into_grid.

PERFORM build_field_catalog.

PERFORM set_layout.

PERFORM display_data.

ENDIF.

ENDMODULE. "STATUS_0100 OUTPUT

*&----


*& Form load_data_into_grid

*&----


FORM load_data_into_grid.

SELECT * FROM zsflight INTO CORRESPONDING FIELDS OF TABLE gi_sflight.

ENDFORM. "load_data_into_grid

*----


  • MODULE USER_COMMAND_0100 INPUT

*----


MODULE user_command_0100 INPUT.

CASE ok_code.

WHEN 'EXIT'.

LEAVE TO SCREEN 0.

WHEN 'XLS'.

PERFORM export_to_excel.

ENDCASE.

ENDMODULE. "USER_COMMAND_0100 INPUT

*&----


*& Form display_data

*&----


FORM display_data.

CALL METHOD go_grid->set_table_for_first_display

EXPORTING

i_save = 'A'

i_default = 'X'

is_layout = ls_layout

CHANGING

it_outtab = gi_sflight

it_fieldcatalog = lt_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. "display_data

*&----


*& Form build_field_catalog

*&----


FORM build_field_catalog .

REFRESH lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'CARRID'.

ls_fieldcat-coltext = 'Airline Code '.

ls_fieldcat-key = 'X'.

APPEND ls_fieldcat TO lt_fieldcat.

ls_fieldcat-fieldname = 'CONNID'.

ls_fieldcat-coltext = 'Flight Connection Number'.

ls_fieldcat-key = 'X'.

APPEND ls_fieldcat TO lt_fieldcat.

ls_fieldcat-fieldname = 'FLDATE'.

ls_fieldcat-coltext = 'Flight Date'.

ls_fieldcat-key = 'X'.

APPEND ls_fieldcat TO lt_fieldcat.

ls_fieldcat-fieldname = 'PRICE'.

ls_fieldcat-coltext = 'Airfare'.

APPEND ls_fieldcat TO lt_fieldcat.

ENDFORM. "build_field_catalog

*&----


*& Form set_layout

*&----


FORM set_layout.

ls_layout-grid_title = text-001.

ls_layout-sel_mode = 'B'.

ls_layout-edit = ''.

ls_layout-info_fname = 'color'.

ls_layout-no_toolbar = 'X'.

ls_layout-info_fname = 'COLOR'.

ENDFORM. "set_layout

DATA BEGIN OF xmplt_v OCCURS 1.

INCLUDE STRUCTURE gxxlt_v.

DATA END OF xmplt_v.

DATA BEGIN OF xmplt_o OCCURS 1.

INCLUDE STRUCTURE gxxlt_o.

DATA END OF xmplt_o.

DATA BEGIN OF xmplt_p OCCURS 1.

INCLUDE STRUCTURE gxxlt_p.

DATA END OF xmplt_p.

DATA BEGIN OF xmplt_v1 OCCURS 1.

INCLUDE STRUCTURE gxxlt_v.

DATA END OF xmplt_v1.

DATA BEGIN OF xmplt_o1 OCCURS 1.

INCLUDE STRUCTURE gxxlt_o.

DATA END OF xmplt_o1.

DATA BEGIN OF xmplt_p1 OCCURS 1.

INCLUDE STRUCTURE gxxlt_p.

DATA END OF xmplt_p1.

*&----


*& Form export_to_excel

*&----


FORM export_to_excel .

DATA: lt_data TYPE REF TO data,

out_line TYPE REF TO data,

wa_fieldcat LIKE LINE OF lt_fieldcat,

l_objtab LIKE STANDARD TABLE OF ddfieldin,

wa_objtab LIKE LINE OF l_objtab,

ws_count(3) TYPE c VALUE '1',

wa_gxxltv TYPE gxxlt_v.

FIELD-SYMBOLS: <l_fieldcat> TYPE lvc_t_fcat,

<l_field> LIKE LINE OF <l_fieldcat>,

<lt_table> TYPE table,

<l_line> TYPE ANY,

<fs_xlsdata> LIKE LINE OF gi_sflight,

<fs_data1> TYPE ANY,

<fs_data2> TYPE ANY.

  • Get the frontend fieldcatalog

CALL METHOD go_grid->get_frontend_fieldcatalog

IMPORTING

et_fieldcatalog = lt_fieldcat.

DELETE lt_fieldcat WHERE no_out EQ 'X'.

*create dynamic table with the frontend fieldcatalog

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_fieldcat

IMPORTING

ep_table = lt_data

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc EQ 0.

ASSIGN lt_data->* TO <lt_table>.

ENDIF.

*create work area for the dynamic table

CREATE DATA out_line LIKE LINE OF <lt_table>.

ASSIGN out_line->* TO <l_line>.

LOOP AT lt_fieldcat ASSIGNING <l_field> WHERE no_out NE 'X'.

wa_objtab-tabname = 'V56I_DLNT_VIEW'.

wa_objtab-fieldname = <l_field>-fieldname.

APPEND wa_objtab TO l_objtab.

CALL FUNCTION 'DD_FIELDINFO_SET_GET'

EXPORTING

langu = sy-langu

TABLES

objinfo = l_objtab

EXCEPTIONS

internal_error = 1

OTHERS = 2.

IF sy-subrc EQ 0.

wa_gxxltv-col_no = ws_count.

wa_gxxltv-col_name = <l_field>-seltext.

APPEND wa_gxxltv TO xmplt_v1.

ADD 1 TO ws_count.

ENDIF.

ENDLOOP.

  • Fill the dynamic table

LOOP AT gi_sflight ASSIGNING <fs_xlsdata>.

LOOP AT lt_fieldcat INTO wa_fieldcat.

ASSIGN COMPONENT wa_fieldcat-fieldname OF STRUCTURE

<fs_xlsdata> TO <fs_data1>.

ASSIGN COMPONENT wa_fieldcat-fieldname OF STRUCTURE

<l_line> TO <fs_data2>.

MOVE <fs_data1> TO <fs_data2>.

ENDLOOP.

APPEND <l_line> TO <lt_table>.

ENDLOOP.

xmplt_o1-line_no = 1.

xmplt_o1-info_name = text-013.

APPEND xmplt_o1.

xmplt_p1-line_no = 1.

xmplt_p1-text = text-013.

APPEND xmplt_p1.

  • call to display the details in excel

CALL FUNCTION 'XXL_SIMPLE_API'

TABLES

col_text = xmplt_v1

data = <lt_table>

online_text = xmplt_o1

print_text = xmplt_p1

EXCEPTIONS

dim_mismatch_data = 1

file_open_error = 2

file_write_error = 3

inv_winsys = 4

inv_xxl = 5

OTHERS = 6.

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. " export_to_excel

Regards

Ravi

Former Member
0 Kudos

hi

good

XXL_SIMPLE_API

or

XXL_FULL_API

Using these function modules you can download the output data into xl sheet.

go throught these links which ll give you clear idea about these function modules

http://www.sap-img.com/abap/download-to-excel-with-format-border-color-cell-etc.htm

http://help.sap.com/printdocu/core/print46b/en/data/en/pdf/BCABA/BCABAXXL.pdf

thanks

mrutyun^

Former Member
0 Kudos

Hi Vipin,

I think you should find a Button with info text Spreadsheet or a button with info text Local file. from these button you can download data to excel.If these buttons are not available check whether you have copied the STANDARD status or not.

Regards,

Tanmay

SantoshKallem
Active Contributor
0 Kudos

go with DWDM tcode.

u can find examples for it

Former Member
0 Kudos

Hi Vipin,

Create a button in the pf-status for downloading.

Rest....follow the code...

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN 'DOWNL'.

CLEAR r_ucomm.

PERFORM sub_export_error.

ENDCASE.

ENDFORM. "user_command

FORM sub_export_error .

DATA: fullpath TYPE string,

filename TYPE string,

path TYPE string,

user_action TYPE i ,

l_title TYPE string.

  • encoding TYPE abap_encoding.

l_title = 'Save Error Data'(005).

  • Open the save dialog

CALL METHOD cl_gui_frontend_services=>file_save_dialog

EXPORTING

window_title = l_title

default_extension = 'XLS'

initial_directory = 'C:\'

CHANGING

filename = filename

path = path

fullpath = fullpath

user_action = user_action

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

not_supported_by_gui = 3

OTHERS = 4.

IF sy-subrc <> 0.

EXIT.

ENDIF.

  • Check which button is pressed

IF user_action <> cl_gui_frontend_services=>action_ok.

EXIT.

ENDIF.

  • Download error data collected from the internal table

CALL METHOD cl_gui_frontend_services=>gui_download

EXPORTING

filename = fullpath

filetype = 'ASC'

write_field_separator = '#'

codepage = '4103'

write_bom = c_true

CHANGING

data_tab = it_error

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

not_supported_by_gui = 22

error_no_gui = 23

OTHERS = 24.

  • If selection is successful

IF sy-subrc EQ 0.

MESSAGE s110 . " File & create successfully

ELSE.

MESSAGE i111 . " File is not create successfully

ENDIF.

ENDFORM. " sub_export_error

Reward is helpful,

Regards,

Tanmay