Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Downloading internal table data into the excel file issue

Former Member
0 Kudos
1,262

Hello,

My requirement is to download the internal table data into the excel file but i have multiple lines in one column so i need multiple lines in one cell.

Example

Internal table data.

Col1 Col2

1 a

b

c

d

e

so my excel file should be in the same formate but for Col1 it should download '1' in one cell and for Col2 'a'

'b'

' '

' '

'c'

'd'

these col2 4lines should be only in one cell.

note: lines with blank space should also considered as one line but it all the col2 lines should be in one cell.

9 REPLIES 9

Former Member
0 Kudos
135

Hi,

Give col1 as 1 for all remaining lines also as

col1 col2

1 'a'

1 'b'

1 'c'

Hope this works

Former Member
0 Kudos
135

Hi Nilam,

Kindly go through this link below:

Hope it helps you

Regrds

Mansi

former_member223537
Active Contributor
0 Kudos
135

Hi Nilam,

One option could be using fm 'XXL_FULL_API'.

Please check sample program XXLFTEST in SE38.

Best regards,

Prashant

Former Member
0 Kudos
135

hi buddy..

u can func module GUI_DOWNLOAD for this purpose.

thank you

0 Kudos
135

Hello,

I know how to use the GUI_DOWNLOAD FM but my question is how u will insert

3 lines i.e 3 rows in one cell and u r saying me about the FM.

Former Member
0 Kudos
135

Hi,


   parameters:  p_err TYPE string OBLIGATORY

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
*   BIN_FILESIZE                    =
      filename                        = p_err
     filetype                        = 'DAT'
*   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                      = ' '
*   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*   SHOW_TRANSFER_STATUS            = ABAP_TRUE
* IMPORTING
*   FILELENGTH                      =
    TABLES
      data_tab                        = it_temp
*   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.

p_err pass the name of file with .XLS

Thanks

Arun Kayal

I355602
Advisor
Advisor
0 Kudos
135

Hi,

Try using this function module.

MS_EXCEL_OLE_STANDARD_DAT

Or you can also use demo code:-


data: it001 type table of t001 with header line.
 
select * into table it001 from t001.
 
call function 'GUI_DOWNLOAD'
     exporting
          filename              = 'C:test.xls'
          write_field_separator = 'X'
     tables
          data_tab              = it001.

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

awin_prabhu
Active Contributor
0 Kudos
135

Hi Nilam,

Try this simple code.

It takes some fields from mara table and fills the internal table.

Then the internal table is dowloaded to c: in excel format.

You can fill internal table manually also.

REPORT zawi_demodownload .

*Types

TYPES: BEGIN OF g_r_mara,

matnr LIKE mara-matnr,

ersda LIKE mara-ersda,

laeda LIKE mara-laeda,

mtart LIKE mara-mtart,

mbrsh LIKE mara-mbrsh,

END OF g_r_mara.

*Data

DATA: g_t_mara TYPE TABLE OF g_r_mara,

filename TYPE string,

s TYPE i.

*Tables

TABLES: mara, sscrfields.

*Selection Screen

SELECT-OPTIONS: s_matnr FOR mara-matnr.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN PUSHBUTTON 10(20) name USER-COMMAND ucom.

SELECTION-SCREEN END OF LINE.

INITIALIZATION.

name = 'Spread Sheet'.

AT SELECTION-SCREEN.

IF sscrfields-ucomm = 'UCOM'.

s = 1.

ENDIF.

*Data retrival and populating internal table

IF s = 1.

SELECT matnr ersda laeda mtart mbrsh

INTO CORRESPONDING FIELDS OF TABLE g_t_mara

FROM mara

WHERE matnr IN s_matnr.

filename = 'C:\Testing.xls'.

  • Downloading data from internal table to excel

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = filename

filetype = 'ASC'

write_field_separator = 'X'

TABLES

data_tab = g_t_mara.

ENDIF.

Thanks........

Former Member
0 Kudos
135

Hello Nilam,

I tried with the following example and it really worked.

The following report draws records from BKPF table and stores the same on Application Server. Further, it saves the whole information onto an excel-sheet.

Selection-screen seeks Application-server file-name and Presentation-server file-name as well.

It's just a soccer of internal tables.

REPORT  zahackson_app_excel NO STANDARD PAGE HEADING.

TYPE-POOLS truxs.

*---------------------------------------------------------------------*
* Structure for Accounting Information                                *
*---------------------------------------------------------------------*
TYPES:
  BEGIN OF type_s_bkpf,
    bukrs TYPE bkpf-bukrs,             " Company Code
    belnr TYPE bkpf-belnr,             " Accounting Document Number
    gjahr TYPE bkpf-gjahr,             " Fiscal Year
    blart TYPE bkpf-blart,             " Document Type
    bldat TYPE bkpf-bldat,             " Document date in document
  END OF type_s_bkpf.                  " BEGIN OF TYPE_S_BKPF

*---------------------------------------------------------------------*
* Field String for Accounting Information                             *
*---------------------------------------------------------------------*
DATA:
  fs_bkpf TYPE type_s_bkpf.

