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: 

FM - SO_NEW_DOCUMENT_SEND_API1

Former Member
0 Kudos

Dear Experts,

I need to send the abap report output through email to the required people.

So i have used FM -   SO_NEW_DOCUMENT_SEND_API1.

But getting run time error on exection and the error is as follows :

In program "SAPFSSOA" the system tried to access field "SOLI" with length 0.

Partial field access to fields with length 0 is not allowed, however.

"OBJHEAD_PARAM_GET_INTERNAL" "(FORM)"

Let me know how to overcome this issue.

Regards,

Gururaj.

1 ACCEPTED SOLUTION

matt
Active Contributor

You should NOT be using this function module. Use classes CL_BCS and associated. Search for these classes and you will find many examples.

For the good of your programming career - ignore any answers involving so_new_document_send_api1.

16 REPLIES 16

FredericGirod
Active Contributor

Hi,

don't use FM, prefer Oo method.

Have a look to this doc : http://scn.sap.com/docs/DOC-42253

regards

Fred

0 Kudos

Hi Fred,

As per your advice, used OO method. The programis working fine, but not getting any mails in my inbox on executing the report.

Below is my code:

   DATA : obj_mime_helper  TYPE REF TO cl_gbt_multirelated_service ,
        obj_bcs         TYPE REF TO cl_bcs ,
        obj_doc_bcs     TYPE REF TO cl_document_bcs ,
        obj_recipient   TYPE REF TO if_recipient_bcs ,
        obj_sender      TYPE REF TO if_sender_bcs,
        w_status        TYPE bcs_rqst ,
        is_soli         TYPE soli ,
        it_soli         TYPE TABLE OF soli ,
        it_html         TYPE html_table ,
        it_listobj      TYPE table_abaplist.


* Perform the program and export the restult in memory.
SUBMIT ZST22_REPORT VIA SELECTION-SCREEN AND RETURN EXPORTING LIST TO MEMORY.

* Catch the memory of the report result.
CALL FUNCTION 'LIST_FROM_MEMORY'
  TABLES
    listobject = it_listobj
  EXCEPTIONS
    not_found  = 1
    OTHERS     = 2.

* Transform the report result in HTML format
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
  TABLES
    html       = it_html
    listobject = it_listobj.

* Put the HTML into the table of the mail.
it_soli = it_html.

* Create the main object of the mail.
CREATE OBJECT obj_mime_helper.

* Set the HTML body of the mail
CALL METHOD obj_mime_helper->set_main_html
  EXPORTING
    content     = it_soli
    filename    = ''
    description = 'Hello world'.

* Set the subject of the mail.
obj_doc_bcs = cl_document_bcs=>create_from_multirelated(
                i_subject          = 'Mail example'
                i_importance       = '9'                    " 1 / 5 / 9
                i_multirel_service = obj_mime_helper ).
obj_bcs = cl_bcs=>create_persistent( ).
obj_bcs->set_document(
           i_document = obj_doc_bcs ).


* Set the email address
obj_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string 'gururaj.zunjarwad@capgemini.com' ).
obj_bcs->add_recipient( i_recipient = obj_recipient ).


* Change the status.
MOVE 'N' TO w_status.
CALL METHOD obj_bcs->set_status_attributes
  EXPORTING
    i_requested_status = w_status.


* Send the mail.
obj_bcs->send( ).

* Commit Work.
IF sy-subrc EQ space.
  COMMIT WORK AND WAIT.
ELSE.
  ROLLBACK WORK.
ENDIF.

Please do help me out. thanks in advance.

regards,

Gururaj.

Former Member
0 Kudos

Hi Gururaj,

Refer the following specs for you FM.

Declaration for the FM.

DATA : WK_OBJHEAD     TYPE SOLI_TAB,

            WK_DOC_CHNG  TYPE SODOCCHGI1,

            I_RECLIST           TYPE  STANDARD TABLE OF  SOMLRECI1 ,

            I_OBJPACK         TYPE  STANDARD TABLE OF SOPCKLSTI1,

            I_OBJTXT             TYPE STANDARD TABLE OF SOLISTI1 ,

            I_OBJBIN             TYPE  STANDARD TABLE OF SOLISTI1 .

