Monday, September 18, 2017

SAP EM Tip: Sample code for coding your own rule set activities

Here is the code snippets but the full document with all the table details is located for download here.

1         Declarations

  DATAl_eh_data         TYPE /saptrx/eh_data,
        ls_hdr            TYPE /saptrx/eh_hdr_dyn,
        ls_cntrl          
TYPE /saptrx/eh_cntrl_dyn,
        lt_cntrl          
TYPE /saptrx/eh_cntrl_tab,
        l_eh_flags        
TYPE /saptrx/eh_access_flags,
        l_model           
TYPE REF TO /saptrx/cl_eh_event_msg_model,
        l_evm_data        
TYPE /saptrx/evm_tables,
        ls_evm_hdr        
TYPE /saptrx/evm_hdr_str,
        l_evt_guid        
TYPE /saptrx/ev_guid,
        ls_evmsg          
TYPE /saptrx/eh_evmsg_dyn,
        lt_eh_evmsg       
TYPE STANDARD TABLE OF /saptrx/eh_evmsg_dyn,
        l_parameters      TYPE /saptrx/evm_par_stru,
        l_param1          
TYPE /saptrx/function_param,
        l_arg_1           TYPE /saptrx/msg_var,
        ls_evm_header     TYPE /saptrx/evm_hdr_str,
        ls_bapi_cntrl     
TYPE /saptrx/eh_cntrl_dyn,
        ls_tspardc        
TYPE /saptrx/tspardc.

2         Retrieving Data

2.1       Retrieving Activity Parameters

  DATAl_param1          TYPE /saptrx/function_param,
        l_arg_1           TYPE /saptrx/msg_var,

* First parameter:
  l_param1 
i_eai-task-param_1.
* If parameter is a meta data element like <EVENT_MSG-HDR-TRXCOD> then:
  l_arg_1 
i_eai-eh_model->get_activity_meta_data(
                       i_eai 
i_eai
                       i_meta_data 
l_param1 ).

2.2       Retrieving EH Detail

  DATAl_eh_data         TYPE /saptrx/eh_data,
        l_eh_flags        TYPE /saptrx/eh_access_flags.


  l_eh_flags
-evm_ext =
  l_eh_flags
-evmsg   =
  l_eh_flags
-cntrl   'X'.
  l_eh_data 
i_eai-eh_model->eh_datal_eh_flags ).

2.3       Retrieving Event Message Detail

  DATAl_model           TYPE REF TO /saptrx/cl_eh_event_msg_model,
        l_evm_data        
TYPE /saptrx/evm_tables.

* get Event Message data
  l_model ?= i_eai
-eh_model.
  
CALL METHOD l_model->evm_data
    
IMPORTING
      e_evm_data 
l_evm_data.

3         Updating Data

3.1       Updating a Control Parameter

  DATAl_eh_data         TYPE /saptrx/eh_data,
        ls_cntrl          TYPE /saptrx/eh_cntrl_dyn,
        ls_bapi_cntrl     
TYPE /saptrx/eh_cntrl_dyn.

  LOOP AT l_eh_data-cntrl INTO ls_cntrl
   
WHERE param_name =  'ZEMC_UPDATE_QTY.
        ls_bapi_cntrl-param_value lv_update_qty.
        
CONDENSE ls_bapi_cntrl-param_value.
      ls_bapi_cntrl-update_ind  'U'.
      ls_bapi_cntrl
-eh_guid     l_eh_data-hdr-eh_guid.
      ls_bapi_cntrl
-param_value ls_cntrl-param_value.
      ls_bapi_cntrl
-param_name  ls_cntrl-param_name.
      ls_bapi_cntrl
-param_index ls_cntrl-param_index.
      ls_bapi_cntrl
-seq_nbr     ls_cntrl-seq_nbr.
      ls_bapi_cntrl-language
    sy-langu.
      ls_bapi_cntrl
-param_type  'C'.
      ls_bapi_cntrl
-param_length '15'.

* Add/change/delete control parameter
      
CALL METHOD i_eai-eh_model->set_cntrl_parameter
        
EXPORTING
          i_eh_cntrl 
ls_bapi_cntrl
        RECEIVING
          result     
lv_result.
  ENDLOOP.

No comments:

Post a Comment