10-24-2007 11:51 AM
I have made one ALV report where i had created one button 'GENERATE'. ON CLICKING THIS BUTTON the data in the ALV report is downloaded to excel file.
i have used this:-
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 = gi_final
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 s004 . " File created successfully
ELSE.
MESSAGE i005 . " File is not created successfully
ENDIF.
In the table i have passed the internal table . this is working fine.
<b>But,
The problem is if i want to display the data in diferent layout based on selection screen criteria the data downloaded are same as default layout.
how to pass a dynamic internal table in the
CALL METHOD cl_gui_frontend_services=>gui_download</b>
10-24-2007 12:08 PM
Hi,
Use the method <b>cl_alv_table_create=>create_dynamic_table</b>
FIELD-SYMBOLS:
<dyn_table> TYPE STANDARD TABLE.
DATA:
lt_fdetails TYPE abap_compdescr_tab,
lt_tarfc TYPE lvc_t_fcat,
wa_fdetails TYPE abap_compdescr,
wa_tarfc TYPE lvc_s_fcat,
wa_dd04 TYPE dd04v,
dy_table TYPE REF TO data,
lp_ref_table_des TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
lp_ref_table_des ?=
cl_abap_typedescr=>describe_by_name('MARA').
lt_fdetails[] = lr_ref_table_des->components[].
* Making internal table compitable for Function module
LOOP AT lt_fdetails INTO wa_fdetails.
CLEAR wa_tarfc.
wa_tarfc-fieldname = wa_fdetails-name .
wa_tarfc-datatype = wa_fdetails-type_kind.
wa_tarfc-inttype = wa_fdetails-type_kind.
wa_tarfc-intlen = wa_fdetails-length.
wa_tarfc-decimals = wa_fdetails-decimals.
APPEND wa_tarfc TO lt_tarfc.
ENDLOOP.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_tarfc
IMPORTING
ep_table = dy_table.
Pass the constructed dynamic internal table (dy_table) to GUI_DOWNLOAD method.
Regards
Bhupal Reddy
Message was edited by:
Bhupal Reddy Vendidandi
10-25-2007 7:55 AM
Hi Bhupal,
if i paste the code in my program in is not detecting
abap_compdescr_tab
lvc_t_fcat
abap_compdescr
dd04v
cl_abap_structdescr
for that what i have to include in my program.
Thanks in Advance .
11-01-2007 4:17 AM
Hi Bhupal,
The type of the table dy_table is <b>ref to data</b> but the type of the table <b>data_tab</b> in method-->
<b>CALL METHOD cl_gui_frontend_services=>gui_download</b> is different. how the problem can be solved.
11-01-2007 12:31 PM
Hi Sandipan ,
The below code shows you how to create dynamic internal table using latest oo concepts like RTTS- Run Time Type Services. Then how to pass this table to ALV.
If any problem please get back to me.
REPORT sapbc401_dyns_RTTS_2.
DATA: ok_code LIKE sy-ucomm, popans.
DATA:
ref_docking TYPE REF TO cl_gui_docking_container,
ref_alv TYPE REF TO cl_gui_alv_grid.
DATA ref_itab TYPE REF TO data.
FIELD-SYMBOLS: <fs_itab> TYPE ANY TABLE.
DATA: r_linetype TYPE REF TO cl_abap_structdescr,
r_tabletype TYPE REF TO cl_abap_tabledescr,
key TYPE abap_keydescr_tab.
PARAMETERS pa_tab TYPE dd02l-tabname DEFAULT 'SPFLI'.
Continued on next page
370 © 2006 SAP AG. All rights reserved. 2006/Q2
BC401 Lesson: RTTS (Run Time Type Services)
START-OF-SELECTION.
*########################################################
*** create a tabletype with RTTC technique***************
*** call static method CREATE of specific RTTC-class ***
r_linetype ?= cl_abap_typedescr=>describe_by_name( pa_tab ).
r_tabletype = cl_abap_tabledescr=>create(
p_line_type = r_linetype ).
*** new technique with RTTC-type creation **************
*** dynamic creation of internal table data object ****
CREATE DATA ref_itab TYPE HANDLE r_tabletype.
* old technique without type creation ******************
* CREATE DATA ref_itab TYPE STANDARD TABLE OF (pa_tab)
* WITH NON-UNIQUE DEFAULT KEY.
ASSIGN ref_itab->* TO <fs_itab>
SELECT * FROM (pa_tab)
INTO TABLE <fs_itab>
UP TO 100 ROWS.
IF sy-subrc <> 0.
MESSAGE a702(bc401).
ENDIF.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module init_controls_0100 OUTPUT
*&---------------------------------------------------------------------*
* initialize controls
*----------------------------------------------------------------------*
MODULE init_controls_0100 OUTPUT.
IF ref_docking IS INITIAL.
CREATE OBJECT ref_docking
EXPORTING
* SIDE = DOCK_AT_LEFT
extension = 2000
EXCEPTIONS
OTHERS = 6
.
IF sy-subrc <> 0.
MESSAGE a015(rfw).
ENDIF.
CREATE OBJECT ref_alv
EXPORTING
i_parent = ref_docking
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5
.
IF sy-subrc <> 0.
MESSAGE a702(bc401).
ENDIF.
CALL METHOD ref_alv->set_table_for_first_display
EXPORTING
i_structure_name = pa_tab
Continued on next page
372 © 2006 SAP AG. All rights reserved. 2006/Q2
BC401 Lesson: RTTS (Run Time Type Services)
CHANGING
it_outtab = <fs_itab>
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE a702(bc401).
ENDIF.
ENDIF.
ENDMODULE. " init_controls_0100 OUTPUT
Reward points if useful,
Aleem.
11-02-2007 8:40 AM
Hi ,
here is the Program for Download
REPORT yrs_download_transport_request.
PARAMETERS:
p_reqest TYPE trkorr OBLIGATORY,
p_folder(255) TYPE c LOWER CASE, p_sepr OBLIGATORY.
DATA:
folder TYPE string,
retval LIKE TABLE OF ddshretval WITH HEADER LINE,
fldvalue LIKE help_info-fldvalue,
transdir TYPE text255,
filename(255),
trfile(20) TYPE c,
datatab TYPE TABLE OF text8192 WITH HEADER LINE,
len TYPE i,
flen TYPE i.
TYPE-POOLS: sabc, stms, trwbo.
INITIALIZATION.
CONCATENATE sy-sysid 'K*' INTO p_reqest.
IF sy-opsys = 'Windows NT'.
p_sepr = ''.
ELSE.
p_sepr = '/'.
ENDIF.
* CALL FUNCTION 'WSAF_BUILD_SEPARATOR'
* IMPORTING
* separator = p_sepr
* EXCEPTIONS
* separator_not_maintained = 1
* wrong_call = 2
* wsaf_config_not_maintained = 3
* OTHERS = 4.
*
* IF sy-subrc NE 0.
* MESSAGE s001(00)
* WITH
* 'Unable to find out the separator symbol for the system.'(011).
* ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_reqest.
DATA:
tt_system TYPE TABLE OF tmscsys WITH HEADER LINE,
es_selected_request TYPE trwbo_request_header,
es_selected_task TYPE trwbo_request_header,
iv_organizer_type TYPE trwbo_calling_organizer,
is_selection TYPE trwbo_selection.
iv_organizer_type = 'W'. is_selection-reqstatus = 'R'.
CALL FUNCTION 'TR_PRESENT_REQUESTS_SEL_POPUP'
EXPORTING
iv_organizer_type = iv_organizer_type
is_selection = is_selection
IMPORTING
es_selected_request = es_selected_request
es_selected_task = es_selected_task.
p_reqest = es_selected_request-trkorr.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder.
DATA: title TYPE string.
title = 'Select target folder'(005).
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = title
CHANGING
selected_folder = folder
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 3.
CALL FUNCTION 'CONTROL_FLUSH'
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2
OTHERS = 3.
p_folder = folder.
AT SELECTION-SCREEN ON p_reqest.
DATA: request_info TYPE stms_wbo_request,
request_infos TYPE stms_wbo_requests.
REFRESH request_infos.
CALL FUNCTION 'TMS_MGR_READ_TRANSPORT_REQUEST'
EXPORTING
iv_request = p_reqest
iv_header_only = 'X'
IMPORTING
et_request_infos = request_infos
EXCEPTIONS
read_config_failed = 1
table_of_requests_is_empty = 2
system_not_available = 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.
CLEAR request_info.
READ TABLE request_infos INTO request_info INDEX 1.
IF sy-subrc NE 0
OR request_info-e070-trkorr IS INITIAL.
MESSAGE e398(00) WITH 'Request'(006) p_reqest 'not found'(007).
ELSEIF request_info-e070-trstatus NE 'R'.
MESSAGE e398(00)
WITH 'You must release request'(008)
request_info-e070-trkorr
'before downloading'(009).
ENDIF.
START-OF-SELECTION.
folder = p_folder.
CONCATENATE p_reqest+3(7) '.' p_reqest(3) INTO trfile.
CALL FUNCTION 'RSPO_R_SAPGPARAM'
EXPORTING
name = 'DIR_TRANS'
IMPORTING
value = transdir
EXCEPTIONS
error = 0
OTHERS = 0.
PERFORM copy_file USING 'cofiles' trfile.
trfile(1) = 'R'.
PERFORM copy_file USING 'data' trfile.
trfile(1) = 'D'.
PERFORM copy_file USING 'data' trfile.
*---------------------------------------------------------------------*
* FORM copy_file *
*---------------------------------------------------------------------*
* --> SUBDIR * * --> FNAME *
*---------------------------------------------------------------------*
FORM copy_file USING subdir fname.
DATA:
auth_filename TYPE authb-filename,
gui_filename TYPE string.
CONCATENATE transdir subdir fname
INTO filename
SEPARATED BY p_sepr.
REFRESH datatab.
CLEAR flen.
auth_filename = filename.
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
activity = sabc_act_read
filename = auth_filename
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3.
IF sy-subrc <> 0.
FORMAT COLOR COL_NEGATIVE.
WRITE: / 'Read access denied. File'(001),
filename.
FORMAT COLOR OFF. EXIT.
ENDIF.
OPEN DATASET filename FOR INPUT IN BINARY MODE.
IF sy-subrc NE 0.
FORMAT COLOR COL_TOTAL.
WRITE: / 'File open error'(010), filename.
FORMAT COLOR OFF. EXIT.
ENDIF.
DO.
CLEAR len.
READ DATASET filename INTO datatab LENGTH len.
flen = flen + len.
IF len > 0. APPEND datatab. ENDIF.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET filename.
CONCATENATE p_folder '' fname INTO gui_filename.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = flen
filename = gui_filename
filetype = 'BIN'
CHANGING
data_tab = datatab[]
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 = 24.
IF sy-subrc = 0.
WRITE: / 'File'(002), filename, 'downloaded. Length'(003), flen.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE: / 'File download error. Filename:'(004), filename.
FORMAT COLOR OFF.
ENDIF.
ENDFORM. "copy_file
Reward points if it is usefull....
Girish