and while using the FM declare the values as follows.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

     EXPORTING

                 DOCUMENT_DATA              = WK_DOC_CHNG

                PUT_IN_OUTBOX                 = 'X'

                 SENDER_ADDRESS             = 'SAPADMIN'                "SY-UNAME    "

                 SENDER_ADDRESS_TYPE        = 'B'                         "'INT'"'SMTP'

       COMMIT_WORK                =           'X'    "COMMIT_WORK

**            IMPORTING

**                 SENT_TO_ALL                = SENT_TO_ALL

**                  NEW_OBJECT_ID              = NEW_OBJECT_ID

     TABLES

                 PACKING_LIST               = I_OBJPACK

                 OBJECT_HEADER              = WK_OBJHEAD

                 CONTENTS_BIN               = I_OBJBIN

                 CONTENTS_TXT               = I_OBJTXT

*                 CONTENTS_HEX               = CONTENTS_HEX

*                 OBJECT_PARA                = OBJECT_PARA

*                  OBJECT_PARB                = OBJECT_PARB

                 RECEIVERS                  = I_RECLIS

     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.

 

*  BREAK 11001413.

    IF sy-subrc <> 0.

           MESSAGE 'Error When Sending the File' TYPE 'E'.

ELSE.

      MESSAGE 'Mail Sent to the concern person!'  TYPE 'I' .

    ENDIF.

hope this will solve your problem, for me it worked fine.

Best Regards--

Tarun

0 Kudos

Hi Tarun,

Tried as per your advice, but on execution of the report, i'm getting error  - 'Error When Sending the File'. Do let me know how to fix this.

Regards,

Gururaj.

venkateswaran_k
Active Contributor
0 Kudos

Hi Gururaj,

Go to SOST, and let me know is your emails are appearing there?

Regards,

Venkat

0 Kudos

Hi Venkat,

Check SOST, I can find my mail but in ERROR status. So mail not sent. Attached screenshots for reference. Please let me know how to overcome this issue.

Error message when seen in Tab - "Recepient list" in SOST is  : Internal error: CL_SMTP_RESPONSE ESMTP error code is not known. 554 554 Relay rejected for policy re...

Regards,

Gururaj.

Former Member
0 Kudos

Dear Gururaj,

I also have an issue with email sent by SO_NEW_DOCUMENT_SEND_API1.
Som chinese words are in my mail body,My korean receivers don't recoganize it.

I  wrote <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> in my html mail.

And I change the code page of SMTP node through T-code SCOT.

Now the problem is continued.

Did you have any suggestion about it?

Former Member
0 Kudos

Hi Gururaj,

Prior sending the email the SAP Connect must be configured (SCOT is used to do the configs).

Alternatively you can change the SAPADMIN with you local user name i.e SYUNAME and your sender_address_type as INT

Ensure that your mail is configured

Use put_in_outbox = 'X' parameter of SO_NEW_DOCUMENT_ATT_SEND_API1, Check if RECEIVER-RETRN_CODE = 0 or not after the function module, Also check if the exception DOCUMENT_NOT_SENT is being raised or not, SCOT customizing INT enter domains to which u can send mail.

Regards--

Tarun

0 Kudos

Hi Tarun,

Can u let me know what configuration need to be done in transaction SCOT ?

Secondly , made changes as per your advice. Following is the code :

   CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

     EXPORTING
         DOCUMENT_DATA                = WK_DOC_CHNG
         PUT_IN_OUTBOX                   = 'X'
         SENDER_ADDRESS              = SYUNAME 

         SENDER_ADDRESS_TYPE    = 'INT' 
         COMMIT_WORK                     = 'X'                     
