cancel
Showing results for 
Search instead for 
Did you mean: 

Determination on save - Infinite loop issue (RAP)

08-07-2023 6:45 PM
muthuhana37 Explorer
6277 views 9 comments
0 Likes
SAP Managed Tags
Subscribe

Hello Team,

I have two determination like below where I want to update admin fields,

determination AdminCreate on save { create; }

determination AdminUpdate on save { create, update; }

While creating instance, I want create admin fields should be populated and while updating instance, update admin fields should be populated but somehow it causes infinite loop and getting below dump

Error analysis

The application has indicated exception "LCX_ABAP_BEHV_DETVAL_ERROR" as the reason for the
termination:
Infinite loop caused by cyclical triggering of on-save determinations

I need to understand,

  1. How to resolve this because without using update EML inside the determination, how to populate values ?
  2. Why create & update should need to define together in the trigger conditions ?
  3. Any other approach is there for this use case ?

Thanks a lot.

Best Regards,

Muthu

0 Likes

Accepted Solutions (0)

Answers (3)

Answers (3)

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Try to limit your determinations such that they are only triggered on field level.

Shortdump LCX_ABAP_BEHV_DETVAL_ERROR | SAP Community

muthuhana37
Explorer
0 Likes

Thanks andre.fischer for your quick response.

Yes keeping trigger conditions on field level disappears the error but in my use case I want to populate these admin fields at the time of create & update.

I kept these fields as read only so from UI it will not get triggered while create/update instance.

Any suggestion here ?

DiegoValdivia
Active Participant

For anyone else facing this same issue, I was able to avoid the infinite loop by using a Global Class with a Static Attribute to control if the Determination was already executed at least once.

Helper Class:

CLASS zcl_test_saver_helper DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    CLASS-DATA:
      already_saved TYPE abap_boolean.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_test_saver_helper IMPLEMENTATION.
ENDCLASS.

Behavior Pool Method

  METHOD update_timestamps.

    IF zcl_test_saver_helper2=>already_saved EQ abap_false.
      zcl_test_saver_helper2=>already_saved = abap_true.

      READ ENTITIES OF ZI_Test1_S IN LOCAL MODE
       ENTITY  Test1
        ALL FIELDS WITH CORRESPONDING #( keys )
       RESULT DATA(lt_res).

      MODIFY ENTITIES OF ZI_Test1_S IN LOCAL MODE
          ENTITY Test1
            UPDATE FIELDS ( UpdateDate )
            WITH VALUE #( FOR key IN keys ( %tky   = key-%tky
                                            UpdateDate = cl_abap_context_info=>get_system_date( ) ) )
            FAILED DATA(ls_failed)
            REPORTED DATA(ls_reported).
    ENDIF.

  ENDMETHOD.

  

d_schuitemaker62
Explorer
0 Likes
I had to resort to the same solution. A pity that the system does not automatically do this max one time running of determinations.
JessieCheah
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Muthu,

why not just have determination AdminUpdate on save { create, update; } and in your determination, evaluate if AdminCreate fields are initial, to skip AdminUpdate fields and vice versa (When AdminCreate fields are not initial, to populate AdminUpdate fields)?

Regards,

Jessie

muthuhana37
Explorer
0 Likes

Hello jessie.cheah,

This again going for infinite loop because I have update request EML inside determination which triggers itself again and again.

When I change the trigger conditions to create alone which doesn't trigger for while updating the instance.

JessieCheah
Product and Topic Expert
Product and Topic Expert
0 Likes

Oh yes you're right, because of the { update; }

But before we go further in, what are the admin fields that you are trying to populate? Are those self defined fields, or just fields like CreatedBy, LastChangedBy etc. ?

muthuhana37
Explorer
0 Likes

just fields like CreatedBy, LastChangedBy etc.

JessieCheah
Product and Topic Expert
Product and Topic Expert

You can use the following annotations in your base view, the framework will then fill up the admin fields automatically.

@Semantics.user.createdBy: true

@Semantics.user.lastChangedBy : true

@Semantics.user.localInstanceLastChangedBy: true

@Semantics.systemDateTime.createdAt: true

@Semantics.systemDateTime.lastChangedAt: true

@Semantics.systemDateTime.LocalInstanceLastChangedAt: true

See example https://github.com/SAP-samples/abap-platform-fiori-feature-showcase/blob/ABAP-platform-cloud/src/%23...