I already wrote a small Post on Combination of Prechecks - but when using Prechecks in DRAFT- enabled scenarios, you'll face an other Problem: Updates only contain changed fields - how to deal with it?
First, we look at the definition. This can be done both at the level of the behavior definition and at the level of the behavior projection - I personally usually prefer this in the projection, as it makes sense to map the check again as a Determination on Save, so that a clean integrity of the BO is ensured:
define behavior for ZC_MyEntity alias Header
{
use create ( augment, precheck );
use update ( augment, precheck );
use delete;
...
}
After defining the behavior, we come to the method definition:
METHODS precheck FOR PRECHECK
IMPORTING entities_create FOR CREATE Header
entities_update FOR UPDATE header.
And yes: last but not least, implementation:
DATA(entities_check) = entities_create.
LOOP AT entities_update INTO DATA(entity_update).
READ ENTITIES OF ZC_MyEntity IN LOCAL MODE
ENTITY Header
ALL FIELDS WITH VALUE #( ( %tky = entity_update-%tky ) )
RESULT DATA(header_read).
IF lines( header_read ) = 0.
CONTINUE.
ENDIF.
APPEND INITIAL LINE TO entities_check ASSIGNING FIELD-SYMBOL(<entity_check>).
<entity_check> = CORRESPONDING #( header_read[ 1 ] ).
<entity_check> = CORRESPONDING #( BASE ( <entity_check> ) entity_update USING CONTROL ).
ENDLOOP.
LOOP AT entities_check INTO DATA(entity_check).
* Here are our checks!
ENDLOOP.
What do we do here?
Enjoy!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 |