**   IMPORTING
**       SENT_TO_ALL                = SENT_TO_ALL
**       NEW_OBJECT_ID              = NEW_OBJECT_ID
     TABLES
         PACKING_LIST                = I_OBJPACK
         OBJECT_HEADER           = WK_OBJHEAD
         CONTENTS_BIN               = I_OBJBIN
         CONTENTS_TXT               = I_OBJTXT
*        CONTENTS_HEX               = CONTENTS_HEX
*        OBJECT_PARA                = OBJECT_PARA
*        OBJECT_PARB                = OBJECT_PARB
         RECEIVERS                  = I_RECLIST
     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.

IF sy-subrc <> 0.
  MESSAGE 'Error When Sending the File' TYPE 'E'.
ELSE.
  MESSAGE 'Mail Sent to the concern person!'  TYPE 'I' .
ENDIF.

Note : On execution, getting run-time error and below is the error analysis :

Error analysis
    An exception occurred. This exception will be dealt with in more detail
    below. The exception, assigned to the class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was
     not caught, which
     led to a runtime error. The reason for this exception is:
    The call to the function module "SO_DOCUMENT_SEND_API1" is incorrect:

    The function module interface allows you to specify only
    fields of a particular type under "SENDER_ADDRESS".
    The field "SY-UNAME" specified here is a different
    field type.

Please help me out. Thanks in advance.

Regards,

Gururaj.

Former Member
0 Kudos

Hi Gururaj,

Prior to config there are some prerequisites i.e the mail server in your installation must be SMTP-compatible, for text message services there is this data transfer service called SMS which could be defined in tcode SA14.

Precisely the SCOT configs are taken care by the basis guy, for your reference you can go through the following link for SMTP configuration.

http://help.sap.com/saphelp_nw04/helpdata/en/af/73563c1e734f0fe10000000a114084/content.htm

http://help.sap.com/saphelp_srm50/helpdata/en/ea/cb69245e44a04bb6567ee19f101746/content.htm

But I would suggest that you should take assistance of some experienced basis consultant prior configuring the SMTP for INT.

Do let me know if the problem occurs while the configs.

Best Regards--

Tarun

former_member209120
Active Contributor
0 Kudos

Hi Gururaj ,

Try like this

REPORT YTEST_DEMO.

*--------------------------------------------------------*

"  Data retrieval related declarations

*--------------------------------------------------------*

TYPES:

      BEGIN OF T_EMP_DAT,

        PERNR TYPE PA0001-PERNR,

        PERSG TYPE PA0001-PERSG,

        PERSK TYPE PA0001-PERSK,

        PLANS TYPE PA0001-PLANS,

        STELL TYPE PA0001-STELL,

      END OF T_EMP_DAT.

DATA:

      W_EMP_DATA TYPE T_EMP_DAT.

DATA:

      I_EMP_DATA TYPE STANDARD TABLE OF T_EMP_DAT.

*--------------------------------------------------------*

"  Mail related declarations

*--------------------------------------------------------*

"Variables

DATA :

    G_SENT_TO_ALL   TYPE SONV-FLAG,

    G_TAB_LINES     TYPE I.

"Types

TYPES:

    T_DOCUMENT_DATA  TYPE  SODOCCHGI1,

    T_PACKING_LIST   TYPE  SOPCKLSTI1,

    T_ATTACHMENT     TYPE  SOLISTI1,

    T_BODY_MSG       TYPE  SOLISTI1,

    T_RECEIVERS      TYPE  SOMLRECI1.

"Workareas

DATA :

    W_DOCUMENT_DATA  TYPE  T_DOCUMENT_DATA,

    W_PACKING_LIST   TYPE  T_PACKING_LIST,

    W_ATTACHMENT     TYPE  T_ATTACHMENT,

    W_BODY_MSG       TYPE  T_BODY_MSG,

    W_RECEIVERS      TYPE  T_RECEIVERS.

"Internal Tables

