To bring some colour into SAP transactions I like to use Icons. I also think that Icons help to recognize faster what kind of data is displayed. Using different icons for different status help to get a better overview.

There is no witchcraft about the dynamic usage of Icons. But dynamic Icons in a search help exit comes quite close.

In a project I wanted to customize the icons for certain status information. Therefore I provided a field ICON_NAME to the status. In a search help I wanted not to have the name of the icon displayed but the icon itself.


With The Help Of My Friends


It was clear that I had to use a search help exit for this. But as providing an icon name to an object is quite obvious I would like to have a search help exit that I could reuse for that requirement.

I remembered that you could define parameters in a search help that could be retrieved by the search help exit. I tried to use this feature…

Parameters
I defined the following parameters to use in the search help exit:
◈ ICON_TEXT (column for displaying the icon)
◈ COLUMN_WITH_ICON_NAME
◈ COLUMN_WITH_ICON_INFO
◈ COLUMN_FOR_ICON_DISPLAY
 

Code

FUNCTION z_f4if_shlp_exit_icon.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     VALUE(SHLP) TYPE  SHLP_DESCR
*"     VALUE(CALLCONTROL) LIKE  DDSHF4CTRL STRUCTURE  DDSHF4CTRL
*"----------------------------------------------------------------------
  DEFINE get_param.
    CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'
      EXPORTING
        parameter         = &1
        fieldname         = '*'
      IMPORTING
        value             = lv_parameter_value
      TABLES
        shlp_tab          = shlp_tab
        record_tab        = record_tab
      CHANGING
        shlp              = shlp
        callcontrol       = callcontrol
      EXCEPTIONS
        parameter_unknown = 1.
    IF sy-subrc = 0.
      &2 = lv_parameter_value.
    ENDIF.
  END-OF-DEFINITION.
  DEFINE icon_create.
    CALL FUNCTION 'ICON_CREATE'
      EXPORTING
        name            = &1
        info            = &2
        add_stdinf      = ''
      IMPORTING
        result          = &3
      EXCEPTIONS
        OTHERS          = 3.
  END-OF-DEFINITION.
*== Info:
* Dieser Baustein kann in Suchhilfen als Suchhilfe-Exit verwendet werden
*== Zweck:
* Anzeige des Icons zu einem Icon-Namen, der in der Tabelle vorhanden ist
*== Voraussetzung:
* Spalte mit dem Namen eines Icons
*
  "Tabelle für den Iconnamen, der aus der RESULTTAB ermittelt wird
  DATA lt_col_iconname TYPE STANDARD TABLE OF icon_name.
  "Tabelle für den Inhalt der Info zum Icon
  DATA lt_col_iconinfo TYPE STANDARD TABLE OF icon_text.
  "Tabelle für das Aufbereitete Icon, das an die RESULTTAB übergeben wird
  DATA lt_col_icontext TYPE STANDARD TABLE OF icon_text.
  DATA lv_icontext TYPE icon_text.
  "Generischer Parameter
  DATA lv_parameter_value       TYPE  ddshvalue.
  "Name der Spalte, die den Iconnamen enthält
  DATA lv_column_with_icon_name TYPE  shlpfield.
  "Name der Spalte, die den Icontext enthält
  DATA lv_column_with_icon_info TYPE  shlpfield.
  "Name der Spalte, in der das aufbereitete Icon dargestellt werden soll
  DATA lv_column_for_display    TYPE  shlpfield.
* EXIT immediately, if you do not want to handle this step
  IF callcontrol-step <> 'SELONE' AND
     callcontrol-step <> 'SELECT' AND
     callcontrol-step <> 'SELONE' AND
     callcontrol-step <> 'PRESEL' AND
     callcontrol-step <> 'SELECT' AND
     callcontrol-step <> 'DISP'.
    EXIT.
  ENDIF.
*"----------------------------------------------------------------------
* STEP DISP     (Display values)
*"----------------------------------------------------------------------
  IF callcontrol-step = 'DISP'.
    get_param 'COLUMN_WITH_ICON_NAME'    lv_column_with_icon_name.
    get_param 'COLUMN_WITH_ICON_INFO'    lv_column_with_icon_info.
    get_param 'COLUMN_FOR_ICON_DISPLAY'  lv_column_for_display.
    "Ermitteln aller ICON_NAMEN der einzelnen Einträge
    CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'
      EXPORTING
        parameter         = lv_column_with_icon_name
        fieldname         = '*'
      TABLES
        shlp_tab          = shlp_tab
        record_tab        = record_tab
        results_tab       = lt_col_iconname
      CHANGING
        shlp              = shlp
        callcontrol       = callcontrol
      EXCEPTIONS
        parameter_unknown = 1
        OTHERS            = 2.
    IF sy-subrc = 0.
      "Wenn alles geklappt hat, dann sind in Tabelle LT_COL_ICONNAME die Namen
      "der Icons aus dem Parameter COLUMN_WITH_ICON_NAME
      "Nun noch die die Texte für die Quickinfo ermitteln
      CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'
        EXPORTING
          parameter         = lv_column_with_icon_info
          fieldname         = '*'
        TABLES
          shlp_tab          = shlp_tab
          record_tab        = record_tab
          results_tab       = lt_col_iconinfo
        CHANGING
          shlp              = shlp
          callcontrol       = callcontrol
        EXCEPTIONS
          parameter_unknown = 1
          OTHERS            = 2.
      if sy-subrc > 0.
        "Macht nichts: Es ist kein Feld definiert/ vorhanden, das zum Icon angezeigt werden soll
        "Die Tabelle LT_COL_ICONINFO ist dann halt leer
      endif.
      LOOP AT lt_col_iconname INTO DATA(lv_iconname).
        "Info zum Icon lesen:
        READ TABLE lt_col_iconinfo INTO DATA(lv_iconinfo) INDEX sy-tabix.
        "Aufbereitung des Icons zur Darstellung
        icon_create lv_iconname lv_iconinfo lv_icontext.
        APPEND lv_icontext TO lt_col_icontext.
      ENDLOOP.
    ENDIF.
    "Alle aufbereiteten Icons an RESULTTAB übergeben
    CALL FUNCTION 'F4UT_PARAMETER_RESULTS_PUT'
      EXPORTING
        parameter         = lv_column_for_display
      TABLES
        shlp_tab          = shlp_tab
        record_tab        = record_tab
        source_tab        = lt_col_icontext
      CHANGING
        shlp              = shlp
        callcontrol       = callcontrol
      EXCEPTIONS
        parameter_unknown = 1
        OTHERS            = 2.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    EXIT.
  ENDIF.
ENDFUNCTION.
 
 
 
Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Team Lead
Contact : serkurumsal@yandex.com