RAP Action and Determination

Actions

In RAP, actions are non-standard operations that can modify the data of a Business Object (BO) instance. These actions are defined in the Behavior Definition and implemented in the Behavior Implementation. 

There are different types of actions in RAP: 

  1. Non-Factory Actions:  

   – These actions are used to implement custom logic that changes the state of an existing business object instance.  

   – They are typically instance-bound, meaning they operate on a specific instance of a business object.  

   – Example: Approving a travel request or marking an order as shipped.  

  1. Factory Actions:  

   – These actions are used to create new instances of a business object.  

   – They can be either instance-bound or static.  

   – Example: Creating a new sales order or generating a new customer record.  

Instance-Bound Actions: Used to copy one or more BO instances and create new instances based on the copied data. 

Static Actions: Used to create instances with default values. 

In this scenario to copy the instance of the maeterial entity Defined the factory action 

Copymaterial and implemented in the behavior pool. 

 

       Define the actions in the behavior definition. 

Nayanakumar_0-1728032643454.png

1. Create the methods in the Behavior pool and define implementations. 

 

 

METHODS copyMaterial FOR MODIFY
IMPORTING keys FOR ACTION znp_i_material~copyMaterial.

METHOD copyMaterial.
DATA : lt_material TYPE TABLE FOR CREATE znp_i_material,
lt_mitem TYPE TABLE FOR CREATE znp_i_material_mitem.

READ TABLE keys ASSIGNING FIELD-SYMBOL(<ls_keys>) WITH KEY
%cid = ‘ ‘.
ASSERT <ls_keys> IS NOT ASSIGNED.

READ ENTITIES OF znp_i_material IN LOCAL MODE
ENTITY znp_i_material
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_r_mat)
FAILED DATA(lt_fialed).

READ ENTITIES OF znp_i_material IN LOCAL MODE
ENTITY znp_i_material BY _mitem
ALL FIELDS WITH CORRESPONDING #( lt_r_mat )
RESULT DATA(lt_r_mitem).

LOOP AT lt_r_mat ASSIGNING FIELD-SYMBOL(<fs_r_mat>).
APPEND VALUE #( %cid = keys[ KEY entity matnr = <fs_r_mat>-matnr ]-%cid
%data = CORRESPONDING #( <fs_r_mat> EXCEPT matnr ) )
TO lt_material ASSIGNING FIELD-SYMBOL(<fs_material>).
<fs_material>-creationdate = cl_abap_context_info=>get_system_date( ).

APPEND VALUE #( %cid_ref = <fs_material>-%cid ) TO lt_mitem
ASSIGNING FIELD-SYMBOL(<fs_mitem>).

LOOP AT lt_r_mitem ASSIGNING FIELD-SYMBOL(<fs_r_mitem>)
USING KEY entity WHERE matnr = <fs_r_mat>-matnr.
APPEND VALUE #( %cid = <fs_material>-%cid && <fs_r_mitem>-werks
%data = CORRESPONDING #( <fs_r_mitem> EXCEPT matnr ) )
TO <fs_mitem>-%target.
ENDLOOP.
ENDLOOP.

MODIFY ENTITIES OF znp_i_material IN LOCAL MODE
ENTITY znp_i_material
CREATE FIELDS ( Baseunitofmeasure Descriptions
FlagMaterial Materialtype creationdate industrysector )
WITH lt_material
ENTITY znp_i_material
CREATE BY _mitem
FIELDS ( mmsta werks pstat perkz plifz )
WITH lt_mitem
MAPPED DATA(lt_mapped).
mapped-znp_i_material = lt_mapped-znp_i_material.
ENDMETHOD.

 

 

2.Defining the custom button in the projection view. 

Nayanakumar_1-1728033195631.png

3.Projecting the action to the  Fiori .

Nayanakumar_2-1728033239106.png

 

 

 

 When we select the instance then only the custom action is enabled.  

Nayanakumar_4-1728033335533.png

If we don’t select the instance action is not enabled. 

Nayanakumar_5-1728033414969.png

  • Select the record and click on the copy material button. 
  • It will create a new instance. 

All the data Material and Item data will be copied. Nayanakumar_6-1728033459150.pngNayanakumar_7-1728033512239.png

Determinations In RAP. 

