12-15-2009 1:07 PM
Hi Gurus,
My requirement is like i have a alv with 84 fields output, and in selection screen i have a alv variant.
i need to have a excel download button cheked in the selection screen and only those fields in variant need to be downloaded to excel sheet..
like if my variant has 20 fields then only those fields need to be downloded,.
what am thinking is to get the fields from that varinat and create a dynamic table fill it and download it but its geting too complicated in my report. any suggestions
Please help.
01-18-2010 7:06 PM
Hi,
No need of creating dynamic table if you are downloading to application server.
before calling alv grid do this
get the variant
get the fieldcatlog based on selected alv variant
if no_out is initial write that field to application server
you can apply the sort sequence too
see the sample code and hope this example clears your issues.
1 pass the variant and fieldcatlog(in both import and export)
CALL FUNCTION 'REUSE_ALV_VARIANT_SELECT'
EXPORTING
i_user_specific = g_x
it_default_fieldcat = g_fieldcat_tab[]
i_layout = g_layout
IMPORTING
et_fieldcat = g_fieldcat_tab[]
et_sort = g_sortfields_tab[]
et_filter = g_filter_tab[]
CHANGING
cs_variant = g_variant
EXCEPTIONS
wrong_input = 1
fc_not_complete = 2
not_found = 3
program_error = 4
OTHERS = 5.
2. apply layout sort sequence
LOOP AT g_sortfields_tab INTO ls_asort.
MOVE-CORRESPONDING ls_asort to ls_sort.
ls_sort-tabname = 'OBJECT_TAB'.
append ls_sort to lt_sort.
ENDLOOP.
CALL FUNCTION 'K_KKB_OUTTAB_SORT'
EXPORTING
it_sort = lt_sort
I_AS_TEXT = 'X'
* I_STABLE = 'X'
tables
t_outtab = object_tab
* EXCEPTIONS
* SORTFIELD_NOT_FOUND = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
ENDIF.
3 writing to application server
lt_fieldcat = pt_fieldcat.
DELETE lt_fieldcat WHERE no_out = 'X'.
LOOP AT object_tab.
CLEAR lv_text.
LOOP AT lt_fieldcat INTO ls_fieldcat.
CLEAR lv_field.
ASSIGN COMPONENT ls_fieldcat-fieldname OF STRUCTURE object_tab
TO <lf_field>.
IF <lf_field> IS NOT INITIAL.
WRITE <lf_field> TO lv_field.
ENDIF.
CONCATENATE lv_text lv_field INTO lv_text SEPARATED BY lc_tab.
ENDLOOP.
SHIFT lv_text LEFT BY 1 PLACES.
TRANSFER lv_text TO lv_apps.
ENDLOOP.
CLOSE DATASET lv_apps.
Regards,
Kishore
Moderator message - Please use code tags to format your code
Edited by: Rob Burbank on Jan 18, 2010 2:52 PM
12-15-2009 1:16 PM
Hi,
Downloading the data into excel is inbuild functionality of SAP but you want to get the fileds as per the varient. so i think you can check , is there any function module in SAP which will provide the fileds in Vairent.
Thanks.
12-15-2009 1:20 PM
Hi Imran,
u can do it through FM ''SAP_CONVERT_TO_XML_FORMAT" the TYPE-POOL is TRUX
here u hare to create a internal tablr abc which stores those data only which is checked. this logic u have to write in your alv output in user-command.
01-18-2010 7:06 PM
Hi,
No need of creating dynamic table if you are downloading to application server.
before calling alv grid do this
get the variant
get the fieldcatlog based on selected alv variant
if no_out is initial write that field to application server
you can apply the sort sequence too
see the sample code and hope this example clears your issues.
1 pass the variant and fieldcatlog(in both import and export)
CALL FUNCTION 'REUSE_ALV_VARIANT_SELECT'
EXPORTING
i_user_specific = g_x
it_default_fieldcat = g_fieldcat_tab[]
i_layout = g_layout
IMPORTING
et_fieldcat = g_fieldcat_tab[]
et_sort = g_sortfields_tab[]
et_filter = g_filter_tab[]
CHANGING
cs_variant = g_variant
EXCEPTIONS
wrong_input = 1
fc_not_complete = 2
not_found = 3
program_error = 4
OTHERS = 5.
2. apply layout sort sequence
LOOP AT g_sortfields_tab INTO ls_asort.
MOVE-CORRESPONDING ls_asort to ls_sort.
ls_sort-tabname = 'OBJECT_TAB'.
append ls_sort to lt_sort.
ENDLOOP.
CALL FUNCTION 'K_KKB_OUTTAB_SORT'
EXPORTING
it_sort = lt_sort
I_AS_TEXT = 'X'
* I_STABLE = 'X'
tables
t_outtab = object_tab
* EXCEPTIONS
* SORTFIELD_NOT_FOUND = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
ENDIF.
3 writing to application server
lt_fieldcat = pt_fieldcat.
DELETE lt_fieldcat WHERE no_out = 'X'.
LOOP AT object_tab.
CLEAR lv_text.
LOOP AT lt_fieldcat INTO ls_fieldcat.
CLEAR lv_field.
ASSIGN COMPONENT ls_fieldcat-fieldname OF STRUCTURE object_tab
TO <lf_field>.
IF <lf_field> IS NOT INITIAL.
WRITE <lf_field> TO lv_field.
ENDIF.
CONCATENATE lv_text lv_field INTO lv_text SEPARATED BY lc_tab.
ENDLOOP.
SHIFT lv_text LEFT BY 1 PLACES.
TRANSFER lv_text TO lv_apps.
ENDLOOP.
CLOSE DATASET lv_apps.
Regards,
Kishore
Moderator message - Please use code tags to format your code
Edited by: Rob Burbank on Jan 18, 2010 2:52 PM
01-18-2010 7:09 PM
And if you want to download to presentation server then you need to create dynamic table from fieldcatlog...
Kishore
01-18-2010 7:22 PM