Skip to Content
author's profile photo
Former Member

Function Module not working as required

Hi,

I am currently using a function module HR_FBN_GENERATE_SEND_EMAIL which sends mail to external sources from a standard SAP screen.

The fm seems to be working fine if its run from within a report program, but isnt executing when is run from within a PAI module.(code same in both).

Could anyone throw some light on a solution to this issue.

Also,this module doesnt seem to allow sending of mails on a specified date. How can i incorporate that or alternatively is there an existing fn module which will send mails out on a specified date with specified content?

Will def shell out loads of points to solutions that help...

Cheers,

Preethi...

Add comment
10|10000 characters needed characters exceeded

7 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Apr 30, 2007 at 02:31 PM

    Hello Preethi,

    Did you try to put that code on a FM separatetly? I mean, make the standard FM inside a Z FM and call the function from your PAI code, may work.

    To send the mails on specified date, try to use the Z FM with a job. Create a zprogram that calls the ZFM, then create the job!!!

    Cheers,

    Dont forget to reward

    Gabriel

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Apr 30, 2007 at 04:11 PM

    The module works perfectly when called from a preport prog but doesnt execute in the PAI ??!!

    Am still working on it...

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I've adopted an approach wherein i call the func mod in a report. But i'm still confused about how and why a function module that doesnt work in the PAI works perfectly in a report prog. Is there a background issue?

      This is theoretical i guess...so any help will def be rewarded for sure

  • author's profile photo
    Former Member
    Posted on Apr 30, 2007 at 02:28 PM

    u can alternatively use <b>SO_DOCUMENT_SEND_API1</b> functon module to send out the mails.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Apr 30, 2007 at 02:31 PM

    HI,

    Here is the code to send the mail from ABAP

    *&---------------------------------------------------------------------*
    *& Report  ZSENDEMAIL                                                  *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *& Example of sending external email via SAPCONNECT                    *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    REPORT  zsendemail                    .
    
    PARAMETERS: psubject(40) type c default  'Hello',
                p_email(40)   type c default 'test@sapdev.co.uk' .
    
    data:   it_packing_list like sopcklsti1 occurs 0 with header line,
            it_contents like solisti1 occurs 0 with header line,
            it_receivers like somlreci1 occurs 0 with header line,
            it_attachment like solisti1 occurs 0 with header line,
            gd_cnt type i,
            gd_sent_all(1) type c,
            gd_doc_data like sodocchgi1,
            gd_error type sy-subrc.
    
    data:   it_message type standard table of SOLISTI1 initial size 0
                    with header line.
    
    ***********************************************************************
    *START-OF-SELECTION.
    START-OF-SELECTION.
    
    Perform populate_message_table.
    
    *Send email message, although is not sent from SAP until mail send
    *program has been executed(rsconn01)
    PERFORM send_email_message.
    
    *Instructs mail send program for SAPCONNECT to send email(rsconn01)
    perform initiate_mail_execute_program.
    
    
    *&---------------------------------------------------------------------*
    *&      Form  POPULATE_MESSAGE_TABLE
    *&---------------------------------------------------------------------*
    *       Adds text to email text table
    *----------------------------------------------------------------------*
    form populate_message_table.
      Append 'Email line 1' to it_message.
      Append 'Email line 2' to it_message.
      Append 'Email line 3' to it_message.
      Append 'Email line 4' to it_message.
    endform.                    " POPULATE_MESSAGE_TABLE
    
    
    *&---------------------------------------------------------------------*
    *&      Form  SEND_EMAIL_MESSAGE
    *&---------------------------------------------------------------------*
    *       Send email message
    *----------------------------------------------------------------------*
    form send_email_message.
    * Fill the document data.
      gd_doc_data-doc_size = 1.
    
    * Populate the subject/generic message attributes
      gd_doc_data-obj_langu = sy-langu.
      gd_doc_data-obj_name  = 'SAPRPT'.
      gd_doc_data-obj_descr = psubject.
      gd_doc_data-sensitivty = 'F'.
    
    * Describe the body of the message
      clear it_packing_list.
      refresh it_packing_list.
      it_packing_list-transf_bin = space.
      it_packing_list-head_start = 1.
      it_packing_list-head_num = 0.
      it_packing_list-body_start = 1.
      describe table it_message lines it_packing_list-body_num.
      it_packing_list-doc_type = 'RAW'.
      append it_packing_list.
    
    * Add the recipients email address
      clear it_receivers.
      refresh it_receivers.
      it_receivers-receiver = p_email.
      it_receivers-rec_type = 'U'.
      it_receivers-com_type = 'INT'.
      it_receivers-notif_del = 'X'.
      it_receivers-notif_ndel = 'X'.
      append it_receivers.
    
    * Call the FM to post the message to SAPMAIL
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
           exporting
                document_data              = gd_doc_data
                put_in_outbox              = 'X'
           importing
                sent_to_all                = gd_sent_all
           tables
                packing_list               = it_packing_list
                contents_txt               = it_message
                receivers                  = it_receivers
           exceptions
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                others                     = 8.
    
    * Store function module return code
      gd_error = sy-subrc.
    
    * Get it_receivers return code
      loop at it_receivers.
      endloop.
    endform.                    " SEND_EMAIL_MESSAGE
    
    
    *&---------------------------------------------------------------------*
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
    *&---------------------------------------------------------------------*
    *       Instructs mail send program for SAPCONNECT to send email.
    *----------------------------------------------------------------------*
    form initiate_mail_execute_program.
      wait up to 2 seconds.
      if gd_error eq 0.
          submit rsconn01 with mode = 'INT'
                        with output = 'X'
                        and return.
      endif.
    endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM

    If you look at the function module, you will get the field to pass the date also

    Regards

    Sudheer

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Apr 30, 2007 at 03:31 PM

    Hi there,

    It has been touched on before but have you tried using a differenet function module like 'SO_NEW_DOCUMENT_ATT_SEND_API1' to send data within the email body and 'SO_DOCUMENT_SEND_API1' to send data as an attachment. Examples of which can be found on

    http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm

    Hope this helps

    Regards

    Mart

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 30, 2007 at 02:31 PM

    >>The fm seems to be working fine if its run from within a report program, but isnt executing when is run from within a PAI module.(code same in both).

    this might be due to a conflict in the COMMIT WORK between the PAI & function call.. you can make the function call as a BACKGROUND TASK in your PAI to separate the two workporcesses..

    ~Suresh

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 23, 2007 at 12:23 AM

    Try this. It will work in PAI.

    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

    <b>STARTING NEW TASK 'task'</b>

    EXPORTING

    -


    Regards

    Keshav

    Add comment
    10|10000 characters needed characters exceeded