Skip to Content
avatar image
Former Member

Req:How to set headings in XL sheet

Hi gurus,

when we are downloading the internal table into XL sheet how to put headings in the top of Excel sheet from the program itself.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 16, 2008 at 11:27 AM

    Hi,

    Check this sample code. I've called FM GUI_DOWNLOAD twice. Once to download the heading of internal table data. and another time to download internal table data itself. While downloading data of internal table make sure path for your heading and data is same and second time APPEND parameter of function module should be active.

    APPEND = 'X'.
    
    REPORT  z_file_download.
    DATA: w_name(90) TYPE c.
    DATA:
      BEGIN OF fs_flight,
        carrid   LIKE sflight-carrid,
        connid   LIKE sflight-connid,
        fldate   LIKE sflight-fldate,
        price    LIKE sflight-price,
        currency LIKE sflight-currency,
      END OF fs_flight.
    DATA:
      BEGIN OF fs_head,
        carrid(10) TYPE c,
        connid(10) TYPE c,
        fldate(10) TYPE c,
        price(10) TYPE c,
        curr(10) TYPE c,
      END OF fs_head.
    DATA:
      t_head LIKE
       TABLE OF
             fs_head.
    DATA:
      t_flight LIKE
         TABLE OF
               fs_flight.
    
    fs_head-carrid = 'CARRID'.
    fs_head-connid = 'CONNID'.
    fs_head-fldate = 'FLDATE'.
    fs_head-price  = 'PRICE'.
    fs_head-curr   = 'CURRENCY'.
    APPEND fs_head TO t_head.
    SELECT-OPTIONS:
      s_carrid FOR fs_flight-carrid.
    
    
    
    START-OF-SELECTION.
      SELECT carrid
             connid
             fldate
             price
             currency
        FROM sflight
        INTO TABLE t_flight
       WHERE carrid IN s_carrid.
    
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
    *   BIN_FILESIZE                  =
        filename                      = 'D:\flight.xls'
       FILETYPE                      = 'ASC'
    *   APPEND                        = ' '
        WRITE_FIELD_SEPARATOR         = 'X'
    *   HEADER                        = '00'
    *   TRUNC_TRAILING_BLANKS         = ' '
    *   WRITE_LF                      = 'X'
    *   COL_SELECT                    = ' '
    *   COL_SELECT_MASK               = ' '
    *   DAT_MODE                      = ' '
    *   CONFIRM_OVERWRITE             = ' '
    *   NO_AUTH_CHECK                 = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    *   WRITE_BOM                     = ' '
    * IMPORTING
    *   FILELENGTH                    =
      tables
        data_tab                      = t_head
     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                        = 22
              .
    IF sy-subrc NE 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    
    
    
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = 'D:\flight.xls'
          filetype                = 'ASC'
          append                  = 'X'
          write_field_separator   = 'X'
        TABLES
          data_tab                = t_flight
        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                  = 22.
      IF sy-subrc EQ 0.
        MESSAGE 'Download successful' TYPE 'I'.
      ELSE.
    *  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    

    Regards

    Abhijeet

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 11:15 AM

    Hi

    You have to populate the TABLES parameter "FIELDNAMES" in the function module GUI_DOWNLOAD.

    Regards

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi

      Parameter "FIELDNAMES" is present under the "Tables" tab in function module GUI_DOWNLOAD

      TABLES
          DATA_TAB                        = IT_MARA
          FIELDNAMES                      = IT_FIELDNAMES

      Adding the sample code below.

      TYPES : BEGIN OF TY_MARA,
              MATNR TYPE MARA-MATNR,
              BRGEW TYPE MARA-BRGEW, "Gross Weight
              END OF TY_MARA.
      
      DATA : IT_MARA       TYPE TABLE OF TY_MARA,
             WA_MARA       TYPE TY_MARA,
             IT_MARA_COLL  TYPE TABLE OF TY_MARA.
      
      DATA : GR_TABLE TYPE REF TO CL_SALV_TABLE.
      
      SELECT MATNR
             BRGEW
      FROM MARA
      INTO TABLE IT_MARA UP TO 500 ROWS.
      
      DATA : BEGIN OF IT_FIELDNAMES OCCURS 0,
             NAME(256) TYPE c,
             END OF IT_FIELDNAMES.
      
      IT_FIELDNAMES-NAME = 'Material No'.
      APPEND IT_FIELDNAMES.
      IT_FIELDNAMES-NAME = 'Gross Weight'.
      APPEND IT_FIELDNAMES.
      
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
      *   BIN_FILESIZE                    =
          FILENAME                        = 'C:\Documents and Settings\sap\Desktop\Hi.xls'
      *   FILETYPE                        = 'ASC'
      *   APPEND                          = ' '
      *   WRITE_FIELD_SEPARATOR           = ' '
      *   HEADER                          = '00'
      *   TRUNC_TRAILING_BLANKS           = ' '
      *   WRITE_LF                        = 'X'
      *   COL_SELECT                      = ' '
      *   COL_SELECT_MASK                 = ' '
      *   DAT_MODE                        = ' '
      *   CONFIRM_OVERWRITE               = ' '
      *   NO_AUTH_CHECK                   = ' '
      *   CODEPAGE                        = ' '
      *   IGNORE_CERR                     = ABAP_TRUE
      *   REPLACEMENT                     = '#'
      *   WRITE_BOM                       = ' '
      *   TRUNC_TRAILING_BLANKS_EOL       = 'X'
      *   WK1_N_FORMAT                    = ' '
      *   WK1_N_SIZE                      = ' '
      *   WK1_T_FORMAT                    = ' '
      *   WK1_T_SIZE                      = ' '
      * IMPORTING
      *   FILELENGTH                      =
        TABLES
          DATA_TAB                        = IT_MARA
          FIELDNAMES                      = IT_FIELDNAMES
      * 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                          = 22
                .
      IF SY-SUBRC <> 0.
      * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
      *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

      Regards

      Edited by: Rajvansh Ravi on Oct 16, 2008 1:29 PM

      Edited by: Rajvansh Ravi on Oct 16, 2008 1:56 PM

  • avatar image
    Former Member
    Oct 16, 2008 at 11:24 AM
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 16, 2008 at 11:25 AM

    Hi,

    create an internal table with enough number of columns of type c. first insert the headers into this internal table then move the data from your internal table which contains data to be downloaded to excel to this new table. then download this internal table to excel. you will have the headers at the first line. just be careful when giving size to the columns, it should be enough for the max size of the columns of your original internal table.

    regards,

    Murat Kaya

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 11:37 AM

    hi radhika ,

    On which version your working .

    This 'FIELDNAME ' is given after 4.7

    Even not in 4.7 .

    Regards,

    Sandeep

    Add comment
    10|10000 characters needed characters exceeded