logo

Are you need IT Support Engineer? Free Consultant

Read & Create “Notes” in Freight Order – SAP Trans…

  • By sujay
  • 02/07/2026
  • 17 Views

This Blog is to Read & Create “Notes” in Freight Order from Code Logic.

 

Read Logic:

    DATA: lt_txc_root        TYPE /bobf/t_txc_root_k,
          lt_txc_text        TYPE /bobf/t_txc_txt_k,
          lt_txc_textcontent TYPE /bobf/t_txc_con_k,
          lt_root_keys       TYPE /bobf/t_frw_key,
          lt_text_keys       TYPE /bobf/t_frw_key.

*--Additional Receiver Emails from Notes.
        TRY.
            /scmtms/cl_common_helper=>get_do_keys_4_rba(
              EXPORTING
                iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
                iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-textcollection
                iv_do_node_key      = /bobf/if_txc_c=>sc_node-root
              IMPORTING
                ev_node_key         = DATA(lv_do_node_key) ).

            lo_srv_mgr->retrieve_by_association(
              EXPORTING
                iv_node_key    = /scmtms/if_tor_c=>sc_node-root
                it_key         = lt_key
                iv_association = /scmtms/if_tor_c=>sc_association-root-textcollection
                iv_fill_data   = abap_true
              IMPORTING
                et_data        = lt_txc_root
                eo_message     = lo_message ).

            /scmtms/cl_common_helper=>get_do_keys_4_rba(
              EXPORTING
                iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
                iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-textcollection
                iv_do_node_key      = /bobf/if_txc_c=>sc_node-text
                iv_do_assoc_key     = /bobf/if_txc_c=>sc_association-root-text
              IMPORTING
                ev_node_key         = DATA(lv_tc_text_node_key)
                ev_assoc_key        = DATA(lv_tc_root_text_assoc) ).

            LOOP AT lt_txc_root ASSIGNING FIELD-SYMBOL().
              APPEND VALUE #( key = -key ) TO lt_root_keys.
            ENDLOOP.

            lo_srv_mgr->retrieve_by_association(
              EXPORTING
                iv_node_key    = lv_do_node_key
                it_key         = lt_root_keys
                iv_association = lv_tc_root_text_assoc
                iv_fill_data   = abap_true
              IMPORTING
                et_data        = lt_txc_text
                eo_message     = lo_message ).

            /scmtms/cl_common_helper=>get_do_keys_4_rba(
              EXPORTING
                iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
                iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-textcollection
                iv_do_node_key      = /bobf/if_txc_c=>sc_node-text_content
                iv_do_assoc_key     = /bobf/if_txc_c=>sc_association-text-text_content
              IMPORTING
                ev_node_key         = DATA(lv_tc_cont_node_key)
                ev_assoc_key        = DATA(lv_tc_text_cont_assoc) ).

            LOOP AT lt_txc_text ASSIGNING FIELD-SYMBOL().
              IF -text_type="ZMAIL".
                APPEND VALUE #( key = -key ) TO lt_text_keys.
              ENDIF.
            ENDLOOP.

            lo_srv_mgr->retrieve_by_association(
              EXPORTING
                iv_node_key    = lv_tc_text_node_key
                it_key         = lt_text_keys
                iv_association = lv_tc_text_cont_assoc
                iv_fill_data   = abap_true
              IMPORTING
                et_data        = lt_txc_textcontent
                eo_message     = lo_message ).

*--Read the Additional Emails saved in Notes.
            LOOP AT lt_txc_textcontent ASSIGNING FIELD-SYMBOL().
              IF -text IS NOT INITIAL.
                SPLIT -text AT ',' INTO TABLE DATA(lt_add_emails).
              ENDIF.
            ENDLOOP.

          CATCH /bobf/cx_frw cx_root INTO DATA(lo_cx_root).
        ENDTRY.

 Create Logic:

