‎2007 May 07 4:27 AM
HI Friends
We need to display 150 fields in ALV & Export all the fields into excel. We know that it's not possible using ALV Grid. To achieve the same using ALV Container (Class & Objects).
Please Tel Me
Advance thanks
ManiR
‎2007 May 07 4:37 AM
This sample program using container would help you.
Create a container in SE51->layout.
DATA: GI_SFLIGHT TYPE STANDARD TABLE OF SFLIGHT.
DATA: OK_CODE LIKE SY-UCOMM,
G_WA_SFLIGHT LIKE SFLIGHT.
Declare reference variables to the ALV grid and the container
DATA:
GO_GRID TYPE REF TO CL_GUI_ALV_GRID,
GO_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
START-OF-SELECTION.
CALL SCREEN '100'.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
IF GO_CUSTOM_CONTAINER IS INITIAL.
CREATE OBJECT GO_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = 'ALV_CONTAINER'.
CREATE OBJECT GO_GRID
EXPORTING
I_PARENT = GO_CUSTOM_CONTAINER.
PERFORM LOAD_DATA_INTO_GRID.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Form load_data_into_grid
&----
text
----
--> p1 text
<-- p2 text
----
FORM LOAD_DATA_INTO_GRID .
DATA:
For parameter IS_VARIANT
L_LAYOUT TYPE DISVARIANT,
GS_LAYOUT TYPE LVC_S_LAYO.
Load data into the grid and display them
L_LAYOUT-REPORT = SY-REPID.
GS_LAYOUT-GRID_TITLE = 'ZAMIT_FLIGHTS'.
GS_LAYOUT-SEL_MODE = 'A'.
SELECT *
FROM ZSFLIGHT
INTO TABLE GI_SFLIGHT.
CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
IS_LAYOUT = GS_LAYOUT
IS_VARIANT = L_LAYOUT
I_SAVE = 'A'
CHANGING
IT_OUTTAB = GI_SFLIGHT.
ENDFORM. " load_data_into_grid
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
MODULE USER_COMMAND_0100 INPUT.
DATA:
Internal table for indexes of selected rows
GI_INDEX_ROWS TYPE LVC_T_ROW,
L_LINES TYPE I,
Information about 1 row
G_SELECTED_ROW LIKE LVC_S_ROW.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'NL'.
CALL METHOD GO_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = GI_INDEX_ROWS.
DESCRIBE TABLE GI_INDEX_ROWS LINES L_LINES.
IF L_LINES = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
TEXTLINE1 =
'You must choose atleast one line to do the action'.
EXIT.
ENDIF.
LOOP AT GI_INDEX_ROWS INTO G_SELECTED_ROW.
G_SELECTED_ROW-INDEX = G_SELECTED_ROW-INDEX + 1.
MODIFY GI_INDEX_ROWS INDEX SY-TABIX FROM G_SELECTED_ROW
TRANSPORTING INDEX.
ENDLOOP.
LOOP AT GI_INDEX_ROWS INTO G_SELECTED_ROW.
*
READ TABLE GI_SFLIGHT INDEX G_SELECTED_ROW-INDEX INTO
G_WA_SFLIGHT.
ENDIF.
ENDLOOP.
DESCRIBE TABLE GI_INDEX_ROWS LINES L_LINES.
IF L_LINES > 0.
CALL METHOD GO_GRID->SET_SELECTED_ROWS
EXPORTING
IT_INDEX_ROWS = GI_INDEX_ROWS.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*reward points if useful
‎2007 May 07 4:51 AM
Hi Mani ,
After displaying in the records in ALV maintain a Button in Appilcation Toolbar , for Excel write a Subroutine for that there are below some function modules which can display in Excel sheet
hi
YOu can use the GUI_DOWNLOAD function module.
Once you have the data in the internal table, you can either display it as a report or download it to the excel sheet
If you only want to transfer the data to Excel like when you transfer the data from
ALV to Excel simply use the Function Modules:
XXL_SIMPLE_API
If you want more modifications when you transfer it to Excel use:
XXL_FULL_API
Often we face situations where we need to download internal table contents onto an Excel sheet. We are familiar with the function module WS_DOWNLOAD. Though this function module downloads the contents onto the Excel sheet, there cannot be any column headings or we cannot differentiate the primary keys just by seeing the Excel sheet.
For this purpose, we can use the function module XXL_FULL_API. The Excel sheet which is generated by this function module contains the column headings and the key columns are highlighted with a different color. Other options that are available with this function module are we can swap two columns or supress a field from displaying on the Excel sheet. The simple code for the usage of this function module is given below.
Program code : Run this code
-
REPORT Excel.
TABLES:
sflight.
header data................................
DATA :
header1 LIKE gxxlt_p-text VALUE 'Suresh',
header2 LIKE gxxlt_p-text VALUE 'Excel sheet'.
Internal table for holding the SFLIGHT data
DATA BEGIN OF t_sflight OCCURS 0.
INCLUDE STRUCTURE sflight.
DATA END OF t_sflight.
Internal table for holding the horizontal key.
DATA BEGIN OF t_hkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_h.
DATA END OF t_hkey .
Internal table for holding the vertical key.
DATA BEGIN OF t_vkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_v.
DATA END OF t_vkey .
Internal table for holding the online text....
DATA BEGIN OF t_online OCCURS 0.
INCLUDE STRUCTURE gxxlt_o.
DATA END OF t_online.
Internal table to hold print text.............
DATA BEGIN OF t_print OCCURS 0.
INCLUDE STRUCTURE gxxlt_p.
DATA END OF t_print.
Internal table to hold SEMA data..............
DATA BEGIN OF t_sema OCCURS 0.
INCLUDE STRUCTURE gxxlt_s.
DATA END OF t_sema.
Retreiving data from sflight.
SELECT * FROM sflight
INTO TABLE t_sflight.
Text which will be displayed online is declared here....
t_online-line_no = '1'.
t_online-info_name = 'Created by'.
t_online-info_value = 'KOTHUR SREEKANTH REDDY'.
APPEND t_online.
Text which will be printed out..........................
t_print-hf = 'H'.
t_print-lcr = 'L'.
t_print-line_no = '1'.
t_print-text = 'This is the header'.
APPEND t_print.
t_print-hf = 'F'.
t_print-lcr = 'C'.
t_print-line_no = '1'.
t_print-text = 'This is the footer'.
APPEND t_print.
Defining the vertical key columns.......
t_vkey-col_no = '1'.
t_vkey-col_name = 'MANDT'.
APPEND t_vkey.
t_vkey-col_no = '2'.
t_vkey-col_name = 'CARRID'.
APPEND t_vkey.
t_vkey-col_no = '3'.
t_vkey-col_name = 'CONNID'.
APPEND t_vkey.
t_vkey-col_no = '4'.
t_vkey-col_name = 'FLDATE'.
APPEND t_vkey.
Header text for the data columns................
t_hkey-row_no = '1'.
t_hkey-col_no = 1.
t_hkey-col_name = 'PRICE'.
APPEND t_hkey.
t_hkey-col_no = 2.
t_hkey-col_name = 'CURRENCY'.
APPEND t_hkey.
t_hkey-col_no = 3.
t_hkey-col_name = 'PLANETYPE'.
APPEND t_hkey.
t_hkey-col_no = 4.
t_hkey-col_name = 'SEATSMAX'.
APPEND t_hkey.
t_hkey-col_no = 5.
t_hkey-col_name = 'SEATSOCC'.
APPEND t_hkey.
t_hkey-col_no = 6.
t_hkey-col_name = 'PAYMENTSUM'.
APPEND t_hkey.
populating the SEMA data..........................
t_sema-col_no = 1.
t_sema-col_typ = 'STR'.
t_sema-col_ops = 'DFT'.
APPEND t_sema.
t_sema-col_no = 2.
APPEND t_sema.
t_sema-col_no = 3.
APPEND t_sema.
t_sema-col_no = 4.
APPEND t_sema.
t_sema-col_no = 5.
APPEND t_sema.
t_sema-col_no = 6.
APPEND t_sema.
t_sema-col_no = 7.
APPEND t_sema.
t_sema-col_no = 8.
APPEND t_sema.
t_sema-col_no = 9.
APPEND t_sema.
t_sema-col_no = 10.
t_sema-col_typ = 'NUM'.
t_sema-col_ops = 'ADD'.
APPEND t_sema.
CALL FUNCTION 'XXL_FULL_API'
EXPORTING
DATA_ENDING_AT = 54
DATA_STARTING_AT = 5
filename = 'TESTFILE'
header_1 = header1
header_2 = header2
no_dialog = 'X'
no_start = ' '
n_att_cols = 6
n_hrz_keys = 1
n_vrt_keys = 4
sema_type = 'X'
SO_TITLE = ' '
TABLES
data = t_sflight
hkey = t_hkey
online_text = t_online
print_text = t_print
sema = t_sema
vkey = t_vkey
EXCEPTIONS
cancelled_by_user = 1
data_too_big = 2
dim_mismatch_data = 3
dim_mismatch_sema = 4
dim_mismatch_vkey = 5
error_in_hkey = 6
error_in_sema = 7
file_open_error = 8
file_write_error = 9
inv_data_range = 10
inv_winsys = 11
inv_xxl = 12
OTHERS = 13
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
regsrds
navjot
reward if helpful
You can use this method to download the contents of an internal table to an excel file.
It is a static method of the class cl_gui_frontend_services. So you dont need an instance to call it.
Just make sure the file name has an extension .xls
call method cl_gui_frontend_services=>gui_download
exporting
filename = gv_file_name
filetype = lv_file_type
confirm_overwrite = space
changing
data_tab = <fs_download>
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
not_supported_by_gui = 22
error_no_gui = 23
others = 24.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
Hope this helps you.
Thanks & Regards
Bhaskar Rao.M
‎2007 May 07 4:56 AM
Refer the following code. The 'Download file' in the alv display download the alv into flat file. You can convert that flat file to excel or else insted of 'GUI_DOWNLOAD', you can use other functional module to download the internal table to excel file.
*&---------------------------------------------------------------------*
*& Report Z_82235_ALV_OOPS_PUSTBUTTON *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
report z_82235_alv_oops_pustbutton .
tables: mara.
types: begin of t_mara,
matnr type matnr,
mtart type mtart,
matkl type matkl,
meins type meins,
end of t_mara.
data: gt_mara type standard table of t_mara,
gs_mara like line of gt_mara.
class lcl_event_receiver definition deferred.
*-- Global Data defenation for ALV
*---Alv Grid instance referance
data : gr_alvgrid type ref to cl_gui_alv_grid,
event_receiver type ref to lcl_event_receiver.
*---Name of the custom control added on the screen
data gc_custom_control_name type scrfname value 'CC_ALV'
.
*---Custom container instance referance
data: gr_ccontainer type ref to cl_gui_custom_container.
*---Field catalog table
data: gt_fieldcat type lvc_t_fcat,
gs_fieldcat type lvc_s_fcat.
*---Layout structure
data: gs_layout type lvc_s_layo.
data: g_repid like sy-repid.
select matnr
mtart
matkl
meins
from mara into table gt_mara
up to 25 rows.
g_repid = sy-repid.
include <icon>.
*********
* Predefine a local class for event handling to allow the
* declaration of a reference variable before the class is defined.
*
*********
* Set initial dynpro
set screen 100.
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_event_receiver: local class to
* define and handle own functions.
*
* Definition:
* ~~~~~~~~~~~
class lcl_event_receiver definition.
public section.
methods:
handle_toolbar
for event toolbar of cl_gui_alv_grid
importing e_object e_interactive,
handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm.
private section.
endclass.
*
* lcl_event_receiver (Definition)
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class lcl_event_receiver (Implementation)
*
*
class lcl_event_receiver implementation.
method handle_toolbar.
* § 2.In event handler method for event TOOLBAR: Append own functions
* by using event parameter E_OBJECT.
data: ls_toolbar type stb_button.
*....................................................................
* E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET.
* This class has got one attribute, namly MT_TOOLBAR, which
* is a table of type TTB_BUTTON. One line of this table is
* defined by the Structure STB_BUTTON (see data deklaration above).
*
* A remark to the flag E_INTERACTIVE:
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 'e_interactive' is set, if this event is raised due to
* the call of 'set_toolbar_interactive' by the user.
* You can distinguish this way if the event was raised
* by yourself or by ALV
* (e.g. in method 'refresh_table_display').
* An application of this feature is still unknown... :-)
* append a separator to normal toolbar
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
* append an icon to download
clear ls_toolbar.
ls_toolbar-function = 'DOWN'.
ls_toolbar-icon = 'icon_generate'.
ls_toolbar-quickinfo = 'DOWNLOAD FILE'.
ls_toolbar-text = 'DOWNLOAD FILE'.
* MOVE ' ' TO ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endmethod.
*-------------------------------------------------------------------
method handle_user_command.
* § 3.In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
data: lt_rows type lvc_t_row.
case e_ucomm.
when 'DOWN'.
call function 'GUI_DOWNLOAD'
exporting
* BIN_FILESIZE =
filename = 'D:a.txt'
* FILETYPE = 'ASC'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
tables
data_tab = gt_mara
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.
endcase.
endmethod. "handle_user_command
*-----------------------------------------------------------------
endclass.
*
* lcl_event_receiver (Implementation)
*===================================================================
*--------------------------------------------------------------------
* S T A R T - O F - S E L E C T I O N.
*--------------------------------------------------------------------
start-of-selection.
set screen '100'.
*&---------------------------------------------------------------------*
*& Module display_alv OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module display_alv output.
if gr_alvgrid is initial.
*---Creating custom container instance
create object gr_ccontainer
exporting
container_name = gc_custom_control_name
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
*---Creating ALV gris instance
create object gr_alvgrid
exporting
i_parent = gr_ccontainer
i_appl_events = 'X'
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
*---Prepare field catalog
perform prepare_field_catalog tables gt_fieldcat.
*---Prepare layout
perform prepare_layout changing gs_layout.
*---Call ALV grid
call method gr_alvgrid->set_table_for_first_display
exporting
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
is_layout = gs_layout
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
changing
it_outtab = gt_mara[]
it_fieldcatalog = gt_fieldcat
* IT_SORT =
* IT_FILTER =
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 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.
********
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*
create object event_receiver.
set handler event_receiver->handle_user_command for gr_alvgrid.
set handler event_receiver->handle_toolbar for gr_alvgrid.
*
********
* § 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
call method gr_alvgrid->set_toolbar_interactive.
* endif. "IF grid1 IS INITIAL
* call method cl_gui_control=>set_focus exporting control = gr_alvgrid.
*--- the instance is present
else .
call method gr_alvgrid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
exceptions
finished = 1
others = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endif.
endmodule. " display_alv OUTPUT
*&---------------------------------------------------------------------*
*& Form prepare_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
form prepare_field_catalog tables gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MATNR'.
gs_fieldcat-col_pos = 1.
gs_fieldcat-emphasize = 'X'.
gs_fieldcat-outputlen = 10.
gs_fieldcat-coltext = 'Material No'.
gs_fieldcat-edit = 'X'.
append gs_fieldcat to gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MTART'.
gs_fieldcat-col_pos = 2.
gs_fieldcat-outputlen = 6.
gs_fieldcat-coltext = 'Material Type'.
append gs_fieldcat to gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MATKL'.
gs_fieldcat-col_pos = 3.
gs_fieldcat-outputlen = 5.
gs_fieldcat-coltext = 'Material Grp'.
append gs_fieldcat to gt_fieldcat.
clear : gs_fieldcat.
gs_fieldcat-fieldname = 'MEINS'.
gs_fieldcat-col_pos = 4.
gs_fieldcat-outputlen = 4.
gs_fieldcat-coltext = 'Unit'.
append gs_fieldcat to gt_fieldcat.
endform. " prepare_field_catalog
*&---------------------------------------------------------------------*
*& Form prepare_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_LAYOUT text
*----------------------------------------------------------------------*
form prepare_layout changing p_gs_layout type lvc_s_layo.
p_gs_layout-zebra = 'X'.
p_gs_layout-grid_title = 'Material'.
p_gs_layout-smalltitle = 'X'.
endform. " prepare_layout
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status 'STATUS1'.
* SET TITLEBAR 'xxx'.
endmodule. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0100 input.
case sy-ucomm.
when 'BACK' or 'UP' or 'CANCEL'.
leave program.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
‎2007 May 07 5:39 AM
Hi abhishek sarkar
Thanks for ur reply.... My problem is how to display 150 in Alv(Large)....
how to achieve this...
Please Reply me
ManiR