A very common activity when working with RAP and Fiori Elements is the validation of user input. Unfortunately, validations are only ever carried out when saving and you often want to give the user feedback earlier - especially when using draft mode. What is the best way to do this? The way to go in this case is to use prechecks. So far all good, but unfortunately the wizard makes it a bit more difficult than necessary, because after defining the prechecks in the behavior definition (or the behavior projection, which I prefer to use) it generates 2 methods if you want to perform the same check for CREATE and UPDATE - e.g. that the customer number should always be filled.
define behavior for ZC_MyEntity alias Entity
{
use create ( augment, precheck );
use update ( augment, precheck );
use delete;
}
The following is generated here:
METHODS precheck_create FOR PRECHECK
IMPORTING entities FOR CREATE Entity.
METHODS precheck_update FOR PRECHECK
IMPORTING entities FOR UPDATE Entity.
However, a look at the documentation shows that there is a simpler way:
METHODS precheck FOR PRECHECK
IMPORTING entities_create FOR CREATE Entity
entities_update FOR UPDATE Entity.
So that you only have to go through one loop, you then pack the almost identical structures together.
METHOD precheck.
DATA(entities_check) = entities_create.
entities_check = VALUE #( BASE entities_check FOR entity_update IN entities_update
( CORRESPONDING #( entity_update ) ) ).
LOOP AT entities_check INTO DATA(entitiy_check).
ENDLOOP.
ENDMETHOD.
This approach saves code duplication and also makes maintenance easier.
If you use DRAFT, then, depending on the use case, you unfortunately still have to read the "unchanged fields" during the update, as only the delta (i.e. the changed fields) is transferred via a PATCH. This is hopefully done before the loop - you can find here my personal favorit on how to this.
I hope this helps you and makes your life easier - 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 |
---|---|
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
5 | |
3 | |
3 | |
3 |