cancel
Showing results for 
Search instead for 
Did you mean: 

Activity Function Module to update Date and status from EM to Transportation Managment

nitesh_hatizar
Participant
0 Kudos

Hi,

How to code activity function module to update date and status from EM to Transportation Managment.

I have done the following coding, and created the function module with reference to standard function module /SAPTRX/TMS_CHANGE_EXEC_INF.

I have removed hardcoding and maintained value in TVARVC table. How to debug

CONSTANTS: co_bo_tor_execinfo           TYPE rs38l_fnam VALUE '/SCMTMS/EXECINFO_PROCESS', "TMS Function Module name for create update execinfo

             lc_zletre0020               
TYPE rvari_vnam VALUE 'ZLETRE0020',

             lc_zletre0020_controlpar    
TYPE char30     VALUE 'ZLETRE0020_CONTROLPAR',

             lc_zletre0020_eventcod      
TYPE char30     VALUE 'ZLETRE0020_EVENTCOD',

             lc_zletre0020_eventcod_pgi  
TYPE char30     VALUE 'ZLETRE0020_EVENTCOD_PGI',

             lc_zletre0020_eventcod_zcont
TYPE char30     VALUE 'ZLETRE0020_EVENTCOD_ZCONT',

             lc_zletre0020_eventcod_pod  
TYPE char30     VALUE 'ZLETRE0020_EVENTCOD_POD',

             lc_zletre0020_rail_no       
TYPE char30     VALUE 'ZRAIL_NO',

             lc_zletre0020_seal_no       
TYPE char30     VALUE 'ZRAIL_SEAL',

             lc_zletre0020_import_po     
TYPE char30     VALUE 'ZIMPORT_PO',

             lc_zletre0020_zcont_seal    
TYPE char30     VALUE 'ZCONT_SEAL'.
* structure for RFC call

 
TYPES: BEGIN OF lty_act_info,

           tor_rootnode_id  
TYPE sesf_bo_node_id,          "Node ID

           tor_id           
TYPE char35,                   "Tor ID

           torstopuuid      
TYPE xstring,

           actual_date      
TYPE timestamp,                "Actual Date

           actual_tzone     
TYPE tznzone,                  "Actual time zone

           estimated_date   
TYPE timestamp,                "Estimate Date

           stop_loc_id      
TYPE char20,                   "Destination Location ID

           ext_res_id       
TYPE char35,

           expected_date    
TYPE timestamp,                "Expected Date

           event_code       
TYPE /saptrx/event_code,       "Internal Event Code

           evnt_reason      
TYPE /saptrx/ev_srctx,         "Event Reason

           event_source     
TYPE char1,                    "Source of event

           ref_event_code   
TYPE /saptrx/event_code,       "Reference Internal Code

           event_status     
TYPE char1,                    "Event Status

           gro_wei_val      
TYPE /saptrx/quantity_content, "Weight

           gro_wei_uni      
TYPE /saptrx/quantity_unit,    "Unit of Weight

           gro_vol_val      
TYPE /saptrx/quantity_content, "Volume

           gro_vol_uni      
TYPE /saptrx/quantity_unit,    "Unit of volume

           net_wei_val      
TYPE /saptrx/quantity_content, "Net weight

           net_wei_uni      
TYPE /saptrx/quantity_unit,    "Unit of Weight

           qua_pcs_val      
TYPE /saptrx/quantity_content, "Quantity

           qua_pcs_uni      
TYPE /saptrx/quantity_unit,    "Unit of Quantity

           datacs           
TYPE /saptrx/data_code_set,    "Data code set

           dataid           
TYPE /saptrx/data_code_id,     "Data code set ID

           event_reason_code
TYPE /saptrx/status_reason_code,"Event reason internal code

           sndcod           
TYPE /saptrx/ev_sndcod,         "Sender code set

           sndid            
