Sorting on calculated (virtual) fields in Web UI

Assignment blocks usually contain tables. The content of these tables can be sorted by clicking the header column and selecting ascending or descending. This sorting feature is supported out of the box and managed by the Web UI framework.

However, this feature is supported only for attributes which are part of the business object layer (BOL entity level). It is not working for calculated (virtual) attributes which are implemented at the context node level only.

To support real and virtual attributes you have to implement a solution similar to

SAP CRM WebUI : Sorting custom columns (custom attributes)

  1. Use a callback method to perform the comparison by implementing interface if_bol_col_sorting. You can place this method in context node class by implementing the sorting interface. There is no need to implement a independent class.
  2. Use a method cl_crm_uiu_bp_tools=>is_a_greater_b, cl_crm_uiu_bp_tools=>is_date_a_greater_b or similar to perform the comparison on context node level instead of BOL entity level.
  3. Perform custom or multiple-field sorting in method ON_NEW_FOCUS after reading/refreshing collection. Use method me->collection_wrapper->if_bol_bo_col~sort. Attribute name must be if_bol_col_sorting=>custom and iv_sort_callback must be the class implementing interface if_bol_col_sorting.
  4. Ensure that you are calling method CLEAR_LAST_LINE before performing sorting otherwise sorting might going wrong on next round trip.

Automated creation of follow-up transactions. How to use and enhance COPY_DOCUMENT?

To create follow-up documents automatically from a business transaction we can use a ppf action with method COPY_DOCUMENT.

We have to use the parameter „process_type“ to specify to transaction type.

The title of the ppf action will be taken over as description of the follow-up transaction. There is no way to deactivate this feature except the title of the ppf action will be left empty. Then it depends on the copy control what will happen, mostly description of the predecessor transaction will be transferred then. If we always want to take over description from predecessor transaction, we have to de-comment line/parameter iv_actiontext on call of lc_action_execute->copy_document in PPF method COPY_DOCUMENT (BADI Def. EXEC_METHODCALL_PPF -> BADI Impl. COPY_DOCUMENT -> Method EXECUTE). Either via modification or via copy, past and adjust.

The long text of the ppf action can be transferred to a text type of the follow-up document. If we want to do this, we just need to configure and use a text determination access sequences using function module CRM_REFERENCE_TEXT_GET (ref object and ref text type can be left empty in customizing).

If we want to set some more values (i.e. priority, category, …), we have to put these static values in the ppf action container like parameter process_type. We also have to enhance method copy_document of class cl_action_execute to transfer these data to the follow-up document. There is currently no standard solution to default/transfer some data to the follow-up document.

If we want to set a partner for a specific partner function we should do it using partner determination or BRF+ based on a field which is already defaulted using solution mentioned above (i.e. category). We should never try to default a partner by the follow-up creation routine itself because the partner number will be different in different systems and the assignment rule might change very often.

The copy control is per default active for the follow-up creation, which means that data can be overtaken from the current transaction to the follow-up transaction.

Unfortunately there is currently no way to create a follow-up based on a template transaction. Only SAP CRM Service is using such a feature for Service Plans (we can have a look at ppf action method CREATE_ORDER_SRVPLAN and transaction CRMD_SERV_CYCLE). However, this solution is specific for this use case only and cannot be used for other use cases as well.

For a lot of use cases COPY_DOCUMENT (with the mentioned extensions) will be sufficient to implement the requirements. However there exist some other ppf action methods which handles items and document flow in a different way. If we want to use/copy items we should try COPY_DEF_ITEMS (create follow-up and copy items), COPY_ITEM_LOCAL (create/copy items in a transaction locally) and COPY_ITEM_TO_TASK (create follow-up transaction with current item as predecessor).

How to work with timestamp attributes in SAP Web Client UI?

It happens very often, that we want to use additional TIMESTAMPs in context of Business Transaction Management.

If we are introducing additional date types (appointments) via configuration, the SAP CRM standard is managing the display, storage and data conversion. We just need to add context nodes for it to our UI components. We should have a look at already existing date/time context nodes and reuse the context node classes used here to ensure standard-like behaviour (virtual fields, value helps, data conversion, …).

