Application Development and Automation 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: 
Read only

Passing Internal table structure to EXCEL

Former Member
0 Likes
1,565

Hi All -

I want to pass the structure of internal table to EXCEL, not the records.

In other words, my requirement is to make an EXCEL sheet with several columns, which would be the fields of internal table. The order of all the columns should also be the same as the fields appear in Internal table.

Is there any standard FMs or something, by which I can do the same. Waiting for your reply. Thanks.

Vishal.

8 REPLIES 8
Read only

Former Member
0 Likes
1,193

hi

Try this function module FILE_READ_AND_CONVERT_SAP_DATA

pass XLS to I_FILEFORMAT

pass PRS to i_servertyp

hope this helps

regards

Aakash Banga

Read only

Former Member
0 Likes
1,193

Hi,

You just try this.hope it is useful.

When we try to upload excel files with macros to an internal table,

using FMs like ALSM_EXCEL_TO_INTERNAL_TABLE and KCD_EXCEL_OLE_TO_INT_CONVERT,

while executing the program it gives a popup to save that excel file , this blog explains to disable that popup

Regards,

Anki Reddy.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,193

Hello Vishal,

What is your requirement? Do you need column heading in addition to the records in the excelsheet?

You can add a column heading to the excel sheet through the FM 'GUI_DOWNLOAD'.


 TYPES:  BEGIN OF ty_xlhead,
         fld TYPE char40,         "For header name
         END OF ty_xlhead.

*1. Posting date
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-029.     "ÃŽnreg datu0103
  APPEND l_wa_xlhead TO fp_it_xlhead.

*2. Document type
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-030.     "Document tip
  APPEND l_wa_xlhead TO fp_it_xlhead.

*3. Document number
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-031.     "Document Nr
  APPEND l_wa_xlhead TO fp_it_xlhead.

*4. Document date
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-032.     "Document datu0103
  APPEND l_wa_xlhead TO fp_it_xlhead.

*5. Header text
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-018.     "Explicau0163ie
  APPEND l_wa_xlhead TO fp_it_xlhead.

*6. Account debit
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-033.     "Simbol cont Debitor
  APPEND l_wa_xlhead TO fp_it_xlhead.

*7. Credit account
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-034.     "Simbol cont Creditor
  APPEND l_wa_xlhead TO fp_it_xlhead.

*8. Debit amount
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-035.     " Sume Debitoare
  APPEND l_wa_xlhead TO fp_it_xlhead.

*9. Credit amount
  CLEAR l_wa_xlhead.
  l_wa_xlhead-fld  = text-036.     " Sume Creditoare
  APPEND l_wa_xlhead TO fp_it_xlhead.


      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = l_v_filename
          write_field_separator   = l_c_x
          dat_mode                = l_c_x
          confirm_overwrite       = l_c_x
        TABLES
          data_tab                = l_it_excel
          fieldnames              = fp_it_xlhead  "--> Excel Header
        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 i004.
*   File Download Failed
      ENDIF.

Is this what you need?

BR,

Suhas

Read only

Former Member
0 Likes
1,193

I want pass the Internal table fields (Not its records) to EXCEL. Not the records of Internal table, but just the structure of the Internal table.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,193

Hello Vishal,

Do you know the internal table structure or is it a dynamic table?

BR,

Suhas

Read only

rodrigo_paisante3
Active Contributor
0 Likes
1,193

Hi,

I supose that you know how to save to EXCEL file.

Loop your itab using field-symbol and use the DESCRIBE statement to get the field of itab. Then, you append it in other itab and create the EXCEL from this new itab.

Regards

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,193

Hello Vishal,

Do you know the internal table structure or is the table dynamic?

BR,

Suhas

Read only

Former Member
0 Likes
1,193

Hi,

In GUI_DOWNLOAD, Pass the below parameters. But Here, you need to pass the dummy internal table which is empty to DATA_TAB parameter.

I hope you can reach your requirement.

TABLES

data_tab = dummy_tab

fieldnames = it_header "--> Excel Header

Regards

Sandeep Reddy