I want to create an action and pass a dynamic container value to it. I only knew how to create an action manually using the SAP GUI or the Webclient UI, but I don't know how to create it using abap coding. Therefore I tried to develop a class which can trigger an action. The following source code shows how to do this:
I defined a class with a method "CREATE_ACTION". This method has the following parameters:
The following source code shows how to do this:
METHOD create_action.
INCLUDE:
crm_objectservices_con.
DATA:
lr_action_context TYPE REF TO cl_doc_context_crm_order,
lr_action TYPE REF TO if_actions_ppf,
lv_changed TYPE crmt_boolean,
lr_object_pool TYPE REF TO cl_object_pool,
lt_trigger_if TYPE ppftactv,
lr_trigger_if TYPE REF TO if_action_ppf,
lr_trigger TYPE REF TO cl_trigger_ppf,
lv_found TYPE crmt_boolean,
lv_ttype TYPE ppfdtt,
lr_container TYPE REF TO cl_swj_ppf_container,
lv_subrc TYPE sysubrc,
lr_medium_if TYPE REF TO if_medium_ppf,
lr_medium TYPE REF TO cl_methodcall_ppf.
" check if header guid and name of the action definition is filled
IF iv_header_guid IS INITIAL OR
iv_ttype IS INITIAL.
RETURN.
ENDIF.
" Get Object Pool. The Object Pool is a singleton class which defines the current context. This object is used later when the actions are saved
lr_object_pool = cl_object_pool=>get_instance( ).
" Determine action context of the order. The action context contains all information of the active and inactive actions of an order
CALL FUNCTION 'CRM_ACTION_CONTEXT_CREATE'
EXPORTING
iv_header_guid = iv_header_guid
iv_object_guid = iv_header_guid
IMPORTING
ev_context = lr_action_context
EXCEPTIONS
no_actionprofile_for_proc_type = 1
no_actionprofile_for_item_type = 2
order_read_failed = 3
OTHERS = 4.
IF lr_action_context IS NOT BOUND.
RETURN.
ENDIF.
" This function module determines all actions of the order in the buffer
CALL FUNCTION 'CRM_ACTION_DETERMINE'
EXPORTING
iv_header_guid = iv_header_guid
iv_object_guid = iv_header_guid
iv_context = lr_action_context
iv_for_toolbar_only = ''
iv_no_detlog = ''
IMPORTING
ev_changed = lv_changed.
" Get all inactive actions of the order (Read it from the buffer)
lr_action = cl_service_factory_ppf=>get_actions_if( ).
lr_action->get_actions( EXPORTING io_context = lr_action_context
ip_active = ''
ip_inactive = 'X'
ip_smartform_processing = ''
ip_other_processing = 'X'
IMPORTING et_actions = lt_trigger_if ).
" Search specific action by action definition name
lv_found = ''.
LOOP AT lt_trigger_if INTO lr_trigger_if.
lr_trigger ?= lr_trigger_if.
lv_ttype = lr_trigger->get_ttype( ).
IF lv_ttype = iv_ttype.
lv_found = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF lv_found = 'X'.
" Create container object and set values to the container. Here you can set a key-value-pair to the container
" This container can be read when the action is executed
CREATE OBJECT lr_container.
lv_subrc = lr_container->if_swj_ppf_container~set_value( element_name = 'ZTEST'
data = 'TEST' ).
" Add the container object to the trigger (using the medium)
lr_medium_if = lr_trigger->get_medium( ).
lr_medium ?= lr_medium_if.
lr_medium->if_medium_container_ppf~set_container( ii_container = lr_container ).
" If you activate the trigger the schedule and the starting conditions are checked. If all conditions are ok the action will be executed
lr_trigger->if_action_ppf~activate( ).
" Save trigger. This step is needed, because an action that can not be executed because for example the starting condition is not okay will be saved to the
" database
lr_object_pool->save_guids( EXPORTING ip_guid = iv_header_guid ).
lr_object_pool->save_single( iv_header_guid ).
COMMIT WORK.
ENDIF.
ENDMETHOD.
Now you can test this using your own action definition. If you want to remove the action from the order you only have to set the trigger object to inactive.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
1 | |
1 |