cancel
Showing results for 
Search instead for 
Did you mean: 

RAP: Side Effect for child entity table

lars_kr
Participant
596

Hello Community,

So far, I have only ever applied side effects to individual fields. But can they also be used to create entire entities in child tables?

My Example:

sideeffect.PNG

In this example, I have a field of a root entity in the creation process. If something is entered in this field using the value help, for example. The table below (child entity) should be filled out. There may be several items that need to be entered here. Normally, of course, the user should click on the Create button and create the child entity themselves, but sometimes there is already data in the SAP system with which the table can be filled. 

regards,

Lars

 

UPDATE:

In the meantime, I came across this blog entry LINK which apparently had the same problem. Unfortunately, I am missing a few things to solve my problem.

I also get the correct lines from the database. Andre Fischer suggests the following solution there:

 

 

 

 

DATA create_nodes TYPE TABLE FOR CREATE ZDMO_R_RAPG_ProjectTP\_Node.  

MODIFY ENTITIES OF ZDMO_R_RAPG_ProjectTP IN LOCAL MODE               
ENTITY Node UPDATE FIELDS ( ) WITH update               
ENTITY Project CREATE BY \_Node FIELDS (  ) WITH create_nodes        
MAPPED  mapped        
FAILED  failed        
REPORTED reported.

 

 

 

Unfortunately, I am not an ABAP expert, so I am not yet fully aware of what the specification “WITH update” does here.

And what would be the correct specification of the side effect in the behavior definition?

 

 

 

side effects {
field Benutzername affects entity _ChildEntity;
}

 

 

 

Would this information be sufficient to trigger the side effect?

UPDATE 2:

I have implemented something that probably corresponds to the solution proposed by Andre Fischer. But I get an error message.

 

 

  DATA: lt_create_child TYPE TABLE FOR CREATE zi_antrag\_child.

  READ ENTITIES OF zi_antrag IN LOCAL MODE
         ENTITY antrag
             FIELDS ( Uuid User ) WITH CORRESPONDING #( keys )
     RESULT DATA(root).

  READ TABLE root INTO DATA(roots) INDEX 1.

  SELECT AGR_NAME FROM agr_users
    WHERE UNAME = -User
    INTO TABLE (roles).

  LOOP AT roles ASSIGNING FIELD-SYMBOL(<fs_roles>).

   lt_create_child = VALUE #( ( %cid_ref             = 'My%CID_1'
                                %is_draft            = if_abap_behv=>mk-on
                                %target = VALUE #( (
                                                      %cid  ='My%ItemCID_1'
                                                      Role = <fs_roles>-agr_name ) ) ) ).

   MODIFY ENTITIES OF zi_antrag IN LOCAL MODE
      ENTITY antrag CREATE BY \_child
          FIELDS ( Role ) with lt_create_child
    MAPPED DATA(ls_mapped)
    FAILED DATA(ls_failed)
    REPORTED DATA(ls_reported).

  ENDLOOP.

 

 

 

View Entire Topic
aldimitrov14
Explorer
0 Kudos

Hi @lars_kr,

Perhaps my answer is a little bit late but I've managed to do something similar in a different way, so perhaps I can share my experience with you.

In my scenario I have to prefill a Child Entity table with some entries whenever we create a draft instance. Keep in mind that this example only works with draft instances. 

The first step what I have done is to add an action that will prefill the data. This action is then represented as a button on the page. Here your approach is a little bit different, since you want to prefill it using when entering a field value.

 

  action fillChildTable;

 

 

After adding the action, I subscribe the action as a side effect on the child entity: 

 

  side effects { action fillChildTable affects entity _Child; }

 

In the implementation of the action to prefill the draft child entities I do the following: 

  1. Read the Child entity in Local Mode - to find out if it was prefilled already or not.
  2. Prefill the Child entity in draft mode.

The sample code looks something like that: 

 

  METHOD fillchildtable.
    READ ENTITIES OF entity IN LOCAL MODE
      ENTITY childentity
        ALL FIELDS WITH CORRESPONDING #( keys )
      RESULT DATA(lt_result)
      FAILED DATA(ls_failed)
      REPORTED DATA(ls_reported).

    IF lt_result IS INITIAL.

      DATA lt_table_for_create TYPE TABLE FOR CREATE entity\_childentity.

        APPEND VALUE #( %cid_ref = keys[ 1 ]-%cid_ref
                        %is_draft = keys[ 1 ]-%is_draft
                        %pid = keys[ 1 ]-%pid
                        %target = VALUE #( ( %cid = lv_cid
                                             %is_draft = keys[ 1 ]-%is_draft
                                             field = '123
                                             %pidparent = keys[ 1 ]-%pid
                                             %control-field = if_abap_behv=>mk-on ) ) ) TO lt_table_for_create.

      ENDLOOP.

      MODIFY ENTITIES OF entity IN LOCAL MODE
      ENTITY entity
         CREATE BY \_childentity FROM lt_table_for_create
      MAPPED DATA(lt_mapped).



    ENDIF.
  ENDMETHOD.

 

Here you should take into consideration a few fields from the keys structure, e.g. %PID which in this case will be your Draft UUID, as well the %CID and the %IS_DRAFT field - since I am creating entries in a draft scenario, it is always draft ( '01' ). It is required to also include the %PID and %IS_DRAFT fields so the RAP Framework knows that you are creating draft entities in local mode.

I've tried implementing something similar with determination on a field and side effects to this determination, however my determination was not triggered when changing the Draft entity, therefore I opted for a Action instead. To be honest it looks cleaner to me with a button, and the users also seems to like it. Perhaps it should also be possible to implement a similar solution with a determination + side effects.

Keep in mind that this implementation is done with unmanaged scenario with draft.