TYPE /saptrx/ev_sndid,          "Sender Code ID

        
END OF lty_act_info.
* Contant Declaration

 
DATA: lv_param              TYPE                   /saptrx/function_param"Ativity Parameter

        lv_arg               
TYPE                   /saptrx/msg_var,         "Message Variable

        lv_pta_linked        
TYPE                   c LENGTH 1,

        lv_object            
TYPE                   c LENGTH 40,             "TOR ID

        lv_object_short      
TYPE                   c LENGTH 40,

        lv_exe_status        
TYPE                   c LENGTH 2,

        lv_cat               
TYPE                   c LENGTH 2,

        lv_location_start    
TYPE                   c LENGTH 20,

        lv_location_end      
TYPE                   c LENGTH 20,

        lv_in_background
(1)   TYPE                   c VALUE 'X',

        lv_queue_name        
TYPE                   trfcqnam,                "Name of tRFC queue

        lv_td_id             
TYPE                   /saptrx/uc_ut_id_quick"Web interface Transaction

        lv_langu             
TYPE                   sy-langu,                "System field

        lv_result            
TYPE                   boole_d,                 "Flag variable

        lv_date              
TYPE                   dats,                    "Date variable

        lv_time              
TYPE                   tims,                    "Time variable

        lv_tzone             
TYPE                   /saptrx/timezone,        "Time zone variable

        lv_rail_no           
TYPE                   c LENGTH 30,             "Rail number

        lv_rail_seal         
TYPE                   c LENGTH 30,             "Rail seal number

        lv_zcont_seal        
TYPE                   c LENGTH 30,             "Container seal

        lv_import_po         
TYPE                   c LENGTH 30,             "Import order
* local structure declaration

        ls_tor_actual_em_data
TYPE                   lty_act_info,             "Structure for RFC call

        ls_request           
TYPE                   /saptrx/bapi_eh_request_id," BAPI structure for Event Handler retrieval ID'S

        ls_eh_hdr            
TYPE                   /saptrx/eh_hdr_dyn,        "Event Handler header table w/ dynamic data

        ls_appsyst           
TYPE                   /saptrx/appsyst,           "Application systems configuration TABLE

        ls_tables            
TYPE                   /saptrx/eh_access_flags,   " EH data retrieval & access flag

        ls_eh_data           
TYPE                   /saptrx/eh_data,           "Event Handler Data Structures

        ls_header            
TYPE                   /saptrx/bapi_eh_hdr,       "BAPI structure for Event Handler header

        ls_evm_ref           
TYPE                   /saptrx/evm_tables,        "Structure of the whole set of Event Message DB tables

        ls_paralist          
TYPE                   zsparamlist,                "Structure for TVARVC


*  local internal table declaration

        lt_request           
TYPE                   /saptrx/bapi_eh_request_id_tab,    "Table type for EH request ID BAPI structure

        lt_header            
TYPE                   /saptrx/bapi_eh_hdr_tab,           "Table type for Event Handler header BAPI structure

        lt_paralist          
TYPE                   ztt_param_list,                    "Internal table for TVARVC

        lt_messages          
TYPE                   bapiret2_tab,                      "Error Messages

        lt_tor_actual_em_data
TYPE STANDARD TABLE OF lty_act_info,     "table for RFC call

        msg                  
TYPE                   c LENGTH 255,

        lo_evm_ref           
TYPE REF TO            /saptrx/cl_eh_event_msg_model,"Reference for Event Handler event msg process mode

        lo_readtvr           
TYPE REF TO            zcl_common_utilities.         "Reference of common  utilities class.



 
FIELD-SYMBOLS:

    <ls_ee_modify> 
TYPE /saptrx/evm_eem,                               "Modifications to Expected Event List

    <fs_parameters>
TYPE /saptrx/evm_par_stru,                          "Event Handler Parameters

    <fs_expev>     
TYPE /saptrx/eh_expev_dyn.                          "Event Handler expected event table


* Check if function module input parameter has value

 
CHECK i_eai-simulate_mode IS INITIAL.


