ABAP - Keyword Documentation → ABAP RAP Business Objects → RAP - Behavior Definitions → RAP - BDL for Behavior Definitions → RAP - Abstract Behavior Definitions → RAP - Entity Behavior Definition, Abstract BDEF → RAP - Entity Behavior Body, Abstract BDEF → 

    RAP - Associations, Abstract BDEF

    Syntax


    ... association [(mandatory:execute)] _Assoc [with hierarchy];

    Description


    Includes a CDS association in the hierarchical BDEF derived type. The keyword association is used for associations and for CDS compositions. An entity whose child entity is included in the same abstract BDEF must specify the respective composition using the keyword association. If no behavior is defined for a subnode, then the respective composition must not be specified.

    The optional addition mandatory:execute declares an association of an abstract BDEF as mandatory. It can be used for CDS compositions and for cross-BO associations, but not for to-parent associations. Whenever the abstract BDEF is used as an input parameter for a RAP action or a RAP function, a value must be supplied, that is, the %control flag must be set. Otherwise, a runtime error occurs. As a prerequisite, the addition with hierarchy must be used in the behavior definition header and with control must be specified for the entity behavior definition in question. In addition, the BDEF strict mode must be enabled. When using IN LOCAL MODE, mandatory:execute has no effect.

    The optional addition with hierarchy can be used for cross-BO associations that specify with hierarchy in the BDEF header. An association with this addition is handled like a composition: the target type is integrated (as structure or table, depending on the cardinality) into the source type. As a result, the association in question is included several times in the type structure. The definable structure thus generalizes from type tree to DAG (directed acyclic graph). Note that the addition with hierarchy must not be used for to-child associations or to-parent associations to avoid cyclical graphs.

    The association target of an association with the addition with hierarchy must be covered by an abstract BDEF with hierarchy. Typically, to-parent associations with hierarchy are used for local sub-structures, while cross-BO associations serve reuse.

    Type mappings to other DDIC types continue to be defined in the BDEF containing the respective entity. Thus, if a hierarchical type is defined with cross-BO associations, its mapping to a hierarchical DDIC type spreads out across multiple abstract BDEFs.

    Example


    The following abstract BDEF defines behavior for four nodes, including intra- and cross-BO associations.

    abstract;
    strict(2);
    with hierarchy;

    define behavior for DEMO_CDS_SCALAR_ROOT alias Root
    with control
    {
      association _sibling;

      association _item1;

      // key field, unwanted in dTypes
      field ( suppress ) key_field;

      deep mapping for demo_cds_scalar_1 corresponding
      {
        field1 = r_fd1;
        field2 = r_fd2;
        field3 = r_sib;

        sub _Item1 = sub_1;
      }
    }

    define behavior for DEMO_CDS_SCALAR_CHILD alias Child
    with control
    {
      // foreign key field for parent, unwanted in dTypes
      field ( suppress ) key_field, i1pfk;

      // hierarchy-enabled [*]-assoc to foreign entity
      association _i1_r2 with hierarchy;

      association _sub1;
      association _sub3;
      deep mapping for DEMO_CDS_SCALAR_3 corresponding
      {
        i1fd1 = i1_fd1;
        i1fd2 = i1_fd2;
        sub _sub1 = sub_1;
        sub _sub3 = sub_3;  // scalar (table)
        sub _i1_r2 = root2;  // cross-BO assoc [*] "with hierarchy"

      }
    }

    define behavior for DEMO_CDS_SCALAR_GRANDCHILD_1 alias Grandchild1
    with control
    {
      field ( suppress ) s1key, s1pfk, s1rfk;

      mapping for DEMO_CDS_SCALAR_5 corresponding
      {
        s1fd1 = s1_fd1;
        s1fd2 = s1_fd2;
      }
    }

    scalar entity DEMO_CDS_SCALAR_GRANDCHILD_2 field s3val;

    Example


    The following example demonstrates the effect of the attribute mandatory:execute.

    The abstract BDEF DEMO_CDS_ABSTRACT_ROOT_ME defines the association _child as mandatory:execute.

    abstract;
    strict ( 2 );
    with hierarchy;

    define behavior for DEMO_CDS_ABSTRACT_ROOT_ME alias Root
    with control
    {
      field ( mandatory : execute ) id, comp1;
      association ( mandatory : execute ) _child;
    }

    define behavior for DEMO_CDS_ABSTRACT_CHILD_ME alias Child
    with control
    {
      field ( mandatory : execute ) iid, comp2;
      association _root;
    }

    The managed BDEF DEMO_RAP_MANDATORY_EXEC_ASSOC defines an action Action1. This action specifies the abstract BDEFDEMO_CDS_ABSTRACT_ROOT_ME as deep output parameter.

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

    define behavior for DEMO_RAP_MANDATORY_EXEC_ASSOC
    persistent table demo_ddic_types
    lock master
    authorization master ( instance )
    {
      create;
      update;
      delete;

      field(readonly:update) id;

      action (authorization:none) Action1 deep parameter
                                            DEMO_CDS_ABSTRACT_ROOT_ME;
    }

    The ABAP class CL_DEMO_MANDATORY_EXECUTE_ASSO executes the action ACTION1. It sets the %control structure for the association _child to if_abap_behv=>mk-on. This is mandatory, since this association is marked as mandatory:execute in the abstract BDEF that is used as input parameter. If the %control structure were set to if_abap_behv=>mk-off or not provided at all, a runtime error would occur.

    Code Snippet:

    DATA: 
          "Derived type for abstract entity;
          par1 TYPE TABLE FOR ACTION IMPORT
            demo_rap_mandatory_exec_assoc~Action1.
     
        par1 = VALUE #( (
          id     = 'A'
          %param = VALUE #(
             %control = VALUE #(
                id     = if_abap_behv=>mk-on
                comp1  = if_abap_behv=>mk-on
                _child = if_abap_behv=>mk-on
                )
                _child   = VALUE #( (
                  %control = VALUE #(
                    iid   = if_abap_behv=>mk-on
                    comp2 = if_abap_behv=>mk-on ) ) ) )
                        ) ).
     
        "Executing Action1
        MODIFY ENTITY demo_rap_mandatory_exec_assoc
           EXECUTE Action1
           FROM par1
            MAPPED FINAL(ls_mapped2)
            REPORTED FINAL(ls_reported2)
            FAILED FINAL(ls_failed2).
     
      cl_demo_output=>display( `Action1 successfully called` ).