Show TOC

Function documentationCalculated Field

 

You can create a read-only field enhancement associated with a formula expression. The formula expression can be comprised of operations, constants, and application-specific data attributes.

You define the formula expression in the Calculated Field Value block.

If you have enabled the expert mode, you can see the name of the BOL (business object layer) object for which you are creating a calculated field.

Prerequisites

In the field details, you have selected the Calculated (Read-only) checkbox.

You are using the WebClient UI. This function is not available in Floorplan Manager for Web Dynpro ABAP.

Features

Operations

You can use operations to calculate the value of the field at runtime. You can select the operations displayed in the Operations block by clicking them. In addition, you can enter the following operations manually: <, >, =, >=, <=, +, -, *, /.

The operations are provided by Business Rule Framework plus (BRFplus). For each operation, you can display the documentation by choosing the ? icon. For more information about BRFplus, see Start of the navigation path http://help.sap.com/netweaverInformation published on SAP site Next navigation step SAP NetWeaver 7.0 (2004s) Enhancement Package 3 Next navigation step SAP NetWeaver Library Next navigation step SAP NetWeaver by Key Capability Next navigation step Application Platform by Key Capability Next navigation step Business Services Next navigation step Business Rule Framework plus End of the navigation path.

Note Note

Calculated fields have some restrictions regarding CRM application data usage and BRFplus integration. For more information, see SAP Note 1457617Information published on SAP site.

End of the note.
Custom Operations

You can also define custom operations. For more information, see the following:

  • http://www.sdn.sap.comInformation published on SAP site Start of the navigation path Articles Next navigation step Business Rules Management Next navigation step How to Create Formula Functions End of the navigation path

  • Documentation for Business Add-in (BAdI) BRFplus Application Exit (AXT_BRFPLUS_APPL_EXIT)

Global Attribute Tags

You can display global attribute tags (left table) by filtering on the UI object type. You can add them to the formula expression by clicking them. They are inserted at your cursor position. If you want to cut and paste attribute tags, make sure that you cut the complete tag: <VALUE[...]>. For information about global attribute tags, see Global Attribute Tag.

You can use the existing attribute tags from the table. In addition, you can create new attribute tags in Customizing for UI Framework under Start of the navigation path UI Framework Definition Next navigation step Global Attribute Tags End of the navigation path.

To use an attribute tag in a formula, the following conditions must be met:

  • The field type of the attribute tag must fit to the position in the formula.

    You can use attribute tags based on different field types together within a formula. However, make sure that they are appropriate for the operation and the position within the formula.

    Example Example

    You have defined a formula expression that contains the timepoint field type. The result of the calculation can be a Boolean value.

    End of the example.
  • To create calculated fields as currency and quantity fields, you have defined a reference field in Customizing for UI Framework under Start of the navigation path UI Framework Definition Next navigation step Global Attribute Tags End of the navigation path.

  • The attribute tag must be accessible from the BOL object where the new calculated field is created.

    User attribute tags and constant attribute tags are always accessible. BOL attribute tags are accessible in the following cases:

    • The BOL entity exists at runtime.

      Example Example

      A BOL attribute tag for contact details of an account that has no contacts is not accessible.

      End of the example.
    • One of the following applies:

      • The BOL object that is to be enhanced by the calculated field must be in the path of the BOL attribute tag.

      • The path to the attribute tag is unique. That is, there must only be one path (one relation) from the root object to the enhanced BOL object.

      • The BOL attribute tag path has only 1:1 relations.

    Calculated fields are added to a BOL object. The BOL object that is enhanced depends on the enhanced business object part that you have selected. The Application Enhancement Tool (AET) uses only the path of the BOL attribute tag. The path of the BOL attribute tag starts with the root object and follows the relations to an attribute. The AET has to find a path from the enhanced BOL object that contains the calculated field to the attribute of the BOL attribute tag.

  • The relation is not an association. Associations cannot be traced backward from child object to parent object.

Using an Untagged Field in a Calculated Field (Application Field or Field Created Using the AET)

In the formula expression, you can use field enhancements, fields from table enhancements, or application fields.

Note Note

You can use a field enhancement as an operand, but not a calculated field. That is, you can create a calculated field based on another field enhancement, but not based on other calculated fields.

End of the note.

Example Example

You have created a field called Discount. You want to create a calculated field called Price in which you would use the discount to calculate the price.

End of the example.

Proceed as follows:

  1. Create and generate the field that you want to use in the calculation.

  2. Create BOL attribute tags for this field as required in Customizing for UI Framework under Start of the navigation path UI Framework Definition Next navigation step Global Attribute Tags End of the navigation pathor in the WebClient UI by pressing F2 and choosing the Tag pushbutton.

  3. Create a calculated field in a field enhancement and add the attribute tag in the formula expression.

Using a Calculated Field in Table Enhancements

BOL attribute tags are defined based on an existing BOL object. Since the BOL object needs to be generated with a table enhancement, you have to proceed as follows to use BOL attribute tags:

  1. Generate the table enhancement without the calculated field.

  2. Create BOL attribute tags for this BOL object.

  3. Edit the table enhancement and use the attribute tag in the formula expression.