TRY.
    DATA: lo_tra_mgr    TYPE REF TO /bobf/if_tra_transaction_mgr,
          lt_mod        TYPE /bobf/t_frw_modification,
          ls_mod        TYPE /bobf/s_frw_modification.

    DATA: lr_txc_root TYPE REF TO /bobf/s_txc_root_k,
          lr_txc_text TYPE REF TO /bobf/s_txc_txt_k,
          lr_txc_cont TYPE REF TO /bobf/s_txc_con_k.

    DATA: lv_txc_root_node_key  TYPE /bobf/obm_node_key,
          lv_txc_text_node_key  TYPE /bobf/obm_node_key,
          lv_txc_cont_node_key  TYPE /bobf/obm_node_key,
          lv_root_txc_assoc     TYPE /bobf/obm_assoc_key,
          lv_txc_root_txt_assoc TYPE /bobf/obm_assoc_key,
          lv_txc_txt_cont_assoc TYPE /bobf/obm_assoc_key.

    lo_tra_mgr = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).

    /scmtms/cl_common_helper=>get_do_keys_4_rba(
      EXPORTING
        iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
        iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-textcollection
        iv_do_node_key      = /bobf/if_txc_c=>sc_node-root
      IMPORTING
        ev_node_key         = lv_txc_root_node_key ).

    /scmtms/cl_common_helper=>get_do_keys_4_rba(
      EXPORTING
        iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
        iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-textcollection
        iv_do_node_key      = /bobf/if_txc_c=>sc_node-text
        iv_do_assoc_key     = /bobf/if_txc_c=>sc_association-root-text
      IMPORTING
        ev_node_key         = lv_txc_text_node_key
        ev_assoc_key        = lv_txc_root_txt_assoc ).

    /scmtms/cl_common_helper=>get_do_keys_4_rba(
      EXPORTING
        iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
        iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-textcollection
        iv_do_node_key      = /bobf/if_txc_c=>sc_node-text_content
        iv_do_assoc_key     = /bobf/if_txc_c=>sc_association-text-text_content
      IMPORTING
        ev_node_key         = lv_txc_cont_node_key
        ev_assoc_key        = lv_txc_txt_cont_assoc ).

    /scmtms/cl_common_helper=>get_do_keys_4_rba(
      EXPORTING
        iv_host_bo_key      = /scmtms/if_tor_c=>sc_bo_key
        iv_host_do_node_key = /scmtms/if_tor_c=>sc_node-textcollection
        iv_do_node_key      = /bobf/if_txc_c=>sc_node-root
        iv_do_assoc_key     = /bobf/if_txc_c=>sc_association-root-root
      IMPORTING
        ev_assoc_key        = lv_root_txc_assoc ).

    "-- Step 1: Create TXC Root node
    CREATE DATA lr_txc_root.
    lr_txc_root->key            = /bobf/cl_frw_factory=>get_new_key( ).
    lr_txc_root->parent_key     = iv_tor_root_key.
    lr_txc_root->root_key       = iv_tor_root_key.
    lr_txc_root->text_schema_id = 'DEFAULT'.
    lr_txc_root->text_exists_ind = abap_true.

    CLEAR ls_mod.
    ls_mod-node         = lv_txc_root_node_key.
    ls_mod-change_mode  = /bobf/if_frw_c=>sc_modify_create.
    ls_mod-association  = lv_root_txc_assoc.
    ls_mod-source_node  = /scmtms/if_tor_c=>sc_node-root.
    ls_mod-source_key   = iv_tor_root_key.
    ls_mod-root_key     = iv_tor_root_key.
    ls_mod-key          = lr_txc_root->key.
    ls_mod-data         = lr_txc_root.
    APPEND ls_mod TO lt_mod.

    "-- Step 2: Create TXC Text node with text_type = ZMAIL
    CREATE DATA lr_txc_text.
    lr_txc_text->key           = /bobf/cl_frw_factory=>get_new_key( ).
    lr_txc_text->parent_key    = lr_txc_root->key.
    lr_txc_text->root_key      = iv_tor_root_key.
    lr_txc_text->text_type="ZMAIL".
    lr_txc_text->language_code = sy-langu.

    CLEAR ls_mod.
    ls_mod-node         = lv_txc_text_node_key.
    ls_mod-change_mode  = /bobf/if_frw_c=>sc_modify_create.
    ls_mod-association  = lv_txc_root_txt_assoc.
    ls_mod-source_node  = lv_txc_root_node_key.
    ls_mod-source_key   = lr_txc_root->key.
    ls_mod-root_key     = iv_tor_root_key.
    ls_mod-key          = lr_txc_text->key.
    ls_mod-data         = lr_txc_text.
    APPEND ls_mod TO lt_mod.

    "-- Step 3: Create TXC Text Content node with email addresses
    CREATE DATA lr_txc_cont.
    lr_txc_cont->key          = /bobf/cl_frw_factory=>get_new_key( ).
    lr_txc_cont->parent_key   = lr_txc_text->key.
    lr_txc_cont->root_key     = iv_tor_root_key.
    lr_txc_cont->text         = iv_email_content. "e.g. '[email protected],[email protected]'

    CLEAR ls_mod.
    ls_mod-node         = lv_txc_cont_node_key.
    ls_mod-change_mode  = /bobf/if_frw_c=>sc_modify_create.
    ls_mod-association  = lv_txc_txt_cont_assoc.
    ls_mod-source_node  = lv_txc_text_node_key.
    ls_mod-source_key   = lr_txc_text->key.
    ls_mod-root_key     = iv_tor_root_key.
    ls_mod-key          = lr_txc_cont->key.
    ls_mod-data         = lr_txc_cont.
    APPEND ls_mod TO lt_mod.

    "-- Step 4: Call Modify on TOR Service Manager
    lo_srv_mgr->modify(
      EXPORTING
        it_modification = lt_mod
      IMPORTING
        eo_change       = DATA(lo_change)
        eo_message      = DATA(lo_message) ).

    "-- Step 5: Save via Transaction Manager
    lo_tra_mgr->save(
      IMPORTING
        ev_rejected = DATA(lv_rejected)
        eo_change   = lo_change
        eo_message  = lo_message ).

  CATCH /bobf/cx_frw INTO DATA(lo_cx_frw).
    MESSAGE lo_cx_frw->get_text( ) TYPE 'E'.

  CATCH cx_root INTO DATA(lo_cx_root).
    MESSAGE lo_cx_root->get_text( ) TYPE 'E'.

ENDTRY.

 

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us on WhatsApp!