Hi All,
I have a basic question. I have a custom assignment block, i have a read only field displaying only year part of date field by manipulating the field in the getter method. While saving i have to save the current date (say 01/03/2014) so i am manipulating in the setter method. I commented the below method. Is this the correct approach?.
CALL METHOD if_bsp_model_util~convert_from_string
EXPORTING
data_ref = copy
value = value
attribute_path = attribute_path.
Setter method code.
method SET_FROM_DATE.
DATA:
current TYPE REF TO if_bol_bo_property_access,
dref TYPE REF TO data,
lv_date TYPE string,
copy TYPE REF TO data.
FIELD-SYMBOLS:
<nval> TYPE ANY,
<oval> TYPE ANY.
* get current entity
if iterator is bound.
current = iterator->get_current( ).
else.
current = collection_wrapper->get_current( ).
endif.
* get old value and dataref to appropriate type
TRY.
TRY.
dref = current->get_property( 'FROM_DATE' ). "#EC NOTEXT
CATCH cx_crm_cic_parameter_error.
ENDTRY.
CATCH cx_sy_ref_is_initial cx_sy_move_cast_error
cx_crm_genil_model_error.
RETURN.
ENDTRY.
* assure that attribue exists
CHECK dref IS BOUND.
* set <oval> to old value
ASSIGN dref->* TO <oval>.
* create a copy for new value
CREATE DATA copy LIKE <oval>.
* set <nval> to new value
ASSIGN copy->* TO <nval>.
* fill new value using the right conversion
TRY.
* CALL METHOD if_bsp_model_util~convert_from_string
* EXPORTING
* data_ref = copy
* value = value
* attribute_path = attribute_path.
CATCH cx_sy_conversion_error.
RAISE EXCEPTION TYPE cx_bsp_conv_failed
EXPORTING
name = 'FROM_DATE'. "#EC NOTEXT
ENDTRY.
lv_date = substring( val = sy-datum off = 4 len = 4 ).
CONCATENATE value lv_date INTO <nval>.
* only set new value if value has changed
IF <nval> <> <oval>.
current->set_property(
iv_attr_name = 'FROM_DATE' "#EC NOTEXT
iv_value = <nval> ).
ENDIF.
endmethod.
Thanks
Tim