09-12-2007 11:38 AM
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.
09-12-2007 11:45 AM
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.
09-12-2007 11:45 AM
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.
09-13-2007 7:18 AM
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?