*  Create refernce variable for ZCL_COMMON_UTILITES class

 
CREATE OBJECT lo_readtvr.


* Get value of TVARVC

 
CALL METHOD lo_readtvr->get_tvarvc_complete

   
EXPORTING

      iv_rvari_vnam
= lc_zletre0020

   
IMPORTING

      et_param_list
= lt_paralist.
* Read TVARVC value.

 
READ TABLE lt_paralist INTO ls_paralist WITH KEY name lc_zletre0020_eventcod.



 
IF sy-subrc = 0.
*Activity Parameter Processing

   
IF

     i_eai
-event_msg-hdr-evtid IN ls_paralist-range.



      lo_evm_ref ?= i_eai
-eh_model.


*   Get Expected Event Data

      ls_tables
-expev      = 'X'.

      ls_eh_data
= i_eai-eh_model->eh_data( ls_tables ).



     
IF sy-subrc = 0.

       
CALL METHOD lo_evm_ref->evm_data

         
IMPORTING

            e_evm_data
= ls_evm_ref.

     
ENDIF.

   
ENDIF.

 
ENDIF.
*In case of event with control parameter

 
READ TABLE lt_paralist INTO ls_paralist WITH KEY name = lc_zletre0020_eventcod_pgi.



 
IF sy-subrc = 0.
*Activity Parameter Processing
*   Get Expected Event Data

   
IF

     i_eai
-event_msg-hdr-evtid = ls_paralist-name.



      lo_evm_ref ?= i_eai
-eh_model.



      ls_tables
-expev      = 'X'.



      ls_eh_data
= i_eai-eh_model->eh_data( ls_tables ).



     
IF sy-subrc = 0.

       
CALL METHOD lo_evm_ref->evm_data

         
IMPORTING

            e_evm_data
= ls_evm_ref.

     
ENDIF.



     
LOOP AT ls_evm_ref-parameters ASSIGNING <fs_parameters> WHERE evt_guid = i_eai-event_msg-hdr-evt_guid.



       
IF <fs_parameters>-param_name = lc_zletre0020_rail_no.

          lv_rail_no
= <fs_parameters>-param_value.

       
ENDIF.

       
IF <fs_parameters>-param_name = lc_zletre0020_seal_no.

          lv_rail_seal
= <fs_parameters>-param_value.

       
ENDIF.

     
ENDLOOP.

   
ENDIF.

 
ENDIF.



 
READ TABLE lt_paralist INTO ls_paralist WITH KEY name lc_zletre0020_eventcod_zcont.



 
IF sy-subrc = 0.
*Activity Parameter Processing
*   Get Expected Event Data

   
IF

     i_eai
-event_msg-hdr-evtid = ls_paralist-name.



      lo_evm_ref ?= i_eai
-eh_model.



      ls_tables
-expev      = 'X'.



      ls_eh_data
= i_eai-eh_model->eh_data( ls_tables ).



     
IF sy-subrc = 0.

       
CALL METHOD lo_evm_ref->evm_data

         
IMPORTING

            e_evm_data
= ls_evm_ref.

     
ENDIF.



     
LOOP AT ls_evm_ref-parameters ASSIGNING <fs_parameters> WHERE evt_guid = i_eai-event_msg-hdr-evt_guid.



       
IF <fs_parameters>-param_name = lc_zletre0020_zcont_seal.

          lv_zcont_seal
= <fs_parameters>-param_value.

       
ENDIF.

     
ENDLOOP.

   
ENDIF.

 
ENDIF.



 
READ TABLE lt_paralist INTO ls_paralist WITH KEY name lc_zletre0020_eventcod_pod.



 
IF sy-subrc = 0.
*Activity Parameter Processing
*   Get Expected Event Data

   
IF

     i_eai
-event_msg-hdr-evtid = ls_paralist-name.



      lo_evm_ref ?= i_eai
-eh_model.



      ls_tables