If we decide to create a field enhancement using Application Enhancement Tool (AET), we dont need an additional context node since we are using context node BTAdminH or BTCustomerH. However, we will now face the challenge, that there is no proper value help available for timestamps. Therefore we need to create two additional virtual attributes for DATE and TIME which are referring to the TIMESTAMP attribute.

(Der Quellcode wird später hier noch ergänzt….)

How to calculate virtual fields for table enhancements created with AET?

All tables, structures, function modules and classes will be generated automatically, if you create a table enhancement using Application Enhancement Tool (AET). However, sometimes you might want to calculate some fields instead of storing it in database.

The AET is not supporting such virtual fields. Therefore you have to implement it manually.

Solution 1: Create an additional attribute in the context node of the generated UI component and place a calculation in the getter method. Deactivate coding of setter and i-getter method.

Solution 2: Enhance structures ?_WORK, ?_ATTR and ?_BOL_ATTR by an additional attribute. Place your calculation at the end of method GET_DETAIL of class CL_AXT_TABLES_API (define and use a table name dependent BADI for high quality solution). Add a value attribute with the same name to context node of the generated UI component. Don’t change the generated code here since it will read the data from BOL/GenIL as wanted.

Conclusion 1: Development should be restricted to a minimum. Whenever source code can be avoided, it should be avoided. Therefore solution 1 is preferred from a supportability perspective, if there are only few virtual fields required.

Conclusion 2: Business logic should be placed in API or BOL/GenIL layer instead of UI layer to be reused UI independently. Therefore solution 2 is preferred from an architecture perspective, if several virtual fields are required or if a high quality and high flexible solution is requested.

Such- und Wertehilfen im SAP Web Client UI

Das SAP Web Client UI ist ein mächtiges und flexibles Framework zur Entwicklung nutzerfreundlicher User Interfaces. Doch manchmal hat SAP SE die Lösung nicht zuende gedacht. Als Beispiel sei hier der üblicherweise ungerechtfertigt hohe Entwicklungsaufwand zur Implementierung Feldprüfungen bei Eingabe, Feldaufbereitungen bei Ausgabe und Such- bzw. Wertehilfen genannt.

Folgende Lösungen stehen zur Verfügung:

  • Die genannten Logiken sind in den Kontextknoten implementiert. Wird also ein Kontextknoten benutzt, der in einer anderen UI-Komponente bereits existiert, sollte geprüft werden, ob der Kontextknotenkontroller wiederverwendet werden kann. Nachdem die Super-Klasse des eigenen Kontextknoten durch die Standard-Kontextknotenkontrollerklasse ausgetauscht wird, stehen in der Regel sämtliche vom Standard gewohnte Prüfungen und Aufbereitungen zur Verfügung.
  • Bei Nutzung des Design Layers können dem Feld Dictionary-Suchhilfen zugeordnet werden. Diese werden dann automatisch gezogen.
  • Für Felderweiterungen mittels Application Enhancement Toolset (AET) werden automatisch die Dictionary-Suchhilfen bzw. -Wertehilfen genutzt. Ohne Programmieraufwand.
  • Im Artikel SAP CRM & SAP Solution Manager Business Transaction Search Enhancement habe ich beschrieben, wie die AET-Automatik auch für SAP-Standard-Felder oder manuell ergänzte Kundenfelder aktiviert werden kann. Dieser Weg wird jedoch von SAP SE nicht supportet.
  • Wenn alle anderen Wege versagen, dann muss am Ende doch klassich die V-Getter-Methode im Kontextknotenkontroller ausprogrammiert werden. Für einfache Dropdown-Listen gibt es jedoch bereits eine Hilfsklasse cl_crm_uiu_ddlb die uns die meiste Arbeit abnimmt:

lr_valuehelp_pldescr TYPE REF TO cl_crm_uiu_ddlb.

*Create Value Help Descriptor
CREATE OBJECT lr_valuehelp_pldescr
iv_source_type = if_bsp_wd_valuehelp_pldescr=>source_type_table.

*Build up dropdown list based on data element.
CALL METHOD lr_valuehelp_pldescr->set_data_element
iv_data_element      = 'NAME_OF_THE_DATA_ELEMENT'
* iv_add_initial_entry =

*Return value help descriptor
rv_valuehelp_descriptor ?= lr_valuehelp_pldescr.