cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger an event with helper class /SCMTMS/CL_TOR_HELPER_EVENT

0 Kudos
3,406

hi,

in Tm embedded function module /SAPTRX/BAPI_EH_ADDEVENTMSG_02 does not exist any more. it was used to raise an event before. I found /SCMTMS/CL_TOR_HELPER_EVENT, method REPORT_EVENT instead, but it is unclear what the mandatory fields are. the below code has no syntax errors, but the event is not raised/visible in the FO.

        "get first location
        lo_srv_tor->retrieve_by_association(
          EXPORTING
                iv_node_key             = /scmtms/if_tor_c=>sc_node-root
                it_key                  = lt_fo_key
                iv_fill_data            = abap_true
                iv_association          = /scmtms/if_tor_c=>sc_association-root-stop_first

          IMPORTING
                eo_message              = lo_message
                et_data                 = lt_stop_first
                et_failed_key           = lt_failed_key ).

        "Move source location into variable
        READ TABLE lt_stop_first ASSIGNING FIELD-SYMBOL(<ls_stop_first>) INDEX 1.
        lv_src_loc = <ls_stop_first>-log_locid.
        lv_first_stop_key = <ls_stop_first>-key.

        APPEND VALUE #( target_key = lv_first_stop_key ) TO lt_first_stop_key.

        "Move today´s date into variable
        CONVERT DATE sy-datum INTO TIME STAMP lv_event_date_time TIME ZONE 'CET'.


        "Set event LOAD_BEGIN
        CALL METHOD /scmtms/cl_tor_helper_event=>report_event
          EXPORTING
            iv_event_code       = 'LOAD_BEGIN'
            iv_ref_event_code   = 'LOAD_BEGIN'
            it_tor_key          = lt_fo_key
            it_tor_root_stop    = lt_first_stop_key
            iv_event_status     = 'R'
*           it_tor_stop_item    =
           " io_modify           = 'X'
            iv_actual_date      = lv_event_date_time
            iv_actual_tz        = 'CET'
            iv_exec_info_source = 'T'
            iv_register_action  = 'X'
          IMPORTING
            et_failed_key       = lt_failed_key
            eo_message          = lo_message.
View Entire Topic

Arun,

