cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate the presence of a mandatory subnode in a RAP BO?

bdrv
Explorer

Hi all,

I'm wondering what is the recommended approach to validate the presence of a mandatory subnode in a (managed, draft enabled) RAP BO.

It seems that to prevent the deletion of the last record, we have to assign a validation with delete trigger on the child node itself in the behavior definition. That validation is triggered correctly when we save (activate) the root, however I’m no longer able to read the deleted data of the imported keys parameter. The EML read operation is returning a failed entry with cause NOT_FOUND. We don’t need the child data to validate it, but we need at least its parent/root key to be able to do a retrieve by association from that parent/root and to check at least one other child record is still present.

I remember with the previous BOPF programming model you can assign a delete validation to a parent node and add the delete trigger on the child node(s). And to retrieve the old data we could use the iv_before_image parameter.

With our current system version, it seems we cannot assign this validation to the prepare action (ADT error: The assignment of a determination or validation of a child entity to Determine Action is not currently supported if a “delete” trigger is used).

  • Is it correct that in order to read the data that was already deleted from buffer, EML does not offer a similar “BEFORE_IMAGE” option and we should simply do a select from the database table? Or is there a more elegant option to find my parent/root key and be able to do my read by association?
  • Any other recommendations for this scenario? Note that we want to allow the users to delete the records of the subnode, as long as they keep at least one record or add a new one before activating the draft it is fine. So we do not want to prevent the actual delete action itself.

Many thanks in advance!

Kind regards,

Bjorn

patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Currently, there is no before image for deleted entities in the RAP runtime. In addition, reading the parent by association for a deleted entity does not work.

patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Does the following work for you? zi_pwid is the parent entity, pwidtext the child entity. The validation is defined in the child entity.

Using a precheck could also be an option: https://help.sap.com/docs/abap-cloud/abap-rap/operation-precheck?version=sap_btp

 

validation ValidateNumber on save ##NOT_ASSIGNED_TO_DETACT { create; update; delete; }  

METHOD validatenumber.
    READ ENTITY IN LOCAL MODE zi_pwid
    FROM CORRESPONDING #( keys MAPPING key_parent = key_child )
    RESULT DATA(all_parents).
    READ ENTITY IN LOCAL MODE zi_pwid
    BY \_pwidtext FROM CORRESPONDING #( all_parents )
    RESULT DATA(all_children).
    LOOP AT all_parents ASSIGNING FIELD-SYMBOL(<parent>).
      IF NOT line_exists( all_children[ KEY draft COMPONENTS %is_draft = <parent>-%is_draft  key_child = <parent>-key_parent ] ).
        APPEND CORRESPONDING #( <parent> ) TO failed-pwid.
        APPEND new_message_with_text( text =  'There must be one' ) TO reported-%other.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.

 

 

 

 

 

 

bdrv
Explorer
0 Kudos
Hi Patrick, The first read statement does not return any data in my case. Are you sure that read of the parent entity can work that way, since the validation is defined on the child node (on entity pwidtext in the behavior definition I assume), but those keys are the keys of the child we just removed, not the keys of the parent entity zi_pwid. Am I missing something? Many thanks for the assistance!
patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos

@bdrvMake sure in the first READ statement to add the MAPPING syntax

FROM CORRESPONDING #( keys MAPPING key_parent = key_child )

 

bdrv
Explorer
0 Kudos
Hi @patrick_winkler, I'm not sure what needs to be mapped? Since the validation is defined on the child node, the keys parameter contains the primary keys of the child node only, not the parent key(s). Mapping the primary key of the child node to the primary key of the parent node would not result in a valid result. The opposite could work, to read starting from the child using its "to_parent" association, however in this case it does not return any data since we're dealing with the delete trigger.
patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos
What is the key definition of the parent and child and what is the join condition between them?
bdrv
Explorer
0 Kudos
I'd say it's a basic scenario with UUIDs where our database tables have one UUID as primary key and in case of the child node there is foreign key to the parent's primary key. E.g. in the root table the primary key field is ROOT_UUID, in the child table the primary key field is CHILD_NAME_UUID (and the foreign key ROOT_UUID is present here as well). The join condition is simply realized via association to parent on $projection.ROOT_UUID = _parentAssoc.ROOT_UUID.
patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos
If the parent key is not part of the child key definition than you cannot apply my proposed coding because of the missing before image of the delete operation.
bdrv
Explorer
0 Kudos
I see what you mean. In this case, would you recommend adding the parent foreign key field as a second key field in the child entity, even though the current key definition is already unique? Or do you think that the solution to read the parent key of my deleted child entity via the db table, followed by a read by association to my mandatory child via EML is as good? I'm thinking about the potential rework adding the second key could bring, as for e.g. for error messages the %path needs to be filled, and I'm not sure that %tky was used everywhere throughout the whole BO. In your previous reply you mentioned currently there is no before image for RAP runtime, any idea if this is planned for future releases? Many thanks for the assistance!!
patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Not sure what to recommend. As for the possibility to read the before image of a deleted entity via EML: not on the roadmap. You could open an improvement request to track the progress: https://influence.sap.com/sap/ino/#/campaign/2911
Last comment: you could also use a precheck to prevent the deletion of the last entity instead of a validation: https://help.sap.com/docs/abap-cloud/abap-rap/operation-precheck?version=sap_btp. Still same problem with reading the parent.

Accepted Solutions (0)

Answers (1)

Answers (1)

bdrv
Explorer
0 Kudos

Hi Patrick,

The first read statement does not return any data in my case. Are you sure that read of the parent entity can work that way, since the validation is defined on the child node (on entity pwidtext in the behavior definition I assume), but those keys are the keys of the child we just removed, not the keys of the parent entity zi_pwid.

Am I missing something?

Many thanks for the assistance!