cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP RAP - Instance Feature control for delete

mhappe
Participant
0 Kudos
4,112

I try to add some feature control to my RAP model. I only want to allow the deletion of draft items (item is a child of my root node) which don't have an active instance yet.

When disallowing deletion, new items (drafts) could not be deleted as well, so this is not a good option.

So adding feature control for the delete function could be an option:

delete( features : instance);

But within the feature control method "get_instance_features", I only want to allow deletion for items which doesn't have an active entity. How to achieve this?


Within the ABAP Fiori programming model with BOPF there was field available called "hasactiveentity".

andre.fischer Any ideas?

Thanks in advance!

Mattijs

Accepted Solutions (0)

Answers (4)

Answers (4)

Ramjee_korada
Active Contributor

Hello Happe,

Copying my proposal into Answer section so that you can accept it 🙂

I also see only option of writing custom logic to check active item exits or not.

Then , I am able to enable delete option based on "only draft" item or not.

METHOD get_instance_features.

      READ ENTITIES OF zrk_i_pur_req_h IN LOCAL MODE
       ENTITY _PRHead BY \_PRItem
       ALL FIELDS WITH CORRESPONDING #( keys )
       RESULT DATA(pr_item_read_result) FAILED failed.

    SELECT a~* FROM
       zrk_i_pur_req_i AS a
       INNER JOIN @pr_item_read_result AS b
       ON a~ObjectId = b~ObjectId
       AND a~ItemNo = b~ItemNo
       INTO TABLE @DATA(lt_active_items).

    IF sy-subrc = 0.

    result =  VALUE #( for <fs_key> in keys (  %tky = <fs_key>-%tky
                                               %delete  = COND #( when line_exists( lt_active_items[ objectid = <fs_key>-ObjectId itemno = <fs_key>-itemno ] )
                                                                then if_abap_behv=>fc-o-disabled
                                                                ELSE if_abap_behv=>fc-o-enabled )
                                                                 ) ).

    ENDIF.

  ENDMETHOD.


Best wishes,

Ramjee Korada

mhappe
Participant
0 Kudos

Hi ramjee.korada ,

I Think your proposed solution is the way to do it. Using a virtual field is also not an option.

Thanks!

Kind Regards
Mattijs Happe

mhappe
Participant
0 Kudos

Hi André,

Unfortunately I tried this solution already, with this solution the delete option is only available in draft mode. In my situation I only want to have a delete option for items which are created in draft (for those items no data exists yet in the active database tables.). So I need to know for my child entity if it's already available in the active table. The external ID of the item is already determined so I'm not able to use that field. Otherwise I have to introduce a kind of help field for it. In the BOPF model there was an attribute named hasactiveentity which we could use.

Disabling the delete option in my child entity is also not a good idea, as this prevents deletion of newly created items in draft as well:

Any other ideas are welcome 🙂

Thanks again!

Ramjee_korada
Active Contributor

Hello Happe,

Did you find any solution or standard way?

I also see only option of writing custom logic to check active item exits or not.

Then , I am able to enable delete option based on "only draft" item or not.

  METHOD get_instance_features.

      READ ENTITIES OF zrk_i_pur_req_h IN LOCAL MODE
       ENTITY _PRHead BY \_PRItem
       ALL FIELDS WITH CORRESPONDING #( keys )
       RESULT DATA(pr_item_read_result) FAILED failed.

    SELECT a~* FROM
       zrk_i_pur_req_i AS a
       INNER JOIN @pr_item_read_result AS b
       ON a~ObjectId = b~ObjectId
       AND a~ItemNo = b~ItemNo
       INTO TABLE @DATA(lt_active_items).

    IF sy-subrc = 0.

    result =  VALUE #( for <fs_key> in keys (  %tky = <fs_key>-%tky
                                               %delete  = COND #( when line_exists( lt_active_items[ objectid = <fs_key>-ObjectId itemno = <fs_key>-itemno ] )
                                                                then if_abap_behv=>fc-o-disabled
                                                                ELSE if_abap_behv=>fc-o-enabled )
                                                                 ) ).

    ENDIF.

  ENDMETHOD.

Best wishes,

Ramjee Korada

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

I am disabling the edit button im my RAP Generator UI when the job for generating the repository objects has been scheduled.

There the action %action-edit is disabled or enabled based on the content of the field jobname in the entity rapbo.

But I assume you should be able to adapt it for your needs as follows:

%action-delete          = COND #( WHEN rapbo-%is_draft = if_abap_behv=>mk-on
                                  THEN if_abap_behv=>fc-o-enabled
                                  ELSE if_abap_behv=>fc-o-disabled )

cloud-abap-rap/zdmo_bp_i_rapgeneratorbo.clas.locals_imp.abap at main · SAP-samples/cloud-abap-rap · ...

line 609 ff.

result = VALUE #( FOR rapbo IN rapbos
                    ( %tky                   = rapbo-%tky

                      %field-packagename    = COND #( WHEN rapbo-packagename IS INITIAL
                                                      THEN if_abap_behv=>fc-f-mandatory
                                                      ELSE if_abap_behv=>fc-f-read_only )
                      %field-namespace      = COND #( WHEN rapbo-packagename IS NOT INITIAL
                                                      THEN if_abap_behv=>fc-f-mandatory
                                                      ELSE if_abap_behv=>fc-f-read_only )
                      %action-edit          = COND #( WHEN rapbo-jobname IS INITIAL
                                                      THEN if_abap_behv=>fc-o-enabled
                                                      ELSE if_abap_behv=>fc-o-disabled )
                      %action-createbo      = COND #( WHEN rapbo-%is_draft = if_abap_behv=>mk-off AND
                                                           rapbo-jobname IS INITIAL
                                                      THEN if_abap_behv=>fc-o-enabled
                                                      ELSE if_abap_behv=>fc-o-disabled )
0 Kudos

Hi Andre,

Is there a similar option available in ABAP Programming model for Fiori?

Below annotation makes 'Delete' enable. But if the instance should not be deleted for any particular condition, is there any similar way as in RAP to control this standard delete function?

If there is none, then plan B is to disable DELETE and add custom action

Thanks

Shabnam