-expev      = 'X'.



      ls_eh_data
= i_eai-eh_model->eh_data( ls_tables ).



     
IF sy-subrc = 0.

       
CALL METHOD lo_evm_ref->evm_data

         
IMPORTING

            e_evm_data
= ls_evm_ref.

     
ENDIF.



     
LOOP AT ls_evm_ref-parameters ASSIGNING <fs_parameters> WHERE evt_guid = i_eai-event_msg-hdr-evt_guid.



       
IF <fs_parameters>-param_name = lc_zletre0020_import_po.

          lv_import_po
= <fs_parameters>-param_value.

       
ENDIF.

     
ENDLOOP.

   
ENDIF.

 
ENDIF.


* : Object
* TOR ID

  lv_object       
= i_eai-event_msg-hdr-trxid.


* <1> Get Event Handler Data

  ls_eh_hdr
= i_eai-eh_model->get_eh_hdr( ).


* <2> Check application system to be called, and prepare

  e_return_code
= 1.

 
SELECT SINGLE * FROM /saptrx/appsyst INTO ls_appsyst

   
WHERE app_system_id = ls_eh_hdr-ao_system.

 
IF sy-subrc <> 0.

   
RETURN.

 
ENDIF.



  e_return_code
= 2.
** Check function is exsit or not.

 
CALL FUNCTION 'FUNCTION_EXISTS'

    DESTINATION ls_appsyst
-rfcdest

   
EXPORTING

      funcname          
= co_bo_tor_execinfo

   
EXCEPTIONS

      function_not_exist
= 1

     
OTHERS             = 2.

 
CHECK sy-subrc = 0.


* get tor ID
* if event updated from 'superior' Event, we need to
* read the evnthandler because msg_hdr id doesn't match in this case

 
IF i_eai-exp_event-eh_guid IS NOT INITIAL.

    ls_request
-eh_guid = i_eai-exp_event-eh_guid.

   
APPEND ls_request TO lt_request.



   
CALL FUNCTION '/SAPTRX/BAPI_EH_GET_DATA'

     
TABLES

        requestids         
= lt_request

        eventhandlerheaders
= lt_header

        bapireturn         
= lt_messages.

   
READ TABLE lt_header INTO ls_header INDEX 1.
******************************************************
* Provide transfer structure
******************************************************

    ls_tor_actual_em_data
-tor_id          = ls_header-trackingid.

 
ELSE.

    ls_tor_actual_em_data
-tor_id          = i_eai-event_msg-hdr-trxid.

 
ENDIF.

  ls_tor_actual_em_data
-expected_date   = i_eai-exp_event-event_exp_date.

  ls_tor_actual_em_data
-actual_date     = i_eai-event_msg-hdr-evttst.

  ls_tor_actual_em_data
-event_code      = i_eai-event_msg-hdr-int_ev_cod.

  ls_tor_actual_em_data
-actual_tzone    = i_eai-event_msg-hdr-evtzon.

  ls_tor_actual_em_data
-stop_loc_id     = i_eai-event_msg-hdr-locid1.

 
IF ls_tor_actual_em_data-torstopuuid  IS INITIAL.

    ls_tor_actual_em_data
-torstopuuid     = i_eai-exp_event-itemident.

 
ENDIF.

  ls_tor_actual_em_data
-evnt_reason     = i_eai-event_msg-hdr-srctx.

  ls_tor_actual_em_data
-event_reason_code = i_eai-event_msg-hdr-int_sr_code.

  ls_tor_actual_em_data
-event_source      = 'E'" External event

  ls_tor_actual_em_data
-event_status    = i_eai-exp_event-event_status.

 
IF ls_tor_actual_em_data-event_status IS INITIAL.

    ls_tor_actual_em_data
-event_status    = 'N'. "not expected

 
ENDIF.

  ls_tor_actual_em_data
-datacs          = i_eai-event_msg-hdr-datacs.

  ls_tor_actual_em_data