DATA :

    I_DOCUMENT_DATA  TYPE STANDARD TABLE OF T_DOCUMENT_DATA,

    I_PACKING_LIST   TYPE STANDARD TABLE OF T_PACKING_LIST,

    I_ATTACHMENT     TYPE STANDARD TABLE OF T_ATTACHMENT,

    I_BODY_MSG       TYPE STANDARD TABLE OF T_BODY_MSG,

    I_RECEIVERS      TYPE STANDARD TABLE OF T_RECEIVERS.

*--------------------------------------------------------*

"Start-of-selection.

*--------------------------------------------------------*

START-OF-SELECTION.

  PERFORM GET_DATA.

  PERFORM BUILD_XLS_DATA_TABLE.

*--------------------------------------------------------*

  "End-of-selection.

*--------------------------------------------------------*

END-OF-SELECTION.

  PERFORM SEND_MAIL.

*&--------------------------------------------------------*

  "Form  get_data from PA0001

*&--------------------------------------------------------*

FORM GET_DATA.

  SELECT PERNR

  PERSG

  PERSK

  PLANS

  STELL

  FROM PA0001

  INTO CORRESPONDING FIELDS OF TABLE I_EMP_DATA

  UP TO 4 ROWS.

ENDFORM.                    " get_data

*&---------------------------------------------------------*

"Form  build_xls_data_table

*&---------------------------------------------------------*

FORM BUILD_XLS_DATA_TABLE.

  "If you have Unicode check active in program attributes then

  "you will need to declare constants as follows.

  CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.

  CONSTANTS:

  CON_TAB  TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

  CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.

  CONCATENATE 'PERNR' 'PERSG' 'PERSK' 'PLANS' 'STELL'

  INTO  W_ATTACHMENT

  SEPARATED BY  CON_TAB.

  CONCATENATE CON_CRET

  W_ATTACHMENT

  INTO W_ATTACHMENT.

  APPEND W_ATTACHMENT TO I_ATTACHMENT.

  CLEAR  W_ATTACHMENT.

  LOOP AT I_EMP_DATA INTO W_EMP_DATA.

    CONCATENATE W_EMP_DATA-PERNR

    W_EMP_DATA-PERSG

    W_EMP_DATA-PERSK

    W_EMP_DATA-PLANS

    W_EMP_DATA-STELL

    INTO W_ATTACHMENT

    SEPARATED BY CON_TAB.

    CONCATENATE CON_CRET W_ATTACHMENT

    INTO W_ATTACHMENT.

    APPEND W_ATTACHMENT TO I_ATTACHMENT.

    CLEAR  W_ATTACHMENT.

  ENDLOOP.

ENDFORM.                    "build_xls_data_table

*&----------------------------------------------------------*

"Form  send_mail

"---------------

"PACKING LIST

"This table requires information about how the data in the

"tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to

"be distributed to the documents and its attachments.The first

"row is for the document, the following rows are each for one

"attachment.

*&-----------------------------------------------------------*