*---------------------------------------------------------------------*
* Internal Table For Accounting Information                           *
*---------------------------------------------------------------------*
DATA:
    t_bkpf LIKE
  STANDARD TABLE
        OF fs_bkpf.

*---------------------------------------------------------------------*
* Work Variables                                                      *
*---------------------------------------------------------------------*
DATA:
  w_filename TYPE string,              " Selected Filename
  w_filename1 TYPE rlgrap-filename,    " Selected Filename
  w_tab_raw_data TYPE truxs_t_text_data.
                                       " Raw Data

*---------------------------------------------------------------------*
*      INITIALIZATION                                                 *
*---------------------------------------------------------------------*
INITIALIZATION.
  PARAMETERS:
   p_filedw(128) VISIBLE LENGTH 15,    " File Name to be open
   p_file TYPE dxfields-longpath.      " Name of File to be saved

*---------------------------------------------------------------------*
*      TOP-OF-PAGE                                                    *
*---------------------------------------------------------------------*
TOP-OF-PAGE.
  FORMAT COLOR 4 INTENSIFIED ON.
  WRITE: 30(255) 'Downloaded Data'.
  WRITE:/5 'Company Code'(001),
        21 'Accounting Document Number'(003),
        52 'Fiscal Year'(004),
        67 'Document Type'(005),
        84(255) 'Document Date in Document'(006).
  FORMAT COLOR OFF.

*---------------------------------------------------------------------*
*      AT SELECTION-SCREEN ON VALUE-REQUEST                           *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM save_customer_file.
  CONCATENATE w_filename1 w_filename INTO p_file.

*---------------------------------------------------------------------*
*      START-OF-SELECTION                                             *
*---------------------------------------------------------------------*
START-OF-SELECTION.
  IF ( p_file IS INITIAL ) OR ( p_filedw IS INITIAL ).
    MESSAGE 'No File Selected' TYPE 'S' DISPLAY LIKE 'E'.
  ELSE.
    PERFORM open_file.
    PERFORM save_file.
  ENDIF.                               " IF ( P_FILE IS INITIAL )...

*&---------------------------------------------------------------------*
*&      Form  save_customer_file
*&---------------------------------------------------------------------*
* This Subroutine saves Customer File on the Presentation Server.
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM save_customer_file .
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
*  EXPORTING
*    WINDOW_TITLE         =
*    DEFAULT_EXTENSION    = ' '
*    DEFAULT_FILE_NAME    =
*    file_filter          = ' '
*    INITIAL_DIRECTORY    =
    CHANGING
      filename             = w_filename
      path                 = w_filename1
      fullpath             = w_filename1.
*    USER_ACTION          =
*  EXCEPTIONS
*    CNTL_ERROR           = 1
*    ERROR_NO_GUI         = 2
*    NOT_SUPPORTED_BY_GUI = 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.                               " IF SY-SUBRC <> 0
ENDFORM.                               " FORM SAVE_CUSTOMER_FILE

*&---------------------------------------------------------------------*
*&      Form  save_file
*&---------------------------------------------------------------------*
* This Subroutine facilitates download on Presentation Server.
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM save_file .

  CONCATENATE w_filename1 w_filename INTO w_filename1.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
     EXPORTING
*   I_FIELD_SEPERATOR =
*   I_LINE_HEADER  = 'X'
     I_TAB_RAW_DATA = w_tab_raw_data
     I_FILENAME     = w_filename1
    TABLES
     I_TAB_CONVERTED_DATA = t_bkpf
  EXCEPTIONS
    CONVERSION_FAILED = 1
    OTHERS            = 2.

  IF SY-SUBRC NE  0.
    MESSAGE ID SY-MSGID
            TYPE SY-MSGTY
            NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ELSE.
    LOOP AT t_bkpf INTO fs_bkpf.
      WRITE:/ fs_bkpf-bukrs under text-001,
              fs_bkpf-belnr under text-003,
              fs_bkpf-gjahr under text-004,
              fs_bkpf-blart under text-005,
              fs_bkpf-bldat under text-006.
    ENDLOOP.                           " LOOP AT T_BKPF INTO FS_BKPF
  ENDIF.                               " IF SY-SUBRC NE 0
ENDFORM.                               " FORM SAVE_FILE

*&---------------------------------------------------------------------*
*&      Form  open_file
*&---------------------------------------------------------------------*
* This Subroutine fetches data from the File saved on Application Server
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM open_file .
  OPEN DATASET p_filedw FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  DO.
    READ DATASET p_filedw INTO fs_bkpf.
    IF sy-subrc <> 0.
      EXIT.
    ELSE.
      APPEND fs_bkpf TO t_bkpf.
    ENDIF.                             " IF SY-SUBRC EQ 0
  ENDDO.                               " DO
  CLOSE DATASET p_filedw.
ENDFORM.                               " FORM OPEN_FILE

*----------------------------------------------------------------------*
*******************END OF PROGRAM***************************************
*----------------------------------------------------------------------*

Courtesy: Zahackson