ABAP - Keyword Documentation → ABAP RAP Business Objects → RAP - Behavior Definitions → RAP - BDL for Behavior Definitions → RAP - Managed and Unmanaged Behavior Definitions → RAP - EntityBehaviorDefinition → RAP - EntityBehaviorBody → RAP - RAP BO Operations → RAP - RAP BO Operation, Additions → 

    RAP - default function

    Syntax


    ... {default function [DefaultValuesFunctionName] [ external 'GetDefaultsForExtName'];}

    Description


    RAP BO operation addition that defines a RAP default values function for a RAP BO operation. A default values function defaults field values or input parameters for a RAP BO operation  on the user interface. An implementation in the RAP handler method FOR READ ... FOR FUNCTION ... is required. default function can be used for the standard operation create, the create-by-association operation, actions, and functions.

    The name DefaultValuesFunctionName and the optional external name GetDefaultsForExtName of the default values function must start with GetDefaultsFor. The name of the default values function must be unique within the current BDEF. The external name does not have to be unique. If specified, it is exposed in the OData metadata.

    Default values functions are defined by adding the keywords {default function GetDefaultsForOperation;} behind the respective operation and parameter definition.

    Special rules apply to this addition for each operation:

    create

    • A dedicated name after default function is optional. If specified, the name must be GetDefaultsForCreate.
    • An external name GetDefaultsForExtName is not possible.
    • A syntax diagram is available in the topic RAP - Standard Operations.

    create by association

    • default function must be specified in combination with create within curly brackets.
    • An external name GetDefaultsForExtName is possible.
    • A syntax diagram is available in the topic  RAP - Operations for Associations.

    RAP action

    • The default values function can default values for the input parameter for the action. As a prerequisite, the action must specify an input parameter InputParameter. Flat, deep, and deep table parameters are supported.
    • An external name GetDefaultsForExtName is possible.
    • A syntax diagram is available in the topic RAP - action.

    RAP function

    • The default values function can default values for the input parameter for the function. As a prerequisite, the function must specify an input parameter InputParameter. Flat, deep, and deep table parameters are supported.
    • An external name GetDefaultsForExtName is possible.
    • A syntax diagram is available in the topic RAP - function.

    Availability


    Hints

    • The defaulting of values takes place in an OData service only. When accessing an operation that has a default values function attached using ABAP EML, the default values function is not accessed and no default values are provided.
    • The RAP default values function can be triggered in ABAP EML like other RAP functions, using the READ ENTITIES ... EXECUTE statement.

    Further Information


    Example


    The following managed BDEF defines a default values function for the operations create, create-by-association, the RAP action InstanceAction, and the RAP function StaticFunction.

    managed implementation in class bp_demo_rap_default_values_fun unique;
    strict ( 2 );

    define behavior for DEMO_RAP_DEFAULT_VALUES_FUNC alias Root
    persistent table demo_dbtab_root
    lock master
    authorization master ( instance )
    {
      //Default values function for create
      create { default function GetDefaultsForCreate; }
      update;
      delete;
      field ( readonly : update ) key_field;

      //Default values function for create-by-association
      association _to_child
      { create { default function GetDefaultsForChild; } }

        //Default values function for action
        action InstanceAction parameter demo_cds_abstract_entity
          { default function GetDefaultsForAction; }

        //Default values function for static function
        static function StaticFunction parameter demo_cds_abstract_entity
          result [0..*] $self
          { default function GetDefaultsForStaticFunction; }
      }

      define behavior for DEMO_RAP_DEFAULT_VALUES_CHLD alias Child
      persistent table demo_dbtab_child
      lock dependent by _to_parent
      authorization dependent by _to_parent
      {
        update;
        delete;
        field ( readonly ) key_field;
        field ( readonly : update ) key_field_child;
        association _to_parent;
      }

    The default values function for the operation create is implemented in the ABAP behavior pool BP_DEMO_RAP_DEFAULT_VALUES_FUN. The RAP handler method GetDefaultsForCreate provides default values for the fields char_field and lchg_date_time.

    METHOD GetDefaultsForCreate. 
    LOOP AT df_create ASSIGNING FIELD-SYMBOL(<df_create>).
        INSERT INITIAL LINE INTO TABLE df_create_result
        ASSIGNING FIELD-SYMBOL(<df_create_result>).
     
        GET TIME STAMP FIELD DATA(lv_timestamp).
     
        <df_create_result> = VALUE #(
                             %cid   = <df_create>-%cid
                             %param = VALUE
                                 #( char_field   = 'Default Value'
                                    lchg_date_time = lv_timestamp ) ).
      ENDLOOP.
    ENDMETHOD.

    The effect is that in an OData service, when creating a new entity instance, the fields char_field and lchg_date_time are filled with default values.