Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ME23N / ME9F - Messages - SOST - Change sender email

joo_gaia
Explorer
0 Kudos

Hi All

I have a request to change the sender email (according with a Z transparent table), when messages are issued from ME23N (purchase order) or ME9F (message output).

So, the sender email should follow business rules - in tcode SOST the sender email should be  the one that I have determined.

My question is how and where  can I create this rule?

After debugging I found the function module CONVERT_COMM_TYPE_DATA.


IF pi_mail_sender IS INITIAL.

* default sender

         swc_set_element lt_container 'AddressString'

                                      sy-uname.

       ELSE.

* other sender

         swc_set_element lt_container 'AddressString'

                                      pi_mail_sender.

       ENDIF.

       swc_set_element lt_container 'TypeID' 'B'.

There is no enhancement point in the fm CONVERT_COMM_TYPE_DATA.

Could you please advise?

Thanks in advance

Joao Gaia

1 ACCEPTED SOLUTION

JuanCarlosDelga
Contributor
0 Kudos

Hi Joao,

I solved the same problem doing the following.

The function CONVERT_COMM_TYPE_DATA return the sender in field pe_mail_sender  as a variable of type SWOTOBJID.


I call my function just after the function CONVERT_COMM_TYPE_DATA in the print program.

This is Business Object of type RECIPIENT, see SWO1 to see Business object definition,so you need to create your own object of this type.

I created a function group with the following TOP include.


TYPE-POOLS: szadr, abap.

INCLUDE <cntn01>.

And the function

This function change the sender to a given email passed in PI_ADDRESSSTRING.


*"*"Interfase local

*"  IMPORTING

*"     VALUE(PI_TYPEID) TYPE  SO_ESC_DES DEFAULT 'U'

*"     VALUE(PI_ADDRESSSTRING) TYPE  SO_NAME

*"     VALUE(PI_MAIL_SENDER) LIKE  SWOTOBJID STRUCTURE  SWOTOBJID

*"       DEFAULT SPACE

*"  EXPORTING

*"     VALUE(PE_MAIL_SENDER) LIKE  SWOTOBJID STRUCTURE  SWOTOBJID

*"  EXCEPTIONS

*"      SENDER_CREATION_FAILED

*"----------------------------------------------------------------------

  DATA: l_sender    TYPE swc_object.

  CLEAR pe_mail_rec_sender.

  swc_container lt_container.

  pe_mail_sender = pi_mail_sender.

  CHECK pi_addressstring IS NOT INITIAL.

* Creo un Objeto de Negocio RECIPIENT

  swc_create_object l_sender    'RECIPIENT' space.

  swc_set_element lt_container 'AddressString'

                              pi_addressstring.

  swc_set_element lt_container 'TypeID' pi_typeid.

  swc_call_method l_sender    'CreateAddress' lt_container.

  IF sy-subrc NE 0.

    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

            RAISING sender_creation_failed.

  ENDIF.

  swc_object_to_persistent l_sender pe_mail_sender.

Regards

JCD

6 REPLIES 6

karthikeyan_p3
Contributor
0 Kudos

Hi Joao,

I guess you may need to create a custom output type and write the logic to fill the sender email id.

Please find the below thread.

*****

Logic to fetch the user id from custom table

*****

SELECT SINGLE * FROM USR21

  INTO WA_USR21 WHERE BNAME = lv_user.

  ADDR_KEY-ADDRNUMBER = WA_USR21-ADDRNUMBER.  "VBDKA-ADRNR.

  ADDR_KEY-PERSNUMBER = WA_USR21-PERSNUMBER.  "VBDKA-ADRNP.

  ADDR_KEY-ADDR_TYPE  = VBDKA-ADDRESS_TYPE.   "VBDKA-ADDRESS_TYPE.

Thanks,

Karthikeyan

roberto_vacca2
Active Contributor
0 Kudos

HI.

You shouldn't use enhancement if sap already gives you a correct alternative. In your case you should create a Z* message type from NACE transaction, as business rules will often change .

SAPFM06P is the main program for printintg and sending from ME2* transaction.

EXIT_SAPLMEDRUCK_001 could be a valid exit . check it out.

Anyway you shouldn't make any changes to CONVERT_COMM_TYPE_DATA..

Hope to help.

Bye

JuanCarlosDelga
Contributor
0 Kudos

Hi Joao,

I solved the same problem doing the following.

The function CONVERT_COMM_TYPE_DATA return the sender in field pe_mail_sender  as a variable of type SWOTOBJID.


