SAPHub

Download Specific Columns of Internal Table to SAP Presentation Server

To download only specific columns of internal table make use of COL_SELECT and COL_SELECT_MASK parameters of the function module GUI_DOWNLOAD’ or ‘GUI_DOWNLOAD’ method of ‘CL_GUI_FRONTEND_SERVICES’ class.

Parameter COL_SELECT activates column selection when it is set to ‘X’. Using the column selection, you can choose which columns are to be transmitted to the file.

Parameter COL_SELECT_MASK masks column selection. It is a character field up to 128 characters, consisting of SPACE and ‘X’. Each character stands for a column in the table. A SPACE stands for a column to be omitted; every other character stands for a column to be inserted.

Example: If COL_SELECT = ‘X’ and COL_SELECTMASK = ‘ X XX’, then Columns 2,4,5 are downloaded.

*---------------------------------------------------------------------*
* Data Declaration
*---------------------------------------------------------------------*
DATA: gt_spfli    TYPE TABLE OF spfli,
      gwa_spfli   TYPE spfli.
DATA: gv_filename TYPE string.
DATA: gv_mask     TYPE char255.
*---------------------------------------------------------------------*
* START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
*Specify the columns that you want to download
  gv_mask = ' X XX'.

*Fetch data from the database
  SELECT * FROM spfli INTO TABLE gt_spfli.

*Move complete file path to file name
  gv_filename = 'C:\test\data.txt'.

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      filename              = gv_filename
      filetype              = 'ASC'
      write_field_separator = 'X'
      col_select            = 'X'
      col_select_mask       = gv_mask
    CHANGING
      data_tab              = gt_spfli.

When you execute the above report program, it fetches all the data from SPFLI table and fills the internal table. But it downloads only second (CARRID), fourth (COUNTRYFR) and fifth (CITYFROM) columns of internal table to a file in SAP presentation server.