Transfer internal table data into PC file using class CL_GUI_FRONTEND_SERVICES
Scenario: Need to tansfer internal table data into PC file or desktop file using class
CL_GUI_FRONTEND_SERVICES
in ABAP
Solution: check the code below
tables: lfa1.
types: begin of ty_lfa1,
lifnr(10) type c,
name1(35) type C,
land1(2) type c,
end of ty_lfa1.
Data: it_data type standard table of ty_lfa1.
data: wa_data type ty_lfa1.
data: v_filename type string,
v_path type string,
v_fullpath type string,
v_action type I.
select-options: s_lfa1 for lfa1-lifnr.
select lifnr name1 land1 from lfa1 into corresponding fields of table it_data where lifnr in s_lfa1.
** calling window to enter file name and path
call method CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
exporting
window_title = 'Testing GUI'
default_extension = 'txt'
default_file_name = 'Test file'
changing
filename = v_filename
path = v_path
fullpath = v_fullpath
user_action = v_action.
if v_action = 0.
** Downloading data into specified file.
call method CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
exporting
FILENAME = v_filename
changing
data_tab = it_data.
else.
write: 'No'.
endif.
Solution: check the code below
tables: lfa1.
types: begin of ty_lfa1,
lifnr(10) type c,
name1(35) type C,
land1(2) type c,
end of ty_lfa1.
Data: it_data type standard table of ty_lfa1.
data: wa_data type ty_lfa1.
data: v_filename type string,
v_path type string,
v_fullpath type string,
v_action type I.
select-options: s_lfa1 for lfa1-lifnr.
select lifnr name1 land1 from lfa1 into corresponding fields of table it_data where lifnr in s_lfa1.
** calling window to enter file name and path
call method CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
exporting
window_title = 'Testing GUI'
default_extension = 'txt'
default_file_name = 'Test file'
changing
filename = v_filename
path = v_path
fullpath = v_fullpath
user_action = v_action.
if v_action = 0.
** Downloading data into specified file.
call method CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
exporting
FILENAME = v_filename
changing
data_tab = it_data.
else.
write: 'No'.
endif.
Comments
Post a Comment