Determination is an optional part of the BO behavior that modifies instances of BO based on trigger conditions. A determination is implicitly invoked by the BO’s framework if the trigger condition of the determination is fulfilled. Trigger conditions can modify operations Curd and modify fields. An invoked determination can compute data, modify entity instances according to the computation result and return messages to the consumer by passing them to be corresponding table in the Reported structure. 

       
The determination result must not change if the determination is executed several times under the same conditions, The execution order of determination is not fixed, if there is more than one determination triggered by than one determination triggered by the same condition, you cannot know which determination is executed first, Once a determination has been triggered, it must run independently from other determinations. 

  In this scenario update the status of material whether it will in the production or discontinued based on that the material will be flagged. 

 

Behavior definition. 

 

 

managed implementation in class zbp_i_material unique;
strict ( 2 );

define behavior for znp_i_material //alias <alias_name>
implementation in class zcl_np_material unique
persistent table znp_t_materials
lock master
authorization master ( instance )
early numbering
{
factory action copyMaterial [1];
internal action status;
create;
update;
delete;
field ( readonly ) Matnr;
association _MITEM { create ( features : instance ) ; }
mapping for znp_t_materials
{
matnr = matnr ;
creationdate = ersda ;
Descriptions = matkl ;
Baseunitofmeasure = meins ;
Materialtype = mtart ;
FlagMaterial = lvorm ;
industrysector = mbrsh ;
}

}

define behavior for znp_i_mitem //alias <alias_name>
implementation in class zcl_np_mitem unique
persistent table znp_t_mitems
lock dependent by _material
authorization dependent by _material
{
update;
delete;
field ( readonly ) Matnr;
action markmaterial result [1] $self;
determination updatestatus on modify {create; field mmsta; }
association _material;
mapping for znp_t_mitems
{
matnr = matnr;
mmsta = mmsta;
werks = werks ;
pstat = pstat;
perkz = perkz;
plifz = plifz;
}

}

 

 

 Defining and implementing method in behavior pool.

 

 

METHOD status.
TYPES : BEGIN OF ty_m,
FlagMaterial TYPE lvorm,
status TYPE char2,
END OF ty_m.

DATA : lt_mat TYPE TABLE OF ty_m.
READ ENTITIES OF znp_i_material IN LOCAL MODE
ENTITY znp_i_material
FIELDS ( matnr )
WITH CORRESPONDING #( keys )
RESULT DATA(lt_material).

READ ENTITIES OF znp_i_material IN LOCAL MODE
ENTITY znp_i_material BY _mitem
FIELDS ( mmsta )
WITH CORRESPONDING #( lt_material )
RESULT DATA(lt_mitem).

LOOP AT lt_material ASSIGNING FIELD-SYMBOL(<fs_material>).

LOOP AT lt_mitem ASSIGNING FIELD-SYMBOL(<fs_item>)
USING KEY entity
WHERE matnr = <fs_material>-matnr.
APPEND VALUE #( status = <fs_item>-mmsta ) TO lt_mat.
ENDLOOP.
LOOP AT lt_mat ASSIGNING FIELD-SYMBOL(<fs_mat>).
IF <fs_mat>-status = ‘A’.
<fs_material>-flagmaterial = ‘ ‘.
elseif <fs_mat>-status = ‘D’.
<fs_material>-flagmaterial = ‘X’.
ENDIF.
ENDLOOP.
ENDLOOP.

MODIFY ENTITIES OF znp_i_material IN LOCAL MODE
ENTITY znp_i_material
UPDATE FIELDS ( FlagMaterial )
WITH CORRESPONDING #( lt_material ).
ENDMETHOD.

METHOD updatestatus.
data it_material TYPE STANDARD TABLE of znp_i_material WITH UNIQUE HASHED KEY key components matnr.
it_material = CORRESPONDING #( keys discarding duplicates mapping matnr = matnr ).

MODIFY ENTITIES OF znp_i_material IN LOCAL MODE
ENTITY znp_i_material
EXECUTE status
from corresponding #( it_material ).
ENDMETHOD.

 

 

 he material is set to discontinued status By setting field value as ‘D’ then the field flag material is set to x and displayed as yes in the front end.

Nayanakumar_8-1728034545620.png

Nayanakumar_9-1728034562790.png

Nayanakumar_10-1728034580940.png

 

Nayanakumar_11-1728034599549.png

 

 

 

 

 

 

 

Scroll to Top