Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Sschlegel
Participant
1,906

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?

  • Line 1: Here we define a variable that should finally contain ALL entries that we want to check
  • Line 3: We loop over the ENTITIES_UPDATE, as we have to read the other contents for these
  • Line 5: Now comes a READ ENTITIES - depending on where we implement our precheck, on the ZI_* or the ZC_*
  • Line 7: This is particularly important for DRAFT newcomers! We do not use %KEY, but %TKY - we may want to read the content of the DRAFT - and not what is only activated.
  • Line 10: As always, we should also make sure that there is already something and that we are not in the first change
  • Line 17: Now we combine "old values" and "new values" - we use the CONTROL flags that RAP provides us with instead of performing a manual comparison
  • Line 22ff: Now we can let off steam with all our magic 🙂

Enjoy!

 

 

 

Labels in this area