Entering content frameProcedure documentationUser-Defined Validation Locate the document in its SAP Library structure

Use

Activate this option in the Attributes display for the BSP element if you wish to execute a user-defined validation of the element call. This can be the case, for example, if you wish to check the correct type of attribute values. Generally speaking, validation can take place both at compile time and at runtime. Runtime validation is particularly appropriate if attributes for BSP elements are assigned through BSP expressions (<%=...%>) only at runtime, or for attributes whose values are transformed into another data type (String -> I) at runtime. Validation at compile time, on the other hand, is done by the BSP compiler and takes place whenever values are passed using static attributes.

Activities

In addition to activating the option User-Defined Validation , you need to redefine the methods COMPILE_TIME_IS_VALID (for validation at compile time) and/or RUNTIME_IS_VALID (for validation at runtime) in the element handler class.

Caution

You must set the return parameter valid within the method COMPILE_TIME_IS_VALID. When determining this value, you use the predefined attributes and utilities belonging to the validation object validator. This object has corresponding conversion methods that identify attributes at compile time through the attribute name (see first example). The validation object validator is already contained in the interface for COMPILE_TIME_IS_VALID as an input parameter.

The RUNTIME_IS_VALID method, on the other hand, does not define any return parameter. The runtime validation triggers an appropriate runtime exception if there is an error. The validation object m_validator.is an important part of the method implementation. This object is already defined as an attribute of the element handler class and also has conversion methods that identify the attributes through their names and also through their value (see second example). The attributes to be checked (runtime attributes) are supplied as argument for calling the method RUNTIME_IS_VALID. This argument consists of a string in which the names of the attributes to be checked are listed, separated by ‘ / ‘.

Recommendation

It can happen that the string with the runtime attributes to be checked exceeds the maximum length of 200 characters when <Elementname>->RUNTIME_IS_VALID(attr_1/attr_2/ .../attr_n) is called – that is, if there is a large number of attributes. In such cases, you should pass the string ‘/ * / ‘ instead of the attribute name in order to avoid termination during activation.

Example: Validation at Compile Time

In the example below, the system is to check at compile time whether the value of the attribute required is a correct Boolean value and whether the two attributes size and maxlength contain integer values.

For this purpose, the interface method COMPILE_TIME_IS_VALID is overwritten. The corresponding methods of the object validator for the attributes concerned are called for the conversion of the string value from the HTML data stream into Boolean and integer values. If all the checked attribute values are valid, the return value valid is filled accordingly with m_all_values_valid.

method IF_BSP_ELEMENT~COMPILE_TIME_IS_VALID .

   validator->to_boolean( name = 'required' ).

   validator->to_integer( name = 'size' ).

   validator->to_integer( name = 'maxlength' ).

   valid = validator->m_all_values_valid.

endmethod.

 

Example: Validation at Runtime

In the example below, the system is to check at runtime whether the value of the attribute visible is a correct Boolean value and whether the two attributes axisMinVal and axisMaxVal contain values of the type Float.

In this case, the interface method RUNTIME_IS_VALID is overwritten. The parameter list m_visible, m_axisMinVal, m_axisMaxVal is passed to this method. The corresponding result of the attribute check is written into this list. The attributes are identified using the methods of the validation object m_validator. The method RUNTIME_IS_VALID does not return any return value. If one of the checked attribute values is invalid, a corresponding exception is triggered at runtime.

method IF_BSP_ELEMENT~RUNTIME_IS_VALID .

    m_visible    = m_validator->to_boolean( name = 'visible'

                                            value = me->visible ).

    m_axisMinVal = m_validator->to_float( name = 'axisMinVal'

                                          value = me->axisMinVal ).

    m_axisMaxVal = m_validator->to_float( name = 'axisMaxVal'

                                          value = me->axisMaxVal ).

endmethod.

 

 

 

Leaving content frame