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

tableslfa1.

typesbegin of ty_lfa1,
       lifnr(10type c,
       name1(35type C,
       land1(2type c,
       end of ty_lfa1.


Datait_data type standard table of ty_lfa1.
datawa_data type ty_lfa1.
datav_filename type string,
      v_path     type string,
      v_fullpath type string,
      v_action   type I.
select-optionss_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

Popular posts from this blog

Add additional fields in VA05 report

Totals table for ACDOCA in S/4 HANA - ACDOCT

FAGLL03 / FBL1N / FBL3N / FBL5N not showing custom fields