Skip to Content
author's profile photo Former Member
Former Member

Sending by email attached documents

Hi,

I need to send by email by means of a program the documents attached to a campaign (SAP CRM) for example.

I can use SO_NEW_DOCUMENT_ATT_SEND_API1 to send the documents as attachments by email but I need beforehand to somehow ‘read’ them .

If the file(s) was on the Application Server, I would do the following:

OPEN DATASET '/usr/zzz.doc' FOR INPUT IN BINARY MODE.

DO.

READ DATASET '/usr/zzz.doc' INTO objbin MAXIMUM LENGTH 255 actual length len.

APPEND <b>objbin</b>.

add len to tlen.

IF sy-subrc <> 0.

EXIT.

ENDIF.

ENDDO.

………………………………..

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

  • COMMIT_WORK = 'X'

TABLES

packing_list = objpack

  • object_header = objhead

contents_hex = <b>objbin</b>

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

So I suppose I have to obtain <b>objbin</b> by ‘reading’ the document, but I can’t find the function/class with which I can achieve this.

Thank you,

Mihai

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Jan 12, 2005 at 07:19 PM

    I am not really clear on your requirements. Are you looking at ways to read the CRM Campaign document attachments?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 12, 2005 at 08:47 PM

    Hi Mihai,

    The tables parameter 'CONTENTS_HEX' is an optional parameter. It is not required to pass this. All you have to do is to send your file contents to the tables parameter 'CONTENTS_TXT'.

    Hope this helps,

    Srinivas

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 13, 2005 at 05:44 AM

    Try this code.... This may help u out.......

    In this i have built attachment from internal table.

    i have seen your code.. instead of reading directly in binary mode use simple text and then use 'table_compress' function..

    for more understanding plz refer the code

    &----


    *& Report YPSR_BDC_CN01 *

    *& *

    &----


    *& *

    *& *

    &----


    REPORT yhrr_mail_payslip.

    ----


    • Declaration Part *

    ----


    TABLES : pv000,

    t549q,

    pa0001,

    v_t514d,

    hrpy_rgdir,

    pa0002,

    pa0105.

    DATA : BEGIN OF itab OCCURS 0,

    pernr LIKE pa0001-pernr,

    abkrs LIKE pa0001-abkrs,

    ename LIKE pa0001-ename,

    usrid_long LIKE pa0105-usrid_long,

    END OF itab.

    DATA : w_begda LIKE hrpy_rgdir-fpbeg,

    w_endda LIKE hrpy_rgdir-fpend.

    DATA : return LIKE bapireturn1 OCCURS 0 WITH HEADER LINE.

    DATA : p_info LIKE pc407,

    p_form LIKE pc408 OCCURS 0 WITH HEADER LINE,

    p_p_form LIKE pc408 OCCURS 0 WITH HEADER LINE.

    DATA : p_idx TYPE i,

    my_month TYPE i,

    str_my_month(2) TYPE c.

    DATA : w_cmonth(10) TYPE c.

    DATA : tab_lines TYPE i,

    att_type LIKE soodk-objtp.

    DATA : BEGIN OF p_index OCCURS 0,

    index TYPE i,

    END OF p_index.

    CONSTANTS:

    BEGIN OF f__ltype, "type of line

    cmd LIKE pc408-ltype VALUE '/:', "command

    txt LIKE pc408-ltype VALUE 's', "textline

    END OF f__ltype.

    CONSTANTS:

    BEGIN OF f__cmd, "commands

    newpage LIKE pc408-linda VALUE '<NEW-PAGE>',

    END OF f__cmd.

    DATA : p_list LIKE abaplist OCCURS 1 WITH HEADER LINE.

    ***********

    DATA : objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

    docdata LIKE sodocchgi1,

    objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

    objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

    reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE,

    objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

    ----


    • INITIALIZATION *

    ----


    INITIALIZATION.

    objbin = ' | '. APPEND objbin.

    objpack-head_start = 1.

    ----


    • SELECTION SCREEN *

    ----


    SELECTION-SCREEN BEGIN OF BLOCK bl1.

    SELECT-OPTIONS : s_abkrs FOR pv000-abkrs OBLIGATORY.

    PARAMETERS : s_pabrp LIKE t549q-pabrp OBLIGATORY.

    PARAMETERS : s_pabrj LIKE t549q-pabrj OBLIGATORY.

    SELECT-OPTIONS : s_pernr FOR pa0001-pernr.

    PARAMETERS : pay_var LIKE bapi7004-payslip_variant DEFAULT 'ZSUZ'

    OBLIGATORY.

    SELECTION-SCREEN END OF BLOCK bl1.

    ----


    • AT SELECTION-SCREEN *

    ----


    AT SELECTION-SCREEN.

    IF sy-ucomm ='ONLI'.

    IF s_pabrp > 12 OR s_pabrp < 1.

    MESSAGE e999(yhr) WITH 'Improper Payroll Period'.

    ENDIF.

    IF s_pabrp > 9.

    my_month = s_pabrp - 10 + 1.

    str_my_month = my_month.

    ELSE.

    my_month = s_pabrp + 3.

    str_my_month = my_month.

    ENDIF.

    SHIFT str_my_month LEFT DELETING LEADING space.

    SHIFT str_my_month RIGHT DELETING TRAILING space.

    TRANSLATE str_my_month USING ' 0'.

    CONCATENATE s_pabrj str_my_month '01' INTO w_begda.

    CALL FUNCTION 'HR_HCP_GET_LAST_DAY_OF_MONTH'

    EXPORTING

    im_date = w_begda

    IMPORTING

    • EX_DATE_IS_MONTHEND =

    ex_last_day_of_month = w_endda.

    SELECT pa0001pernr pa0001abkrs pa0001~ename

    INTO CORRESPONDING FIELDS OF TABLE itab

    FROM pa0001

    JOIN pa0000

    ON pa0000pernr EQ pa0001pernr

    JOIN hrpy_rgdir

    ON pa0001pernr EQ hrpy_rgdirpernr

    WHERE pa0001~pernr IN s_pernr

    AND pa0001~abkrs IN s_abkrs

    AND pa0000~stat2 EQ '3'

    AND pa0001~endda GE '99991231'

    AND pa0001~plans NE '99999999'

    GROUP BY pa0001pernr pa0001abkrs pa0001~ename.

    IF sy-subrc <> 0.

    MESSAGE e999(yhr) WITH 'No record(s) found.'.

    ENDIF.

    ENDIF.

    ----


    • START-OF-SELECTION *

    ----


    START-OF-SELECTION.

    WRITE : / 'Payroll Period/Year : ',str_my_month,'-',s_pabrj.

    WRITE : / 'System Date : ', sy-datum.

    WRITE : / 'System Time : ', sy-uzeit.

    WRITE : / 'User Name : ', sy-uname.

    WRITE : / sy-uline.

    LOOP AT itab.

    CLEAR : p_info, p_p_form, p_form, p_index, p_list, objbin,

    docdata, objtxt, objpack, reclist, tab_lines.

    REFRESH : p_p_form, p_form, p_index, p_list, objbin,

    objtxt, objpack, reclist.

    SELECT SINGLE * FROM hrpy_rgdir

    WHERE pernr EQ itab-pernr

    AND fpbeg GE w_begda

    AND fpend LE w_endda

    AND srtza EQ 'A'.

    IF sy-subrc <> 0.

    WRITE : / 'Payroll data not found for Employee : ' , itab-pernr.

    CONTINUE.

    ENDIF.

    CALL FUNCTION 'GET_PAYSLIP'

    EXPORTING

    employee_number = itab-pernr

    sequence_number = hrpy_rgdir-seqnr

    payslip_variant = pay_var

    IMPORTING

    return = return

    p_info = p_info

    TABLES

    p_form = p_form.

    CHECK return IS INITIAL.

    LOOP AT p_form WHERE linda EQ f__cmd-newpage

    AND ltype EQ f__ltype-cmd.

    p_index-index = sy-tabix.

    APPEND p_index.

    ENDLOOP.

    p_idx = 1.

    REFRESH p_p_form.

    APPEND LINES OF p_form FROM p_idx TO p_index-index TO p_p_form.

    p_idx = p_index-index.

    EXPORT p_p_form TO MEMORY ID '%%_P_FORM_%%'.

    EXPORT p_info TO MEMORY ID '%%_P_INFO_%%'.

    SUBMIT rpcedt_list_to_memory EXPORTING LIST TO MEMORY AND RETURN.

    CALL FUNCTION 'LIST_FROM_MEMORY'

    TABLES

    listobject = p_list.

    CALL FUNCTION 'TABLE_COMPRESS'

    • IMPORTING

    • COMPRESSED_SIZE =

    TABLES

    in = p_list

    out = objbin

    EXCEPTIONS

    OTHERS = 1.

    objhead = 'Objhead'.

    APPEND objhead.

    • prearing subject

    CONCATENATE w_endda(6)

    ' Payslip-' itab-ename0(28) '(' itab-pernr4(4) ')'

    INTO docdata-obj_descr.

    docdata-obj_name = 'Pay Slip'.

    docdata-obj_langu = sy-langu.

    objtxt = 'Pay Slip.'.

    APPEND objtxt.

    objtxt = docdata-obj_descr.

    APPEND objtxt.

    objtxt = 'Have a nice day.'.

    APPEND objtxt.

    • Write Packing List (Main)

    • 3 has been fixed becuase OBJTXT has fix three lines

    READ TABLE objtxt INDEX 3.

    docdata-doc_size = ( 3 - 1 ) * 255 + STRLEN( objtxt ).

    CLEAR objpack-transf_bin.

    objpack-head_start = 1.

    objpack-head_num = 0.

    objpack-body_start = 1.

    objpack-body_num = 3.

    objpack-doc_type = 'RAW'.

    APPEND objpack.

    • Create Message Attachment

    • Write Packing List (Attachment)

    att_type = 'ALI'.

    DESCRIBE TABLE objbin LINES tab_lines.

    READ TABLE objbin INDEX tab_lines.

    objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

    objpack-transf_bin = 'X'.

    objpack-head_start = 1.

    objpack-head_num = 0.

    objpack-body_start = 1.

    objpack-body_num = tab_lines.

    objpack-doc_type = att_type.

    objpack-obj_name = 'ATTACHMENT'.

    objpack-obj_descr = 'Attached Document'.

    APPEND objpack.

    • Create receiver list

    REFRESH reclist.

    CLEAR reclist.

    SELECT SINGLE * FROM pa0105

    WHERE pernr EQ itab-pernr

    AND subty EQ 'MAIL'

    AND usrid NE ''

    AND pa0105~endda GE '99991231'.

    IF sy-subrc = 0.

    reclist-receiver = pa0105-usrid.

    TRANSLATE reclist-receiver TO LOWER CASE.

    ELSE.

    WRITE : / 'Please maintain E-mail adress for Employee : ',

    itab-pernr.

    CONTINUE.

    ENDIF.

    reclist-rec_type = 'U'.

    APPEND reclist.

    • Send the document

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = docdata

    put_in_outbox = 'X'

    commit_work = 'X'

    • IMPORTING

    • SENT_TO_ALL =

    • NEW_OBJECT_ID =

    TABLES

    packing_list = objpack

    object_header = objhead

    contents_bin = objbin

    contents_txt = objtxt

    • CONTENTS_HEX =

    • OBJECT_PARA =

    • OBJECT_PARB =

    receivers = 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.

    WRITE : / 'Message Not Sent to : ', itab-pernr.

    ELSE.

    WRITE : / 'Message Sent to : ', itab-pernr.

    ENDIF.

    ENDLOOP.

    -


    If this help u out give me reward points

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 13, 2005 at 07:33 AM

    <b>Nablan</b>,

    Yes; to 'read' the attached documents and send them by email.

    <b>Srinivas</b>,

    I know that CONTENTS_TXT is for the body of the message.

    To 'build' the attachment one has to use CONTENTS_HEX.

    <b>Sagar</b>,

    I will look on the code .

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      I managed to solve it (apparently) so I think that others might be interested too

      System SAP CRM 3.1

      I used the following functions (starting from GUID of object)

      1. SKWG_OLS_BO_LINKS_GET

      2. SDOK_LOIOS_PHIOS_GET - Extended Context Resolution (Selection of Physical Documents)

      3. SDOK_PHIO_LOAD_CONTENT - Load Content of a Physical Object into an Internal Table

      5. SO_DOCUMENT_SEND_API1

      Message was edited by: Mihai Olaru

      Message was edited by: Mihai Olaru

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.