Carsten Ziegler, Chief Product Owner SAP NetWeaver Decision Service Management, SAP AG Customer-Defined Value Lists in SAP NetWeaver Decision Service Management September 2013
TABLE OF CONTENTS WHERE THE VALUES COME FROM... 4 Database / Data Dictionary... 5 Value lists... 5 Exit class... 5 LIMITATIONS... 7 SOLUTION... 8 END NOTE... 11 2
SAP NetWeaver Decision Service Management (DSM) embeds and extends Business Rule Framework plus (BRFplus) for the creation of business rules. With DSM those business rules can be used to implement decision services that can be deployed, this means transferred, to managed systems for local execution. DSM allows also access to data from managed systems during rules modeling for best integration with the ABAP stack and ABAP-based applications on the local system or on remote systems. DSM provides access to master data or configuration data on any managed system in the customer landscape, which has the following advantages: Avoiding the need to replicate any data Perfect integration with business applications Reduction of modeling errors (only existing data is used) VALUE LISTS IN THE UI Values from the ABAP backend are dynamically retrieved and used for validation of business rules such as decision tables. In decision tables a gap analysis is also performed based on the backend data to make sure all possible value combinations are covered by the decision table. Most visible is the use in the value help in the user interface. Figure 1: Value list used in value help In the data object properties, it is possible to define the check behavior. Values that do not exist in the value list may be used, or they may result in warnings or errors. 3
Figure 2: Additional element properties WHERE THE VALUES COME FROM There can be three sources for possible values: 1. Database / Data Dictionary 2. Value lists 3. Exit class When values are found they are shown on the respective tab in data object maintenance. Figure 3: Value list in element UI 4
Database / Data Dictionary Values are taken from the data dictionary or the database when a data object is bound to a data element in the data dictionary. Figure 4: Element binding Additionally, the data element needs to use a domain that has a value table or a list of values (Value Range tab). DSM inspects the data element and the domain as well as the value table when available. DSM further analyzes the value table for an assigned text table that is used to find descriptions for the values. All of the metadata is defined in the data dictionary. Value lists Data objects that are not bound to a data element in the data dictionary allow the creation of value lists directly in the data object user interface. Figure 5: Domain values in element UI Exit class It is possible to dynamically create value lists with help of a code exit for any data object. Therefore, an exit class needs to be defined on application level and the respective methods need to be implemented, namely CLASS_CONSTRUCTOR and IF_FDT_APPLICATION_SETTINGS~GET_ELEMENT_VALUES. 5
Figure 6: Application exit class In the class constructor, only one line of code is necessary to activate the element values exit if_fdt_application_settings~gv_get_element_values = abap_true. In the exit method IF_FDT_APPLICATION_SETTINGS~GET_ELEMENT_VALUES, any logic can be implemented to build a value list. The method provides several parameters: IV_ID IV_TIMESTAMP ITR_VALUE ITR_TEXT IV_LANGU IO_SELECTION ET_VALUE EV_NO_CHECKLIST EV_APPLICABLE ID of the data object for which values are retrieved Optional timestamp, usually values are independent of time and the parameter is not required Optional ABAP range table with selection conditions for the values Optional ABAP range table with selection conditions for the value texts Language to be used for the value texts Optional internal parameter List of values with texts Indicates that no value list does exist Indicates that the exit class applies for creation of the value list The following code can be used as a generic pattern to implement the method. DATA ls_value LIKE LINE OF et_value. CLEAR: ev_no_checklist, ev_applicable, et_value. ">>> only for a specific object CHECK iv_id EQ '005056A501951EE38A9D598B62FF4E26'. ">>> put your data retrieval code here DELETE et_value WHERE value NOT IN itr_value. DELETE et_value WHERE text NOT IN itr_text. ev_no_checklist = abap_false. ev_applicable = abap_true. 6
LIMITATIONS Value lists are created for single fields. Problems may occur when a data object is bound to a data element with reference to a value table that contains additional keys. A good example of this problem is the data element REGIO with value table T005S and text table T005U. Figure 7: Database table T005S Figure 8: Database table T005U 7
The values in the BLAND column that is typed with REGIO are not unique. In other words, there are multiple regions with value 01 and only the value in LAND 1 (=country) makes the value unique. LAND1 (Country) BLAND (Region) BEZEI (Description) AR 01 Buenos Aires BE 01 Antwerp BG 01 Burgas DE 01 Schleswig-Holstein In the dynamically generated value help in a decision table or text rule the country information is not available or not unique. In a decision table there may be a country column but cells may have enumeration values such as DE (Germany); FR (France); ES (Spain) or range options such as not equals, starts with and so on. Therefore it is not clear what exactly is meant when value 01 is used in the region column of the decision table. SOLUTION The solution to such problems is combining the values of two (or more) fields into one and the provisioning of values with the value help exit. The caller can combine two or more fields before evaluating of the decision service. But a formula expression as part of the decision service can also do the job. First, a data object with an appropriate length is needed to take the concatenated value. Figure 9: New data object to combine country and region The concatenation takes place with a formula, returning the value in the COUNTRY_REGION data object. 8
Figure 10: Formula to concatenate country and region Either the data object or the formula can now be used in rules or expressions such as decision tables. Note that you can use an expression as a calculated column in a decision table, for example, the formula that concatenates country and region. The formula result will then be compared with the table cell value, such as starts with DE for all regions in Germany. Next, an exit class that implements the class-constructor method (see above) and the element values exit needs to be created. METHOD if_fdt_application_settings~get_element_values. DATA: ls_value lv_rfcdest lt_t005t lt_t005s lt_t005u LIKE LINE OF et_value, TYPE rfcdest, TYPE STANDARD TABLE OF t005t, TYPE STANDARD TABLE OF t005s, TYPE STANDARD TABLE OF t005u. FIELD-SYMBOLS: <ls_t005s> TYPE t005s, <ls_t005t> TYPE t005t, <ls_t005u> TYPE t005u. CLEAR: ev_no_checklist, ev_applicable, et_value. ">>> only for specific object CHECK iv_id EQ '005056A501951EE38A9D598B62FF4E26'. * in remote scenarios data has to be retireved from other system lv_rfcdest = cl_fdt_dsm=>get_destination_for_object( iv_id ). IF lv_rfcdest IS INITIAL OR lv_rfcdest EQ 'NONE'. * select from local tables SELECT * FROM: t005s INTO TABLE lt_t005s, t005u INTO TABLE lt_t005u WHERE spras EQ iv_langu, t005t INTO TABLE lt_t005t WHERE spras EQ iv_langu. LOOP AT lt_t005s ASSIGNING <ls_t005s>. ls_value-value = <ls_t005s>-land1 && `/` && <ls_t005s>-bland. UNASSIGN: <ls_t005u>, <ls_t005t>. READ TABLE lt_t005u ASSIGNING <ls_t005u> WITH KEY land1 = <ls_t005s>-land1 bland = <ls_t005s>-bland. READ TABLE lt_t005t ASSIGNING <ls_t005t> WITH KEY land1 = <ls_t005s>-land1. CLEAR ls_value-text. IF <ls_t005t> IS ASSIGNED. "country description is available ls_value-text = <ls_t005t>-landx50. ENDIF. IF <ls_t005u> IS ASSIGNED. "region description is available 9
ls_value-text = ls_value-text && `/` && <ls_t005u>-bezei. ENDIF. INSERT ls_value INTO TABLE et_value. ENDLOOP. ELSE. * TODO: call your remote function module here ENDIF. DELETE et_value WHERE: value NOT IN itr_value, text NOT IN itr_text. ev_no_checklist = abap_false. ev_applicable = abap_true. ENDMETHOD. The result is a custom value list optimized for the specific use case. Now range options such as starts with can also be used and the selection of the state is possible because each value is unique. Figure 11: Value list with concatenated country and region values 10
END NOTE SAP NetWeaver AS ABAP in version 7.40 with Support Package 5 as well as SAP NetWeaver Decision Service Management 1.0 Support Package 2 were used for this document. The examples also work in a very similar way on other versions of the software. You can find more information about SAP NetWeaver Decision Service Management in SAP Community Network: http://scn.sap.com/docs/doc-29158 11
www.sap.com 2013 SAP AG. All rights reserved. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork, SAP HANA, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company. Sybase and Adaptive Server, ianywhere, Sybase 365, SQL Anywhere, and other Sybase products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Sybase Inc. Sybase is an SAP company. Crossgate, m@gic EDDY, B2B 360, and B2B 360 Services are registered trademarks of Crossgate AG in Germany and other countries. Crossgate is an SAP company. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.