thank you for your answer. It reminds me that I have to post the solution. Actually, I have managed to raise the event in a different way. I have first set the handling execution status on Stop level to "loaded" using the related standard action and that has raised a load_end event. I have tested it. It works perfectly well.

 METHOD SET_TOR_TO_STATUS.

    " This method does the following:
    " Check if there is a carrier (else error at status setting)
    " if input parameter IV_SET_LOADED is flagged ->
    " set the departure stop to "loaded" which sends a load_end event
    " set the header status to "loading in process"
    " if input parameter IV_SET_DEPARTED is flagged ->
    " set the departure stop to "departed" which sends a departure event
    " set the header status to "executed"

    DATA:

      lo_srv_tor         TYPE REF TO /bobf/if_tra_service_manager, "Package unit
      lo_tra_tor         TYPE REF TO /bobf/if_tra_transaction_mgr,
      lv_fo_key          TYPE /bobf/conf_key,
      lt_fo_key          TYPE /bobf/t_frw_key,
      lt_root            TYPE /scmtms/t_tor_root_k,
      lt_stop_first      TYPE /scmtms/t_tor_stop_k,
      lt_trackingheader  TYPE TABLE OF /saptrx/bapi_evm_header,
      ls_trackingheader  TYPE /saptrx/bapi_evm_header,
      lt_tracklocation   TYPE TABLE OF /saptrx/bapi_evm_locationid,
      ls_tracklocation   TYPE /saptrx/bapi_evm_locationid,
      lt_return          TYPE bapiret2_t,
      ls_return          TYPE bapiret2,
      lv_rejected        TYPE boole_d,
      lv_src_loc         TYPE /scmtms/source_location,
      lt_root_stop       TYPE /bobf/t_frw_key_link,
      lv_first_stop_key  TYPE /bobf/conf_key,
      lo_change          TYPE REF TO /bobf/if_tra_change,
      lt_failed_key      TYPE /bobf/t_frw_key,
      lv_event_date_time TYPE /scmtms/stop_plan_date,
      lr_param           TYPE REF TO /scmtms/s_tor_a_set_handl_exec,
      lt_first_stop_key  TYPE /bobf/t_frw_key.


    "Initiate service and transaction managers
    lo_srv_tor = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( /scmtms/if_tor_c=>sc_bo_key )."Srv Manager TOR object
    lo_tra_tor = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( )."Transaction Manager

    "Convert FO id to freight order key
    lv_fo_key = /scmtms/cl_tor_helper_root=>return_key_for_torid( iv_torid = iv_freight_order_id ).
    CHECK lv_fo_key IS NOT INITIAL.
    APPEND VALUE #( key = lv_fo_key ) TO lt_fo_key.

    "Read root header to check if the carrier is there
    lo_srv_tor->retrieve(
      EXPORTING
            iv_node_key             = /scmtms/if_tor_c=>sc_node-root
            it_key                  = lt_fo_key
            iv_fill_data            = abap_true
            iv_edit_mode            = /bobf/if_conf_c=>sc_edit_read_only
      IMPORTING
            eo_message              = DATA(lo_message)
            et_data                 = lt_root
            et_failed_key           = lt_failed_key ).

    CHECK lt_root IS NOT INITIAL.

    "if the carrier not there, issue an error message
    READ TABLE lt_root ASSIGNING FIELD-SYMBOL(<root>) INDEX 1.
    IF <root>-tspid IS INITIAL.
      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = 'E'
          cl     = 'ZTM'
          number = '006' "Spediteur fehlt
        IMPORTING
          return = ls_return
        EXCEPTIONS
          OTHERS = 1.

      APPEND ls_return TO lt_return.
      iv_sped_fehlt = 'X'.

    ELSE.

      "get first location
      lo_srv_tor->retrieve_by_association(
        EXPORTING
              iv_node_key             = /scmtms/if_tor_c=>sc_node-root
              it_key                  = lt_fo_key
              iv_fill_data            = abap_true
              iv_association          = /scmtms/if_tor_c=>sc_association-root-stop_first

        IMPORTING
              eo_message              = lo_message
              et_data                 = lt_stop_first
              et_key_link             = lt_root_stop
              et_failed_key           = lt_failed_key ).

      "Move source stop key into the variable
      READ TABLE lt_stop_first ASSIGNING FIELD-SYMBOL(<ls_stop_first>) INDEX 1.
      lv_first_stop_key = <ls_stop_first>-key.
      APPEND VALUE #( key = lv_first_stop_key ) to lt_first_stop_key.

      IF iv_set_to_loaded = 'X'.

          "Fill the parameters to set first stop to loaded
          CREATE DATA lr_param.
          lr_param->handling_exec_stop = /scmtms/if_tor_status_c=>sc_stop-handling_exec-v_loaded.
          lr_param->set_handl_exec_stop = abap_true.
          lr_param->disable_event_report = abap_false.
          lr_param->disable_recalc = abap_true.

          "Set handling execution status at stop level to "loaded"
          lo_srv_tor->do_action(
          exporting
            iv_act_key           = /scmtms/if_tor_c=>sc_action-stop-set_handling_execution
            it_key               = lt_first_stop_key
            is_parameters        = lr_param
          importing
            eo_change            = lo_change
            eo_message           = lo_message
            et_failed_key        = lt_failed_key
            et_failed_action_key = DATA(lt_failed_action_key) ).

          "set status "loading in process" at header level
          lo_srv_tor->do_action(
            EXPORTING
              iv_act_key      = /scmtms/if_tor_c=>sc_action-root-set_exm_status_in_loading
              it_key          = lt_fo_key
            IMPORTING
              et_failed_key   = lt_failed_key ).

       ELSEIF iv_set_to_departed = 'X'.

         "Fill the parameters to set first stop to departed
          CREATE DATA lr_param.
          lr_param->handling_exec_stop = /scmtms/if_tor_status_c=>sc_stop-handling_exec-v_departed.
          lr_param->set_handl_exec_stop = abap_true.
          lr_param->disable_event_report = abap_false.
          lr_param->disable_recalc = abap_true.

          "Set handling execution status at stop level to "departed"
          lo_srv_tor->do_action(
          exporting
            iv_act_key           = /scmtms/if_tor_c=>sc_action-stop-set_handling_execution
            it_key               = lt_first_stop_key
            is_parameters        = lr_param
          importing
            eo_change            = lo_change
            eo_message           = lo_message
            et_failed_key        = lt_failed_key
            et_failed_action_key = lt_failed_action_key ).

          "set status "executed" at header level
          lo_srv_tor->do_action(
            EXPORTING
              iv_act_key      = /scmtms/if_tor_c=>sc_action-root-set_exm_status_executed
              it_key          = lt_fo_key
            IMPORTING
              et_failed_key   = lt_failed_key ).

      ENDIF."loaded or departed

         IF lt_failed_key IS INITIAL.
           iv_fo_status_set = 'X'.
         ENDIF.

           lo_tra_tor->save(
               IMPORTING
                 ev_rejected         = lv_rejected
                 eo_change           = lo_change
                 eo_message          = lo_message
                 et_rejecting_bo_key = DATA(lt_rej_bo_key) ).

      ENDIF. "Spediteur vorhanden/nicht vorhanden

    ENDMETHOD.

RobToao
Discoverer
0 Kudos
We use this logic. But in some cases the status is not set. How can we proof this? The logic is asynchrone ...