-dataid          = i_eai-event_msg-hdr-dataid.



  ls_tor_actual_em_data
-sndcod          = i_eai-event_msg-hdr-sndcod.

  ls_tor_actual_em_data
-sndid           = i_eai-event_msg-hdr-sndid.



 
APPEND ls_tor_actual_em_data TO lt_tor_actual_em_data.


* Create Qname (EM_Object_No')

 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

   
EXPORTING

     
input  = lv_object

   
IMPORTING

     
output = lv_object_short.

 
CONCATENATE 'EM_' lv_object_short INTO lv_queue_name.



 
CALL FUNCTION 'TRFC_SET_QUEUE_NAME'                       "#EC *

   
EXPORTING

      qname             
= lv_queue_name

   
EXCEPTIONS

      invalid_queue_name
= 1

     
OTHERS             = 2.



 
CALL FUNCTION 'TRFC_SET_QIN_PROPERTIES'

   
EXPORTING

      qin_name
= lv_queue_name.



 
IF lv_in_background = abap_true.
* <4> Call TM Asynchronously to create/update execinfo

   
CALL FUNCTION co_bo_tor_execinfo IN BACKGROUND TASK

      DESTINATION ls_appsyst
-rfcdest

     
EXPORTING

        it_tor_actual_em_data
= lt_tor_actual_em_data

     
EXCEPTIONS

        system_failure       
= 1 message msg

        communication_failure
= 2 message msg

        resource_failure     
= 3

       
OTHERS                = 4.

 
ELSE.
* <4> Call TM synchronously to create/update execinfo

   
CALL FUNCTION co_bo_tor_execinfo
*      DESTINATION ls_appsyst-rfcdest

     
EXPORTING

        it_tor_actual_em_data
= lt_tor_actual_em_data

     
TABLES

        et_return            
= lt_messages

     
EXCEPTIONS

        system_failure       
= 1 message msg
*       communication_failure = 2  MESSAGE msg

        resource_failure     
= 3

       
OTHERS                = 4.

 
ENDIF.

 
CASE sy-subrc.

   
WHEN 1.

     
WRITE: / 'EXCEPTION SYSTEM_FAILURE', msg.

   
WHEN 2.

     
WRITE: / 'EXCEPTION COMMUNICATION_FAILURE', msg.

   
WHEN 3.

     
WRITE: / 'EXCEPTION RESOURCE_FAILURE'.

 
ENDCASE.



  e_return_code
= sy-subrc.


* <5> Log the system ID (for commit).

  lv_result
= i_eai-eh_model->log_system_id( ls_eh_hdr-ao_system ).


ENDFUNCTION.

While configuring this custome fumction module its giving information message

"Interface of fuction module is incorrect,change the function module interface"

Regards

Nitesh

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Nitesh,

As Daniel mentioned, you have to interface correctly I_EAI in structure /SAPTRX/EM_ACTIVITY_INTERFACE.

Whether you have written a code in this model.

EH_MODEL

EVENT_MSG

RULE_ID

TASK

EXP_EVENT

SIMULATE_MODE

EH_ACTIVITY

EVENT_MSG_EXT

In my opinion, your parameter or sequence code interface or field length might be missing to interface correctly in FM.  Also ensure that you have captured the exception like below.

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(I_EAI) TYPE  /SAPTRX/EM_ACTIVITY_INTERFACE

*"  EXPORTING

*"     REFERENCE(E_RETURN_CODE) LIKE  SY-SUBRC

*"  EXCEPTIONS

*"      COMMUNICATION_FAILURE

*"      SYSTEM_FAILURE

Check and let me know.

Regards

GGOPII

former_member186607
Active Contributor
0 Kudos

Hi,

if you want to assign a function module to a rule set activity, it has to have a specific interface, which consists of importing parameter I_EAI and exporting parameter E_RETURN_CODE (like e.g. FM /SAPTRX/TMS_CHANGE_EXEC_INF).

Best regards, Daniel