06-01-2007 1:04 PM
Hi,
I am stuck with a problem. I need to display an internal table using ALV and then download that ALV to Excel by triggering a button. While downloading to Excel, the report is split into two seperate file with four values changing in the second file, the fields remain the same only the values change.
Can anyone please help.
Thanks,
Rosh
06-01-2007 1:08 PM
try to do diffrent way ,
click on local file and then give ur xl path.
06-01-2007 1:09 PM
06-01-2007 1:12 PM
Step 1: Display the internal table as ALV
Step 2: Trigger download to Excel by clicking a button, splitting the output file into two. One has the standard data display in the ALV output and the second one has the same structure only that four values have changed
06-01-2007 1:21 PM
&----
*& Form output_in_alv
&----
text
----
--> p1 text
<-- p2 text
----
FORM output_in_alv.
****
We use this form whenever
we want to display something
in ALV.
Take this for granted,
don't really try to understand
what it is actually doing.
The thing you have to do is
to change some of the
follwing lines.
I marked this lines the
comment " need to be changed "
****
Data for ALV grid...
DATA: w_repid LIKE sy-repid,
my_layout TYPE slis_layout_alv,
g_save TYPE c VALUE 'X', "Use all ALV variant types
it_fieldcatalog TYPE slis_t_fieldcat_alv,
wa_fieldcatalog LIKE LINE OF it_fieldcatalog,
it_sort TYPE slis_t_sortinfo_alv,
wa_sort LIKE LINE OF it_sort.
w_repid = sy-repid.
my_layout-cell_merge = 'X'.
my_layout-zebra = 'X'.
****
The follwing function module determine
what fields are to be shown on screen
Here you should change only the internal table
name that is to be output.
Care to put the name in CAPITAL.
****
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = w_repid
i_internal_tabname = 'I_MOVES' " need to be changed
I_STRUCTURE_NAME =
i_inclname = w_repid
CHANGING
ct_fieldcat = it_fieldcatalog
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
****
The follwing lines determine
the fields on which the output
will be sorted
You should change the field name
and the sort priority.
If you wish to add another field
just copy the lines between
the clear and the append statement
and simply change the field name
and the sort priority
****
CLEAR wa_sort.
wa_sort-fieldname = 'MATNR'. " need to be changed
wa_sort-spos = 1. " need to be changed
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'WERKS'. " need to be changed
wa_sort-spos = 2. " need to be changed
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'LGORT'.
wa_sort-spos = 3.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort.
****
The follwing lines determine
which fields will become sum.
You only change here the field
name (in CAPITAL).
If you wish to add another field
just copy the lines between
the if and the endif and simply
change the field name.
****
LOOP AT it_fieldcatalog INTO wa_fieldcatalog.
IF wa_fieldcatalog-fieldname = 'MENGE'. " need to be changed
wa_fieldcatalog-do_sum = 'X'.
MODIFY it_fieldcatalog FROM wa_fieldcatalog.
ENDIF.
ENDLOOP.
loop at it_fieldcatalog into wa_fieldcatalog.
if wa_fieldcatalog-fieldname = 'UDATE_D'.
wa_fieldcatalog-seltext_s = wa_fieldcatalog-seltext_m =
wa_fieldcatalog-seltext_l = 'imerominia_d_egrisis'.
wa_fieldcatalog-ddictxt = 'L'.
modify it_fieldcatalog from wa_fieldcatalog.
endif.
endloop.
****
The follwing function module
outputs the ALV with the parameters
have previously defined.
Here you should only change the
name of the internal table
that is to be output
****
ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
****
Caution!!!!!!
Use this line only if you want to
show the save button on your screen.
i_callback_pf_status_set = 'PF_STATUS_SET'
****
i_callback_user_command = 'LINE_CLICK'
i_callback_top_of_page = 'TOP_ROUTINE'
i_grid_title = text-h01
is_layout = my_layout
it_fieldcat = it_fieldcatalog
it_sort = it_sort
i_save = g_save
is_variant = lh_variant
TABLES
t_outtab = i_moves " need to be changed
EXCEPTIONS
program_error = 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.
ENDFORM. " output_in_alv
&----
*& Form top_routine
&----
text
----
--> p1 text
<-- p2 text
----
FORM top_routine.
****
In this form we define what will
be output on top.
You should only change the marked
lines with what will be
actually output
****
{ Local
DATA:
l_line TYPE slis_entry,
lh_top TYPE slis_listheader,
lt_top TYPE slis_t_listheader.
}
DEFINE top_line.
clear lh_top.
lh_top-typ = &1.
lh_top-key = &2.
lh_top-info = &3.
append lh_top to lt_top.
END-OF-DEFINITION.
WRITE sy-datum TO l_line. " need to be changed
top_line 'S' 'Date:' l_line. " need to be changed
WRITE sy-uname TO l_line. " need to be changed
top_line 'S' 'User:' l_line. " need to be changed
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_top.
ENDFORM. " top_routine
&----
*& Form LINE_CLICK
&----
text
----
--> p1 text
<-- p2 text
----
FORM line_click USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
****
In this form we define what will
happen if the user double clicks
on a field or presses save on toolbar
The event '&IC1' is reserved
for the double click event
The event 'SAVE' is triggered
on save button press.
****
CASE r_ucomm.
WHEN '&IC1'.
****
We call a transaction using
the value of the clicked field.
****
IF rs_selfield-fieldname = 'MATNR'. " need to be changed
SET PARAMETER ID 'MAT' FIELD rs_selfield-value. " need to be changed
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN. " need to be changed
ENDIF.
WHEN 'SAVE'.
PERFORM save.
ENDCASE.
ENDFORM. " LINE_CLICK
&----
*& Form PF_STATUS_SET
&----
text
----
--> p1 text
<-- p2 text
----
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
****
Caution!!!!!!
Use this Form only if you want to
show the save button on your screen.
**
In this form we define the
pf status of the screen
Go to transaction 'SE41' and
copy the status STANDARD_FULLSCREEN
of the program SAPLKKBL
status STATUS_0100 of
your program.
The double click on the 'STATUS_0100'
of the following line and
change the field &DATA_SAVE on the
fuction keys and put
name SAVE there.
Save and activate the status
and click back
****
SET PF-STATUS 'STATUS_0100'.
ENDFORM. " LINE_CLICK
<b>reward if its helpful </b>