2025 Jan 06 3:50 PM
HI All,
I have a requirement of enabling the URL as hyperlink when i download the ALV output to an excel file (.xlsx).
Currently, the URL column in the downloaded excel file is displayed as a text and not a hyperlink. Character:(') is getting added to the cell value as it is beginning with "=hyperlink.....".
I tried changing the field of the URL type from CHAR to SERVICE_RL, but it does not work.
Basically whenever the user download the ALV into excel, he should be able to open the URL by clicking on it.
Please let me know how can this be made feasible.
Thanks,
Ram
2025 Jan 06 5:08 PM
You didn't explain anything about your code, so I can only advise using abap2xlsx.
2025 Jan 06 7:26 PM - edited 2025 Jan 06 7:26 PM
Hi Sandra, ThankYou so much for responding to my query..... really appreciate it!
Giving You the code snippet:
REPORT ztest_excel_hyperlink.
TYPES: BEGIN OF ty_s_cline,
line TYPE C LENGTH 1024, " Line of type Character
END OF ty_s_cline .
DATA : ls_fc TYPE lvc_s_fcat,
lt_fc TYPE lvc_t_fcat.
DATA : dtab TYPE REF TO data.
DATA: gr_table TYPE REF TO cl_salv_table.
DATA: lr_functions TYPE REF TO cl_salv_functions_list,
lr_layout TYPE REF TO cl_salv_layout,
lv_xml_type TYPE salv_bs_constant,
lv_xml TYPE xstring.
DATA : ls_key TYPE salv_s_layout_key.
DATA : lr_content TYPE REF TO cl_salv_form_element.
DATA : lt_srctab TYPE STANDARD TABLE OF ty_s_cline.
DATA : gt_len TYPE i.
DATA : lv_file_xlsx TYPE string VALUE 'C:\Downloads\test_link.xlsx'.
FIELD-SYMBOLS : <fs_tab> type STANDARD TABLE.
ls_fc-fieldname = 'LINK'.
ls_fc-datatype = 'STRG'.
ls_fc-inttype = 'g'.
ls_fc-intlen = '00000'.
ls_fc-decimals = '000000'.
ls_fc-scrtext_l = ls_fc-scrtext_m = ls_fc-scrtext_s = 'Link'.
Append ls_fc to lt_fc.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fc
IMPORTING
ep_table = dtab.
ASSIGN dtab->* TO <fs_tab>.
APPEND INITIAL LINE TO <fs_tab> ASSIGNING FIELD-SYMBOL(<fs_line>).
ASSIGN COMPONENT 'LINK ' OF STRUCTURE <fs_line> to FIELD-SYMBOL(<fs_cell>).
Move '=HYPERLINK("WWW.GOOGLE.COM","LINK")' to <fs_cell>.
CONDENSE <fs_cell>.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = <fs_tab> ).
lr_functions = gr_table->get_functions( ).
lr_functions->set_all( abap_true ).
lr_layout = gr_table->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_save_restriction( if_salv_c_layout=>restrict_user_independant ).
gr_table->set_top_of_list( lr_content ).
gr_table->set_end_of_list( lr_content ).
* gr_table->display( ).
lv_xml_type = if_salv_bs_xml=>c_type_xlsx.
lv_xml = gr_table->to_xml( xml_type = lv_xml_type ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xml
* APPEND_TO_TABLE = ' '
IMPORTING
output_length = gt_len
TABLES
binary_tab = lt_srctab.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = gt_len
filename = lv_file_xlsx
filetype = 'BIN'
CHANGING
data_tab = lt_srctab
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.
ENDIF.
2025 Jan 06 8:02 PM
Thanks Sandra for replying to this .. Attached is the snippet
2025 Jan 07 9:41 AM - edited 2025 Jan 07 9:45 AM
You did define the field as a text field, did you look at a demo report such as SALV_TEST_HYPE_REFRESH
2025 Jan 07 10:49 AM
Hi Raymond, thanks so much for checking this post...
I have gone through SALV_TEST_HYPE_REFRESH where there are coding like: building handler with salv_de_hyperlink_handle or set_cell_type( if_salv_c_cell_type=>link ) and set_hyperlink_entry() .. but those work on-screen and handling navigation on GUI screen. I do not see anything for excel file download. Please advise...
Thanks Ram
I did try with the set_cell_type( if_salv_c_cell_type=>link ) but it has no effect.
2025 Jan 07 1:29 PM - edited 2025 Jan 07 2:54 PM
2025 Jan 07 12:20 PM
With SALV, there is no built-in feature to define a HTTP hyperlink cell: with an ALV hotspot cell, you also need ABAP code to open the Web page via an event handler, TO_XML can't know that and can never generate a hyperlink cell in the Excel file. Also, as far as I know, TO_XML never interprets cell contents as formulas, they are formatted as raw texts or numbers.
NB: don't use the method "cl_alv_table_create=>create_dynamic_table" which is not released, also it's based on GENERATE SUBROUTINE POOL, which is slow and does a runtime error after 36 repeated calls, instead use the Z alternative here (based on released RTTS, which is fast and doesn't fail): Alternative to CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC... - SAP Community.
2025 Jan 08 11:41 AM
Thanks Sandra & Raymond for your time and effort to solve this problem... Your inputs were of great value for me to proceed.
I turned to a CSV format file and converted to xml via fm: SCMS_STRING_TO_XSTRING. Though it wont have the formats that was needed, but at least I could get the hyperlinks on the file.
Thanks much for Your perusal and help!