1:n Relations

If the path of a BOL attribute tag contains at least one 1:n relation, a table of data is returned by the BOL attribute tag. In this case, you have to use the table operations to get only one result value, which can be passed to the calculated field as result of the formula.

Length

Global attribute tags, for example <VALUE[BOL:BP_ACCOUNT:ID]>, can have a length of up to 255 characters. They are not passed to BRFplus directly, but converted to BRFplus parameters. The string literals in formula expressions can have a length of up to 60 characters. If you try to define a literal that is longer, for example, if you want to calculate the URL of an image, an error is displayed. You can use two shorter strings instead of one and concatenate them.

Example Example

You want to calculate the URL of an image, but the following formula fails:

CONCATENATE( 'http://URL_that_has_more_than_60_characters/', <VALUE[BOL:BP_ACCOUNT:ID]> ).

You can concatenate this URL string using two shorter strings:

CONCATENATE( 'http://first_part_of_the_URL_that_has_more_than_60_characters', CONCATENATE('_second_part_of_the_URL_that_has more_than_60_characters/', <VALUE[BOL:BP_ACCOUNT:ID]> )).

End of the example.
Validation of the Formula

You can choose the Check pushbutton to validate the formula expression. If you do not validate the formula, the AET automatically validates the formula when you choose the Back pushbutton.

The field types of the AET and BRFplus are slightly different. If you choose the Check pushbutton, the calculated field that displays the result of the formula is checked against the field types of BRFplus. For this reason, you may encounter valid formulas that do not work at runtime, since the checks could not be executed at design time.

Calculation of the Field Value at Runtime

If the calculation of a field fails at runtime and the field is displayed on the UI, a standard user sees the message Calculation for field <field name> failed.

Some fields are not displayed on the current view, but they are calculated, since the calculation is performed when the BOL entity is read.

Example Example

  • Errors from sales order fields are not displayed on the opportunity overview page.

  • On the search result page, you do not see the calculated field, but the calculation has happened. Therefore, the message is not displayed on the search result page or overview page.

End of the example.

Technical users can increase their message level by setting the user parameter BSPWD_USER_LEVEL to 6. This displays all messages of the calculation. For example, a calculation message is created if either an attribute tag cannot be resolved at runtime because a relation points to BOL entities that do not exist yet, or if the field types within the calculation do not match.

Activities

  1. You define the field details.

  2. You add the operation that is to be used to calculate the field value.

  3. You insert one or more global attribute tags as operands.

  4. If necessary, you create new global attribute tags.

    Note Note

    You may have to generate the enhancement first.

    End of the note.
  5. You validate the formula.

  6. You save and generate the enhancement.

Example

The following table shows whether BOL attribute tags can be used in the calculated fields of the enhanced BOL objects:

BOL Attribute Tag

BOL Object

OrderHeader

Account

ShipmentData

Item

PricingData

ScheduleLine

OrderHeader->@HEAD_ID

Yes

No

Associations cannot be traced backward

Yes (a unique parent relation exists)

Yes

The BOL attribute tag path has only 1:1 relations

Yes

The BOL attribute tag path has only 1:1 relations

Yes

The BOL attribute tag path has only 1:1 relations

OrderHeader->SoldToRelation/@NAME

Yes

Yes

Yes (a unique parent relation exists)

Yes

The BOL attribute tag path has only 1:1 relations

Yes

The BOL attribute tag path has only 1:1 relations

Yes

The BOL attribute tag path has only 1:1 relations

OrderHeader->ShipmentRelation/@CAN_BE_SHIPPED

Yes

No

Associations cannot be traced backward

Yes

Yes

The BOL attribute tag path has only 1:1 relations

Yes

The BOL attribute tag path has only 1:1 relations

Yes

The BOL attribute tag path has only 1:1 relations

OrderHeader->ShippedItemsRelation/@ITEM_NO

Yes (the result is a table and you have to use the table functions)

No

Associations cannot be traced backward

Yes

A unique parent relation exists (the result is a table and you have to use the table functions)

Yes

No

*

No

*

OrderHeader->ShippedItemsRelation/SubItemsRelations/@ITEM_NO

Yes (the result is a table and you have to use the table functions)

No

Associations cannot be traced backward

Yes

A unique parent relation exists (the result is a table and you have to use the table functions)

Yes

No

*

No

*

OrderHeader->OpenItemsRelations/PricingRelation/@NET_VALUE

Yes (the result is a table and you have to use the table functions)

No

Associations cannot be traced backward

Yes

A unique parent relation exists (the result is a table and you have to use the table functions)

Yes

Yes

No

*

OrderHeader->OpenItemsRelation/ScheduleLineRelation/@SHIPMENT_DATE

Yes

No

Associations cannot be traced backward

Yes

A unique parent relation exists (the result is a table and you have to use the table functions)

Yes (the result is a table and you have to use the table functions)

No

*

Yes

* The root object has more than one path to the enhanced BOL object. The Item has two possible parent objects, that is, OrderHeader and Item itself. Due to the SubItemsRelation, an item is its own parent object.