cancel
Showing results for 
Search instead for 
Did you mean: 

Set Default Value in RAP Managed App (without draft)

Rajeshwari_09
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,098

Hi All,

I am working on custom List Report Fiori Elements App(Managed without draft). I want to default a date value in input field if its not provided by the user based on a status field.

Example:

IF Status = 'Yes' THEN Date Mandatory.

IF Status = 'No' THEN Date is optional & if left blank by user a default value has to assigned before Save.

I tried implementing the requirement using determination but it only works for Create and not for Update.

If I use Create and Update in my determination it goes into infinite loop.

Please Advise. Thank you.

ABAP RESTful Application Programming Model , SAP BTP, ABAP environment @Andre_Fischer @JessieCheah 

 

View Entire Topic
Ram9066
Explorer
0 Kudos

Hi,

Yes, determination goes to infinite loop and results in Runtime error when Update is mentioned in determination. Please avoid providing update.
Eg:

determination setdocdate on modify { field bukrs; create; update; }

There are 2 types of variants in determination. 
1. determination...on modify - which is used to set default values when new entry is created. It is just like PBO.

2. determination...on save - it triggers after save, Eg: any field values to be populated based on other input fields after save.

To set default values, below is sample code and logic can be written in respective determination method.

Eg: In this scenario, 3 fields should have default values to be set when a record created newly.

determination setdocdate on modify { field bukrs; create; }

 

  METHOD setdocdate.

    READ ENTITIES OF yi_rbkp IN LOCAL MODE
    ENTITY yi_rbkp
    FIELDS ( blart bldat budat )
    WITH CORRESPONDING #( keys )
    RESULT DATA(lt_bldat).

    SELECT SINGLE AccountingDocumentType
    FROM F_Mmim_Blart
    INTO @DATA(lv_blart)
    WHERE AccountingDocumentType = 'KR'.

    MODIFY ENTITIES OF yi_rbkp
    IN LOCAL MODE
    ENTITY yi_rbkp
    UPDATE FIELDS ( blart bldat budat )
    WITH VALUE #( FOR ls_bldat IN lt_bldat
                     ( %key = ls_bldat-%key
                       %tky = ls_bldat-%tky
                       %is_draft = ls_bldat-%is_draft
                       bldat = sy-datum
                       budat = sy-datum
                       blart = lv_blart
                       %control-bldat = if_abap_behv=>mk-on
                       %control-budat = if_abap_behv=>mk-on
                       %control-blart = if_abap_behv=>mk-on )
                )
              REPORTED DATA(date_reported)
              FAILED DATA(date_failed)
              MAPPED DATA(date_mapped).
  ENDMETHOD.




 

Rajeshwari_09
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you for your inputs. I tried to follow along the same steps. It works for Create Scenario but one scenario doesn't work in Update.

When I try to edit a record Where Status = 'No' & Expiration Date= 'Some_Value'. And I just empty out the Expiration field and try to save it.

In this case the determination does not trigger to set it to default value, And the record is saved with Expdate = 'empty'. I assume because Status field was not edited at all.

I  have defined validation & determination as follows:

validation ValidateExpdate on save { create; update; field Expdate; }

  • In this method I have set a check If Status = 'Yes' & Expdate IS INITIAL, Raise a error message to user. This makes Expdate Mandatory if Status = 'Yes'.

determination DefaultExpDate on modify { field Status; create; }

  • In this method I am trying to set the Default Value for ExpDate = 'Any_value'.

Please let me know if you have any other input. Thank you.