FORM SEND_MAIL .

  "Subject of the mail.

  W_DOCUMENT_DATA-OBJ_NAME  = 'MAIL_TO_HEAD'.

  W_DOCUMENT_DATA-OBJ_DESCR = 'Regarding Mail Program by SAP ABAP'.

  "Body of the mail

  PERFORM BUILD_BODY_OF_MAIL

  USING:SPACE,

  'Hi,',

  'I am fine. How are you? How are you doing ? '.

  "Write Packing List for Body

  DESCRIBE TABLE I_BODY_MSG LINES G_TAB_LINES.

  W_PACKING_LIST-HEAD_START = 1.

  W_PACKING_LIST-HEAD_NUM   = 0.

  W_PACKING_LIST-BODY_START = 1.

  W_PACKING_LIST-BODY_NUM   = G_TAB_LINES.

  W_PACKING_LIST-DOC_TYPE   = 'RAW'.

  APPEND W_PACKING_LIST TO I_PACKING_LIST.

  CLEAR  W_PACKING_LIST.

  "Write Packing List for Attachment

  W_PACKING_LIST-TRANSF_BIN = SPACE.

  W_PACKING_LIST-HEAD_START = 1.

  W_PACKING_LIST-HEAD_NUM   = 1.

  W_PACKING_LIST-BODY_START = G_TAB_LINES + 1.

  DESCRIBE TABLE I_ATTACHMENT LINES W_PACKING_LIST-BODY_NUM.

  W_PACKING_LIST-DOC_TYPE   = 'XXL'.

  W_PACKING_LIST-OBJ_DESCR  = 'Excell Attachment'.

  W_PACKING_LIST-OBJ_NAME   = 'XLS_ATTACHMENT'.

  W_PACKING_LIST-DOC_SIZE   = W_PACKING_LIST-BODY_NUM * 255.

  APPEND W_PACKING_LIST TO I_PACKING_LIST.

  CLEAR  W_PACKING_LIST.

  APPEND LINES OF I_ATTACHMENT TO I_BODY_MSG.

  "Fill the document data and get size of attachment

  W_DOCUMENT_DATA-OBJ_LANGU  = SY-LANGU.

  READ TABLE I_BODY_MSG INTO W_BODY_MSG INDEX G_TAB_LINES.

  W_DOCUMENT_DATA-DOC_SIZE = ( G_TAB_LINES - 1 ) * 255 + STRLEN( W_BODY_MSG ).

  "Receivers List.

  W_RECEIVERS-REC_TYPE   = 'U'.  "Internet address

  W_RECEIVERS-RECEIVER   = 'test.program@gmail.com'.

  W_RECEIVERS-COM_TYPE   = 'INT'.

  W_RECEIVERS-NOTIF_DEL  = 'X'.

  W_RECEIVERS-NOTIF_NDEL = 'X'.

  APPEND W_RECEIVERS TO I_RECEIVERS .

  CLEAR:W_RECEIVERS.

  "Function module to send mail to Recipients

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

      DOCUMENT_DATA              = W_DOCUMENT_DATA

      PUT_IN_OUTBOX              = 'X'

      COMMIT_WORK                = 'X'

    IMPORTING

      SENT_TO_ALL                = G_SENT_TO_ALL

    TABLES

      PACKING_LIST               = I_PACKING_LIST

      CONTENTS_TXT               = I_BODY_MSG

      RECEIVERS                  = I_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.

  IF SY-SUBRC = 0 .

    MESSAGE I303(ME) WITH 'Mail has been Successfully Sent.'.

  ELSE.

    WAIT UP TO 2 SECONDS.

    "This program starts the SAPconnect send process.

    SUBMIT RSCONN01 WITH MODE = 'INT'

    WITH OUTPUT = 'X'

    AND RETURN.

  ENDIF.

ENDFORM.                    " send_mail

*&-----------------------------------------------------------*

"      Form  build_body_of_mail

*&-----------------------------------------------------------*

FORM BUILD_BODY_OF_MAIL  USING L_MESSAGE.

  W_BODY_MSG = L_MESSAGE.

  APPEND W_BODY_MSG TO I_BODY_MSG.

  CLEAR  W_BODY_MSG.

ENDFORM.                    " build_body_of_mail

0 Kudos

This message was moderated.

0 Kudos

Hi Ramesh,

Implemented your code, but on exection, i just receive the pop-up message saying "

  Mail has been Successfully Sent". But there is no mail in my inbox nor in SOST

Do let me know.

Regards,

Gururaj.

mayur_priyan
Active Participant
0 Kudos

Hi,

FM SO_NEW_DOCUMENT_SEND_API1 is outdated.

Refer to report BCS_EXAMPLE_7 - BCS: Send E-Mail with Self-Created Excel Attachment in your system, this will be helpful.

matt
Active Contributor

You should NOT be using this function module. Use classes CL_BCS and associated. Search for these classes and you will find many examples.

For the good of your programming career - ignore any answers involving so_new_document_send_api1.

0 Kudos

If only people listened (sigh), we would have "Utopia" here itself