I call my function just after the function CONVERT_COMM_TYPE_DATA in the print program.

This is Business Object of type RECIPIENT, see SWO1 to see Business object definition,so you need to create your own object of this type.

I created a function group with the following TOP include.


TYPE-POOLS: szadr, abap.

INCLUDE <cntn01>.

And the function

This function change the sender to a given email passed in PI_ADDRESSSTRING.


*"*"Interfase local

*"  IMPORTING

*"     VALUE(PI_TYPEID) TYPE  SO_ESC_DES DEFAULT 'U'

*"     VALUE(PI_ADDRESSSTRING) TYPE  SO_NAME

*"     VALUE(PI_MAIL_SENDER) LIKE  SWOTOBJID STRUCTURE  SWOTOBJID

*"       DEFAULT SPACE

*"  EXPORTING

*"     VALUE(PE_MAIL_SENDER) LIKE  SWOTOBJID STRUCTURE  SWOTOBJID

*"  EXCEPTIONS

*"      SENDER_CREATION_FAILED

*"----------------------------------------------------------------------

  DATA: l_sender    TYPE swc_object.

  CLEAR pe_mail_rec_sender.

  swc_container lt_container.

  pe_mail_sender = pi_mail_sender.

  CHECK pi_addressstring IS NOT INITIAL.

* Creo un Objeto de Negocio RECIPIENT

  swc_create_object l_sender    'RECIPIENT' space.

  swc_set_element lt_container 'AddressString'

                              pi_addressstring.

  swc_set_element lt_container 'TypeID' pi_typeid.

  swc_call_method l_sender    'CreateAddress' lt_container.

  IF sy-subrc NE 0.

    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

            RAISING sender_creation_failed.

  ENDIF.

  swc_object_to_persistent l_sender pe_mail_sender.

Regards

JCD

0 Kudos

Hi JCD

I have the following sequence:

program Z*  ==> fm ME_PRINT_PO  ==>  fm CONVERT_COMM_TYPE_DATA  ==> program Z*

Would be correct if I insert your fm in the Z* program, after the ME_PRINT_PO?

And do I need to create something new at SWO1?

Thanks in advance.

João Gaia

0 Kudos

Hi Joao,

You must determine the new sender between the function CONVERT_COMM_TYPE_DATA and the function OPEN_FORM, the problem is that both are in the subroutine 'prepare_formular' called from function ME_PRINT_PO, so you need to create an enhancement (implicit or explicit).

Regards.

JCD

0 Kudos

Hi JCD

I was able to resolve it with your answer.

I created an enhancement point in the include MEDRUCK F1O - between the function CONVERT_COMM_TYPE_DATA and the function OPEN_FORM, as you said.

In the enhancemnet point I accessed EKKO to obtain ERNAM, and after I called the fm CONVERT_COMM_TYPE_DATA, passing the ERNAM to the parameter pi_mail_sender .

Thanks to all!


ENHANCEMENT Z_INCLUDE_LMEDRUCKF10.    "active version

*

*

*  Altera o SENDER do email, qdo Pedido é emitido pela ME9F

*

if sy-tcode eq 'ME9F' .

    if not intnast is initial.

       data: lv_po_creator type syuname,

             l_BUKRS       type BUKRS.

       clear  lv_po_creator.

*     busca usuario

       SELECT SINGLE BUKRS ERNAM

              FROM   EKKO

              INTO   (l_BUKRS, lv_po_creator)

              WHERE  EBELN = nast-objky.

       if sy-subrc eq 0 and l_BUKRS eq '151 '.

          CALL FUNCTION 'CONVERT_COMM_TYPE_DATA'

          EXPORTING

               pi_comm_type         = lvs_comm_type

               pi_comm_values       = lvs_comm_values

               pi_country           = lfa1-land1

               pi_repid             = xprogramm

               pi_snast             = intnast

               pi_mail_sender       = lv_po_creator "<-- this is the username of the new sender

          IMPORTING

               pe_itcpo             = itcpo

               pe_device            = xdevice

               pe_mail_recipient    = lvs_recipient

               pe_mail_sender       = lvs_sender

           EXCEPTIONS

               comm_type_not_supported   = 1

               recipient_creation_failed = 2

               sender_creation_failed    = 3

           OTHERS                        = 4.

           if sy-subrc <> 0.

*            Implement suitable error handling here

           endif.

       endif.

    endif.

endif.

 

Joao Gaia