Copyright 2024 - BV TallVision IT

Wouldn't it be great if Smartform output could contain click-link or hyperlink texts that would take the end user to some web site in his/her own browser ? It can be done ! This is an example where a Smartform is composed with a reference text, URL references are prepared before the Smartform is produced, then the output is transformed into a PDF file (on the presentation server) with working alias links. 

The way these hyperlinks work is as follows: first of all create your smartform with your texts. Select the text you want to transform in to a Hyperlink, where the text "SAP" is used in this example. If your Smartform text editor dies not allow you to turn a bit of text into a hyperlink - don't worry. I stumbled across the same problem and resolved it by simply putting <%W>SAP</> tags around my hyperlink word - which has the required effect.

Separately to defining which words become hyperlink words, the actual hyperlink url's need to be supplied. In the downloadable example this is done as preperation step in composing the Smartform. Available discussion threads suggest it can be done from anywhere in the smartform as well - which I have not tried. So a full list of hypertext words and thier URLs is supplied via the HR_RCF_SF_URL_* modules. Check out the example for more detail.

.

A simple Smartform utility class

To address this issue for a series of Smartforms, I've introduces a smartform utility class with only 1 method. It reads an SO10 longtext (all standard SAP) which holds the full list of hyperlink alias words with links. Assuming there is only one such list for several Smartforms, this would work fine. If you would have different lists, simply specify the name of the SO10 longtext to apply this setup with an alternate list. The longtext would look something like this:

* LinkedIn~http://www.linkedin.com/company/bakerybombers/careers
* Facebook~http://www.facebook.com/bakerybombers
* Twitter~https://twitter.com/bakerybombersWorks
* YouTube~https://www.youtube.com/user/bomberchannel
* LinkedIn~http://www.linkedin.com/company/bakerybombers/careers
* contact~http://www.bakerybombers.gov/contact/

What you would need to do to implement this is create a global class ZCL_SMARTFORM_UTILITY (you may already have such class available) and add a single method SET_HYPERLINK_ALIASSES to it. The method is Static, Public and has an Importing parameter TEXT_NAME with reference type TDOBNAME. The default value of this importing parameter is set to the name of your longtext holding the hyperlink references, e.g. Z_E-RECRUITMENT-HYPERLINKS.

Now copy this coding into the method:

* This method will read an SO10 longtext and interpret the text as a
* list of Alias texts followed by a hyperlink. The method can be called
* form the initialization routine in the Smartform which will make all
* hyperlink references available.

* IMPORTANT NOTICE: if you want to use this setup in your own Smartform,
* make sure you:
* (1) Set output_options-urlcall = 'HR_RCF_SF_URL_CALLBACK'. before calling
*     the Smartform  - OR -
*     Set the urlcall function method in the Smartform initialization block
* (2) Call this method before calling the Smartform - OR -
*     call it from the Smartform initialization block
* (3) Make sure the longtext that is in TEXT_NAME (standard SO10 text)
*     holds a list of alias~https://some-secure-site.com/reference
* (4) Turn the word "alias" into an actual alias reference by bombarding
*     it to a hyperlink - OR - by placing <%W>alias</> tags around the word
*     anywhere on your Smartform.
  types: BEGIN OF ty_url, "<= definition copied from LHRRCF00_CALLBACKTOP
           name(80),
           url TYPE string,
         END OF ty_url.
  data: lt_lines type standard table of tline,
        lw_line type tline,
        lt_urls type standard table of ty_url,
        lw_url type ty_url.

* First read the SO10 text with the alias-list. Each line contains
* an alias text followed by the http link reference and separated by ~
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id                            = 'ST'
      language                      = sy-langu
      name                          = TEXT_NAME
      object                        = 'TEXT'
    tables
      lines                         = lt_lines
    EXCEPTIONS
      OTHERS                        = 4.
* Only continue when an existing text with content is found:
  check sy-subrc = 0 and not lt_lines[] is initial.
* Compose the lt_urls listing with the content of the text:
  loop at lt_lines into lw_line.
    split lw_line+2 at '~' into lw_url-name lw_url-url.
    if not lw_url-url is initial.
      append lw_url to lt_urls.
    endif.
  endloop.
* Only continue if there are URLS to prepare
  check not lt_urls[] is initial.
  CALL FUNCTION 'HR_RCF_SF_URL_REFRESH_GT'.
  CALL FUNCTION 'HR_RCF_SF_URL_PREPARE_CALLBACK'
    TABLES
      pt_url = lt_urls.

With this logic in place, all that needs to be done now is involve it from the Smartform Initialization routine (or even before calling the Smartform). An example on how this can be done:

After this call is implemented, the list of URL's which need to be available for Alias use is available. Simply change your text from

If you like, you can find us on YouTube or LinkedIn.

to

If you like, you can find us on <%W>YouTube</> or <%W>LinkedIn</>.

and your text will be underlined and hyperlinks become active. Not in the print preview though, but active nevertheless in PDF output.