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: 

Generate and display excel file

jlsim
Explorer
0 Kudos

Hi guys,

Is there a way to generate and display excel file in sapgui without the need of downloading the excel file to local directory first?

I found the following 2 ways of doing it, but both require me to download the generated xls file to local directory:

#1 way:

1. Generate the xls file using GUI_DOWNLOAD with the filename = 'c:\test.xls'.

2. Call fm SAP_STARTS_EXCEL and pass in the parameter i_filename = 'c:\test.xls'

#2 way:

1. Generate the xls file using GUI_DOWNLOAD with the filename = 'c:\test.xls'.

2. Upload it back using the below so that i can get it in xstring format.

CALL FUNCTION 'GUI_UPLOAD'

exporting

filetype = 'BIN'

filename = 'C:\test.xls'

tables

data_tab = itab.

3. Then pass it to the cl_gui_html_viewer to display it.

call method html_control->load_data

exporting

url = 'test.xls'

type = 'application'

subtype = 'vnd.ms-excel'

importing

assigned_url = l_url

changing

data_table = l_pdf_data

exceptions

others = 1.

I prefer the #2 way as my program will get wrapped thru ITS server, and it seems the #1 way will not work. So is there any way i can get the excel file to be generated in xstring format so that i can pass to cl_gui_html_viewer straight away to display without having to save to local directory first?

Any other suggestion apart from the above 2 ways are welcome as well.

Thanks guys.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Use function module ALV_XXL_CALL. It will solve ur prob immediately.


 REPORT  ZSKC_ALV_XXL.

TYPE-POOLS : KKBLO.

DATA : ITAB LIKE T100 OCCURS 0,
       T_FCAT_LVC TYPE LVC_S_FCAT OCCURS 0 WITH HEADER LINE,
       T_FCAT_KKB TYPE KKBLO_T_FIELDCAT.


START-OF-SELECTION.

* Get data.
  SELECT * UP TO 20 ROWS
  FROM   T100
  INTO   TABLE ITAB
  WHERE  SPRSL = SY-LANGU.

  CHECK SY-SUBRC EQ 0.

* Create the field catalog.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
   EXPORTING
      I_STRUCTURE_NAME             = 'T100'
    CHANGING
      CT_FIELDCAT                  = T_FCAT_LVC[]
    EXCEPTIONS
      INCONSISTENT_INTERFACE       = 1
      PROGRAM_ERROR                = 2
      OTHERS                       = 3.

  CHECK SY-SUBRC EQ 0.
* make sure you pass the correct internal table name in the field catalog.
  t_fcat_lvC-tabname = 'ITAB'.
  MODIFY T_FCAT_LVC TRANSPORTING TABNAME WHERE TABNAME NE SPACE.

* Transfer to KKBLO format.
  CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'
    EXPORTING
      IT_FIELDCAT_LVC                 = T_FCAT_LVC[]
    IMPORTING
      ET_FIELDCAT_KKBLO               = T_FCAT_KKB
   EXCEPTIONS
     IT_DATA_MISSING                 = 1
     IT_FIELDCAT_LVC_MISSING         = 2
     OTHERS                          = 3.

  CHECK SY-SUBRC EQ 0.

* Call XXL.
  CALL FUNCTION 'ALV_XXL_CALL'
    EXPORTING
      I_TABNAME                    = 'ITAB'
      IT_FIELDCAT                  = T_FCAT_KKB
    TABLES
      IT_OUTTAB                    = ITAB[]
    EXCEPTIONS
      FATAL_ERROR                  = 1
      NO_DISPLAY_POSSIBLE          = 2
      OTHERS                       = 3.

  IF SY-SUBRC <> 0.
  ENDIF. 

It will open the Excel in front of you and populate the cells from your internal table

with color for Key columns.

Cheers

SKC.

2 REPLIES 2

Former Member
0 Kudos

Use function module ALV_XXL_CALL. It will solve ur prob immediately.


 REPORT  ZSKC_ALV_XXL.

TYPE-POOLS : KKBLO.

DATA : ITAB LIKE T100 OCCURS 0,
       T_FCAT_LVC TYPE LVC_S_FCAT OCCURS 0 WITH HEADER LINE,
       T_FCAT_KKB TYPE KKBLO_T_FIELDCAT.


START-OF-SELECTION.

* Get data.
  SELECT * UP TO 20 ROWS
  FROM   T100
  INTO   TABLE ITAB
  WHERE  SPRSL = SY-LANGU.

  CHECK SY-SUBRC EQ 0.

* Create the field catalog.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
   EXPORTING
      I_STRUCTURE_NAME             = 'T100'
    CHANGING
      CT_FIELDCAT                  = T_FCAT_LVC[]
    EXCEPTIONS
      INCONSISTENT_INTERFACE       = 1
      PROGRAM_ERROR                = 2
      OTHERS                       = 3.

  CHECK SY-SUBRC EQ 0.
* make sure you pass the correct internal table name in the field catalog.
  t_fcat_lvC-tabname = 'ITAB'.
  MODIFY T_FCAT_LVC TRANSPORTING TABNAME WHERE TABNAME NE SPACE.

* Transfer to KKBLO format.
  CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'
    EXPORTING
      IT_FIELDCAT_LVC                 = T_FCAT_LVC[]
    IMPORTING
      ET_FIELDCAT_KKBLO               = T_FCAT_KKB
   EXCEPTIONS
     IT_DATA_MISSING                 = 1
     IT_FIELDCAT_LVC_MISSING         = 2
     OTHERS                          = 3.

  CHECK SY-SUBRC EQ 0.

* Call XXL.
  CALL FUNCTION 'ALV_XXL_CALL'
    EXPORTING
      I_TABNAME                    = 'ITAB'
      IT_FIELDCAT                  = T_FCAT_KKB
    TABLES
      IT_OUTTAB                    = ITAB[]
    EXCEPTIONS
      FATAL_ERROR                  = 1
      NO_DISPLAY_POSSIBLE          = 2
      OTHERS                       = 3.

  IF SY-SUBRC <> 0.
  ENDIF. 

It will open the Excel in front of you and populate the cells from your internal table

with color for Key columns.

Cheers

SKC.

0 Kudos

Hi thanks for the suggestion. A good one but the problem is if i wrap it thru ITS server, it will have an exception NOT_SUPPORTED_BY_GUI thrown by CL_GUI_FRONTEND_SERVICES.

Any more ideas?