Hello Sap WebUi developpers gurus,
I am not a pure technical guy, but I have to build a code within the Save of a business partner, that calculate automatically the number of months from the actual date to a future date. This future date is typed in the system by the user.
I have implemented the BADI CRM_BP_UIU_SAVE in the method ON_SAVE_EVENT.
The below code is working whenever I have a single entry but unfortunately does not cover the requirement as the user can insert in this table view more entries.
Data:
lv_iterator type ref to if_bol_bo_col_iterator,
lv_collection type ref to if_bol_bo_col,
lr_relation TYPE REF TO if_bol_bo_property_access,
lo_core TYPE REF TO cl_crm_bol_core,
lv_guid TYPE BU_PARTNER_GUID,
lo_entity type ref to cl_crm_bol_entity.
DATA: lv_mo TYPE i,
LV_FUTUDATE TYPE ZDTEL00002W,
LV_TAGEN TYPE i.
lv_collection = gv_access_header->get_related_entities( iv_relation_name = 'ZEXT_BOL_RELAT00000C' ).
**iv_mode = 'c').
*** iv_mode = 'n').IF lv_collection IS BOUND.
lr_relation = lv_collection->get_current( ).
TRY.
lr_relation->GET_PROPERTY_AS_VALUE( exporting IV_ATTR_NAME = 'ZZFLD00001F' IMPORTING ev_result = LV_FUTUDATE ).CATCH cx_crm_cic_parameter_error cx_sy_ref_is_initial cx_sy_move_cast_error
cx_crm_genil_model_error.ENDTRY.
***** CONVERSION DATEN Variablen sy-datum und LV_FUTUDATE.CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = LV_FUTUDATE
I_DATUM_VON = sy-datum
IMPORTING
E_TAGE = LV_TAGEN
EXCEPTIONS
DAYS_METHOD_NOT_DEFINED = 1
OTHERS = 2.
IF LV_TAGEN IS INITIAL
OR LV_FUTUDATE IS INITIAL
OR LV_FUTUDATE LE sy-datum.
lv_mo = '00'.
ELSE.
lv_mo = LV_TAGEN / 30.IF lv_mo GE '1' AND lv_mo LE '99'.
lr_relation->SET_PROPERTY( IV_ATTR_NAME = 'ZZFLD00001K'
IV_VALUE = lv_mo ).
ELSE.lr_relation->SET_PROPERTY( IV_ATTR_NAME = 'ZZFLD00001K'
IV_VALUE = '00' ).ENDIF.
ENDIF.
ENDIF.
gv_access_header->if_bol_bo_property_access~get_property_as_value(
EXPORTING
iv_attr_name = 'BP_GUID'
IMPORTING
ev_result = lv_GUID ).lo_core = cl_crm_bol_core=>get_instance( ).
lo_core->start_up( 'BP' ).
lo_entity ?= lo_core->get_root_entity( iv_object_name = 'BuilHeader'
iv_object_guid = lv_guid ).
if lo_entity->lock( ) = abap_true.
lo_entity->switch_to_change_mode( ).
lo_entity->create_related_entity( 'ZEXT_BOL_RELAT00000C' ).
lo_entity = lo_entity->get_related_entity( IV_RELATION_NAME = 'ZEXT_BOL_RELAT00000C'
iv_mode = 'n' ).lo_core->modify( ).
ENDIF.
So I decided to modify this code in order to create a while to read these multiple entries and then a Loop around an internal table.
Please have a look at the code below:
Data:
lv_iterator type ref to if_bol_bo_col_iterator,
lv_collection type ref to if_bol_bo_col,
lr_relation TYPE REF TO if_bol_bo_property_access,
lr_relation2 TYPE REF TO cl_crm_bol_entity,
lo_core TYPE REF TO cl_crm_bol_core,
lv_guid TYPE BU_PARTNER_GUID,
ls_portman type ZTAB00002S_ATTR,
lt_portman type standard table of ZTAB00002S_ATTR,
lr_transaction TYPE REF TO IF_BOL_TRANSACTION_CONTEXT,
lo_entity type ref to cl_crm_bol_entity.
DATA: lv_mo TYPE i,
LV_FUTUDATE TYPE ZDTEL00002W,
LV_TAGEN TYPE i.
clear lt_portman.
refresh lt_portman.
lv_collection = gv_access_header->get_related_entities( iv_relation_name = 'ZEXT_BOL_RELAT00000C' ).
IF lv_collection IS BOUND AND lv_collection->size( ) > 0.
lv_iterator = lv_collection->get_iterator( ).
lr_relation2 ?= lv_iterator->get_first( ).
WHILE lr_relation2 IS BOUND.
lr_relation2->get_properties( importing ES_ATTRIBUTES = ls_portman ).
append ls_portman to lt_portman.
lr_relation2 ?= lv_iterator->get_next( ).
ENDWHILE.
*** Schleife über interne Tabelle
loop at lt_portman into ls_portman.
LV_FUTUDATE = ls_portman-ZZFLD00001F.
***** CONVERSION DATEN Variablen sy-datum und LV_FUTUDATE.
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = LV_FUTUDATE
I_DATUM_VON = sy-datum
IMPORTING
E_TAGE = LV_TAGEN
EXCEPTIONS
DAYS_METHOD_NOT_DEFINED = 1
OTHERS = 2.
IF LV_TAGEN IS INITIAL
OR LV_FUTUDATE IS INITIAL
OR LV_FUTUDATE LE sy-datum.
lv_mo = '00'.
ELSE.
lv_mo = LV_TAGEN / 30.
IF lv_mo GE '1' AND lv_mo LE '99'.
TRY.
lr_relation2->SET_PROPERTY( IV_ATTR_NAME = 'ZZFLD00001K'
IV_VALUE = lv_mo ).
CATCH cx_crm_cic_parameter_error cx_sy_ref_is_initial cx_sy_move_cast_error
cx_crm_genil_model_error.
ENDTRY.
ELSE.
lr_relation2->SET_PROPERTY( IV_ATTR_NAME = 'ZZFLD00001K'
IV_VALUE = '00' ).
ENDIF.
ENDIF.
gv_access_header->if_bol_bo_property_access~get_property_as_value(
EXPORTING
iv_attr_name = 'BP_GUID'
IMPORTING
ev_result = lv_GUID ).
lo_core = cl_crm_bol_core=>get_instance( ).
lo_core->start_up( 'BP_APPL' ).
lo_entity ?= lo_core->get_root_entity( iv_object_name = 'BuilHeader'
iv_object_guid = lv_guid ).
if lo_entity->lock( ) = abap_true.
lo_entity->switch_to_change_mode( ).
lo_entity->create_related_entity( 'ZEXT_BOL_RELAT00000C' ).
lo_entity = lo_entity->get_related_entity( IV_RELATION_NAME = 'ZEXT_BOL_RELAT00000C').
* iv_mode = 'n' ).
*lo_core = cl_crm_bol_core=>get_instance( ).
lo_core->modify( ).
* lr_transaction = lo_core->get_transaction( ).
* lr_transaction->save( ).
* lr_transaction->commit( ).
ENDIF.
ENDLOOP.
ENDIF.
Now the problem is that the above code is not working with multiple entries.
Please see the image below. The field to be calculated is called "Verblienden Laufzeit".
I have tried a lot of codes, but none seems to be working. No update within the database table is carried out and the webui is not updated.
Please , if you have experienced this case, any suggestion is welcome.
Best Regards,
Andrea
