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: 

Email with attachment to different vendors

former_member296785
Participant
0 Kudos

Hi friends,

Please tell me how to send email with attached pdf file to Multiple vendors.

Foe me mail system is working perfectly, but the problem is the mail is going only for first vendor, In my requirement i want to send this to multiple vendors with Different data.

Thanks & Regards

sach.

6 REPLIES 6

former_member296785
Participant
0 Kudos

Can we use At end of statement to resolve this issue????

0 Kudos

If you are able to send the pdf  to one vendor then I think there is problem in your logic. Extract all the vendors for which you need to send based on your criteria into internal table and put your logic in this loop and send. if you are still facing the error please send the code you are using.

Former Member
0 Kudos

Can you post the code please?.

0 Kudos

TABLES : bsik,

          bsak,

          lfa1.

*types

TYPES : BEGIN OF ty_bsik,

           bukrs TYPE bsik-bukrs,

           lifnr TYPE bsik-lifnr,

           umsks TYPE bsik-umsks,

           umskz TYPE bsik-umskz,

           augdt TYPE bsik-augdt,

           augbl TYPE bsik-augbl,

           zuonr TYPE bsik-zuonr,

           gjahr TYPE bsik-gjahr,

           belnr TYPE bsik-belnr,

           bldat TYPE bsik-bldat,

           waers TYPE bsik-waers,

           blart TYPE bsik-blart,

           dmbtr TYPE bsik-dmbtr,

           sgtxt TYPE bsik-sgtxt,

         END OF ty_bsik.

TYPES : BEGIN OF ty_bsak,

           bukrs TYPE bsik-bukrs,

           lifnr TYPE bsik-lifnr,

           umsks TYPE bsik-umsks,

           umskz TYPE bsik-umskz,

           augdt TYPE bsik-augdt,

           augbl TYPE bsik-augbl,

           zuonr TYPE bsik-zuonr,

           gjahr TYPE bsik-gjahr,

           belnr TYPE bsik-belnr,

           bldat TYPE bsik-bldat,

           waers TYPE bsik-waers,

           blart TYPE bsik-blart,

           dmbtr TYPE bsik-dmbtr,

           sgtxt TYPE bsik-sgtxt,

         END OF ty_bsak.

TYPES : BEGIN OF ty_lfa1,

           kunnr TYPE lfa1-kunnr,

           name1 TYPE lfa1-name1,

           ort01 TYPE lfa1-ort01,

           adrnr TYPE lfa1-adrnr,

         END OF ty_lfa1.

TYPES : BEGIN OF ty_lfb1,

           lifnr TYPE lfb1-lifnr,

           bukrs TYPE lfb1-bukrs,

           tlfns TYPE lfb1-tlfns,

         END OF ty_lfb1.

TYPES : BEGIN OF ty_adr6,

           addrnumber TYPE adr6-addrnumber,

           persnumber TYPE adr6-persnumber,

           date_from  TYPE adr6-date_from,

           consnumber TYPE adr6-consnumber,

           smtp_addr  TYPE adr6-smtp_addr,

         END OF ty_adr6.

*internal table and work area

DATA : it_final TYPE TABLE OF zvnd_stmt,"ty_final,

        wa_final TYPE  zvnd_stmt,"ty_final,

        it_bsik  TYPE TABLE OF ty_bsik,

        wa_bsik  TYPE   ty_bsik,

        it_bsak  TYPE TABLE OF ty_bsak,

        wa_bsak  TYPE   ty_bsak,

        it_lfa1  TYPE TABLE OF ty_lfa1,

        wa_lfa1  TYPE   ty_lfa1,

        it_lfb1  TYPE TABLE OF ty_lfb1,

        wa_lfb1  TYPE   ty_lfb1,

        it_adr6  TYPE TABLE OF ty_adr6,

        wa_adr6  TYPE   ty_adr6.

DATA : fname TYPE  rs38l_fnam.

* Internal Table declarations

DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

       i_tline TYPE TABLE OF tline WITH HEADER LINE,

       i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,

       i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

* Objects to send mail.

       i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

       i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

       i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

       i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

* Work Area declarations

       wa_objhead TYPE soli_tab,

       w_ctrlop TYPE ssfctrlop,

       w_compop TYPE ssfcompop,

       w_return TYPE ssfcrescl,

       wa_doc_chng TYPE sodocchgi1,

       w_data TYPE sodocchgi1,

       wa_buffer TYPE string, "To convert from 132 to 255

* Variables declarations

       v_len_in LIKE sood-objlen,

       v_len_out LIKE sood-objlen,

       v_len_outn TYPE i,

       v_lines_txt TYPE i,

       v_lines_bin TYPE i.

DATA : file_to_send TYPE xstring,

        pdf_document TYPE solix_tab,

        it_docs TYPE STANDARD TABLE OF docs.

DATA : document TYPE REF TO cl_document_bcs.

DATA: wa_tdformat TYPE string,

wa_tdline TYPE string,

length TYPE i.

DATA : lv_final TYPE TABLE OF zvnd_stmt,

        wrk_final TYPE zvnd_stmt.

DATA : lv_val  TYPE i.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS   : s_bukrs FOR bsik-bukrs

                     OBLIGATORY NO INTERVALS NO-EXTENSION ,

                    s_date  FOR bsik-budat

                     OBLIGATORY NO INTERVALS NO-EXTENSION,

                    s_lifnr FOR bsik-lifnr.

SELECTION-SCREEN : END OF BLOCK b1.


START-OF-SELECTION.

   PERFORM db_selection. "database selection

   PERFORM fetch_data. "fetch output data

   IF it_final IS NOT INITIAL.

     PERFORM sf_display. "smartform and email

   ELSE.

     MESSAGE 'No record found' TYPE 'S'.

   ENDIF.



FORM db_selection .

   DATA : lv_date TYPE bsik-budat.

   lv_date = s_date-low.

   SELECT bukrs

          lifnr

          umsks

          umskz

          augdt

          augbl

          zuonr

          gjahr

          belnr

          bldat

          waers

          blart

          dmbtr

          sgtxt

          FROM bsik INTO TABLE it_bsik

          WHERE budat LE lv_date

          AND   bukrs IN s_bukrs

          AND   lifnr IN s_lifnr.

*  IF it_bsik IS NOT INITIAL.

   SELECT bukrs

          lifnr

          umsks

          umskz

          augdt

          augbl

          zuonr

          gjahr

          belnr

          bldat

          waers

          blart

          dmbtr

          sgtxt

          FROM bsak INTO TABLE it_bsak

*           FOR ALL ENTRIES IN it_bsik

*           WHERE bukrs = it_bsik-bukrs

*        and lifnr = it_bsik-lifnr  and

   WHERE  budat LE lv_date

     AND augdt GT lv_date

     AND   bukrs IN s_bukrs

     AND   lifnr IN s_lifnr.

   LOOP AT it_bsak INTO wa_bsak.

     APPEND wa_bsak TO it_bsik.

     CLEAR wa_bsak.

   ENDLOOP.

*

*  IF it_bsak IS NOT INITIAL.

   IF it_bsik IS NOT INITIAL.

     SELECT lifnr

            name1

            ort01

            adrnr

            FROM lfa1 INTO TABLE it_lfa1

*           FOR ALL ENTRIES IN it_bsak

*           WHERE lifnr = it_bsak-lifnr.

       FOR ALL ENTRIES IN it_bsik

            WHERE lifnr = it_bsik-lifnr.

     SELECT lifnr

            bukrs

            tlfns

            FROM lfb1 INTO TABLE it_lfb1

*           FOR ALL ENTRIES IN it_bsak

*           WHERE lifnr = it_bsak-lifnr

*           AND   bukrs = it_bsak-bukrs.

       FOR ALL ENTRIES IN it_bsik

            WHERE lifnr = it_bsik-lifnr

            AND   bukrs = it_bsik-bukrs.

     SELECT  addrnumber

             persnumber

             date_from

             consnumber

             smtp_addr

             FROM adr6 INTO TABLE it_adr6

             FOR ALL ENTRIES IN it_lfa1

             WHERE addrnumber = it_lfa1-adrnr.

   ENDIF.

*ENDIF.

ENDFORM.                    " DB_SELECTION

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

*&      Form  FETCH_DATA

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

*       text

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

*  -->  p1        text

*  <--  p2        text

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

FORM fetch_data .

*  LOOP AT it_bsak INTO wa_bsak.

   LOOP AT it_bsik INTO wa_bsik.

*    wa_final-zuonr = wa_bsak-zuonr.

*    wa_final-lifnr = wa_bsak-lifnr.

*    wa_final-bukrs = wa_bsak-bukrs.

*    wa_final-belnr = wa_bsak-belnr.

*    wa_final-blart = wa_bsak-blart.

*    wa_final-bldat = wa_bsak-bldat.

*    wa_final-dmbtr = wa_bsak-dmbtr.

*    wa_final-waers = wa_bsak-waers.

*    wa_final-sgtxt = wa_bsak-sgtxt.

     wa_final-zuonr = wa_bsik-zuonr.

     wa_final-lifnr = wa_bsik-lifnr.

     wa_final-bukrs = wa_bsik-bukrs.

     wa_final-belnr = wa_bsik-belnr.

     wa_final-blart = wa_bsik-blart.

     wa_final-bldat = wa_bsik-bldat.

     wa_final-dmbtr = wa_bsik-dmbtr.

     wa_final-waers = wa_bsik-waers.

     wa_final-sgtxt = wa_bsik-sgtxt.

     READ TABLE it_lfa1 INTO wa_lfa1

*    WITH KEY kunnr = wa_bsak-lifnr.

WITH KEY kunnr = wa_bsik-lifnr.

     IF sy-subrc = 0.

       wa_final-name1 = wa_lfa1-name1.

       wa_final-ort01 = wa_lfa1-ort01.

     ENDIF.

     READ TABLE it_lfb1 INTO wa_lfb1

*    WITH KEY lifnr = wa_bsak-lifnr

*             bukrs = wa_bsak-bukrs.

  WITH KEY lifnr = wa_bsik-lifnr

              bukrs = wa_bsik-bukrs.

     IF sy-subrc = 0.

       wa_final-tlfns = wa_lfb1-tlfns.

     ENDIF.

     READ TABLE it_adr6 INTO wa_adr6

     WITH KEY addrnumber = wa_lfa1-adrnr.

     IF sy-subrc = 0.

       wa_final-smtp_addr = wa_adr6-smtp_addr.

     ENDIF.

     APPEND wa_final TO it_final.

   ENDLOOP.

   CLEAR wa_final.

ENDFORM.                    " FETCH_DATA

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

*&      Form  SF_DISPLAY

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

*       text

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

*  -->  p1        text

*  <--  p2        text

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

FORM sf_display .

   SORT it_final BY lifnr.

   LOOP AT it_final INTO wa_final.

     wrk_final-zuonr = wa_final-zuonr.

     wrk_final-lifnr = wa_final-lifnr.

     wrk_final-bukrs = wa_final-bukrs.

     wrk_final-belnr = wa_final-belnr.

     wrk_final-blart = wa_final-blart.

     wrk_final-bldat = wa_final-bldat.

     wrk_final-dmbtr = wa_final-dmbtr.

     wrk_final-waers = wa_final-waers.

     wrk_final-sgtxt = wa_final-sgtxt.

     wrk_final-name1 = wa_final-name1.

     wrk_final-ort01 = wa_final-ort01.

     wrk_final-tlfns = wa_final-tlfns.

     wrk_final-smtp_addr = wa_final-smtp_addr.

     APPEND wrk_final TO lv_final.

     AT END OF lifnr.

       CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

         EXPORTING

           formname           = 'ZFI_VNDSTMT_SF'

         IMPORTING

           fm_name            = fname

         EXCEPTIONS

           no_form            = 1

           no_function_module = 2

           OTHERS             = 3.

       IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

       ENDIF.

       w_ctrlop-getotf = 'X'.

       w_ctrlop-no_dialog = 'X'.

       w_compop-tdnoprev = 'X'.

       CALL FUNCTION fname

         EXPORTING

           control_parameters = w_ctrlop

           output_options     = w_compop

           user_settings      = 'X'

           wa_out1            = wrk_final

         IMPORTING

           job_output_info    = w_return

         TABLES

           it_out             = lv_final

         EXCEPTIONS

           formatting_error   = 1

           internal_error     = 2

           send_error         = 3

           user_canceled      = 4

           OTHERS             = 5.

       IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

       ENDIF.

       i_otf[] = w_return-otfdata[].

       CALL FUNCTION 'CONVERT_OTF'

         EXPORTING

           format                = 'PDF'

           max_linewidth         = 132

         IMPORTING

           bin_filesize          = v_len_in

*       bin_file             = file_to_send

         TABLES

           otf                   = i_otf

           lines                 = i_tline

         EXCEPTIONS

           err_max_linewidth     = 1

           err_format            = 2

           err_conv_not_possible = 3

           OTHERS                = 4.

       IF sy-subrc <> 0.

       ENDIF.

       LOOP AT i_tline.

         TRANSLATE i_tline USING '~'.

         CONCATENATE wa_buffer i_tline INTO wa_buffer.

       ENDLOOP.

       TRANSLATE wa_buffer USING '~'.

       DO.

         i_record = wa_buffer.

         APPEND i_record.

         SHIFT wa_buffer LEFT BY 255 PLACES.

         IF wa_buffer IS INITIAL.

           EXIT.

         ENDIF.

       ENDDO.

       LOOP AT i_tline.

         CLEAR: wa_tdformat, length.

         wa_tdformat = i_tline-tdformat.

         length = STRLEN( wa_tdformat ).

         IF length < 2.

           CONCATENATE wa_tdformat 'hold' INTO wa_tdformat.

         ENDIF.

         WHILE wa_tdformat CA ' '.

           REPLACE ' ' WITH 'hold' INTO wa_tdformat.

         ENDWHILE.

         CLEAR: wa_tdline, length.

         wa_tdline = i_tline-tdline.

         length = STRLEN( wa_tdline ).

         IF length < 132.

           CONCATENATE wa_tdline 'hold' INTO wa_tdline.

         ENDIF.

         WHILE wa_tdline CA ' '.

           REPLACE ' ' WITH 'hold' INTO wa_tdline.

         ENDWHILE.

         CONCATENATE wa_buffer wa_tdformat wa_tdline INTO wa_buffer.

       ENDLOOP.

       WHILE wa_buffer CS 'hold'.

         REPLACE 'hold' WITH ' ' INTO wa_buffer.

       ENDWHILE.

       DO.

         i_record = wa_buffer.

         APPEND i_record.

         SHIFT wa_buffer LEFT BY 255 PLACES.

         IF wa_buffer IS INITIAL.

           EXIT.

         ENDIF.

       ENDDO.

* Attachment

       REFRESH: i_reclist,

                 i_objtxt,

                 i_objbin,

                 i_objpack.

       CLEAR wa_objhead.

       i_objbin[] = i_record[].

* Create Message Body Title and Description

       DATA : wrk_con2 TYPE char20.

       CONCATENATE s_date-low+6(2) '.'

                   s_date-low+4(2) '.'

                   s_date-low(4)

                   INTO wrk_con2.

       i_objtxt = text-002.

       APPEND i_objtxt.

       CONCATENATE text-003 wrk_con2 INTO i_objtxt SEPARATED BY space.

       APPEND i_objtxt.

       i_objtxt = text-004.

       APPEND i_objtxt.

       i_objtxt = text-005.

       APPEND i_objtxt.

       DESCRIBE TABLE i_objtxt LINES v_lines_txt.

       READ TABLE i_objtxt INDEX v_lines_txt.

       wa_doc_chng-obj_name = 'Statements'.

       wa_doc_chng-expiry_dat = sy-datum + 10.

       wa_doc_chng-obj_descr = 'Statements'.

       wa_doc_chng-sensitivty = 'F'.

       wa_doc_chng-doc_size = v_lines_txt * 255.

* Main Text

       CLEAR i_objpack-transf_bin.

       i_objpack-head_start = 1.

       i_objpack-head_num = 0.

       i_objpack-body_start = 1.

       i_objpack-body_num = v_lines_txt.

       i_objpack-doc_type = 'RAW'.

       APPEND i_objpack.

* Attachment (pdf-Attachment)

       i_objpack-transf_bin = 'X'.

       i_objpack-head_start = 1.

       i_objpack-head_num = 0.

       i_objpack-body_start = 1.

       DESCRIBE TABLE i_objbin LINES v_lines_bin.

       READ TABLE i_objbin INDEX v_lines_bin.

       i_objpack-doc_size = v_lines_bin * 255 .

       i_objpack-body_num = v_lines_bin.

       i_objpack-doc_type = 'PDF'.

       i_objpack-obj_name = 'smart'.

*      i_objpack-obj_descr = 'Statements'.

       CONCATENATE wrk_final-lifnr '- Statements'

        INTO i_objpack-obj_descr SEPARATED BY space.

       APPEND i_objpack.

       CLEAR i_reclist.

       i_reclist-receiver = wrk_final-smtp_addr.

       i_reclist-rec_type = 'U'.

       APPEND i_reclist.

       CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

         EXPORTING

           document_data              = wa_doc_chng

           put_in_outbox              = 'X'

           commit_work                = 'X'

         TABLES

           packing_list               = i_objpack

           object_header              = wa_objhead

           contents_bin               = i_objbin

           contents_txt               = i_objtxt

           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.

         lv_val = sy-subrc.

         WRITE:/ 'Error When Sending the File', sy-subrc.

*      ELSE.

*        WRITE:/ 'Mail sent'.

       ENDIF.

       CLEAR : w_return,i_otf,i_tline,lv_final.

     ENDAT.

     CLEAR : wrk_final, wa_final.

   ENDLOOP.

   IF lv_val = 0.

     WRITE : 'Mail sent'.

   ENDIF.





Friends this is my code.

Using this i can send mail to all  vendors but the attachment(pdf file)  is same for all vendors.

For vendor am using range for selection.

i want to send  Different attachment(pdf file) According to vendor selection criteria.


Please help me friends


Thank you.

former_member190578
Participant
0 Kudos

If the vendors always the same: I recommend to create a distribution list, it's an easy way to maintain email addresses   AND

you will be able to use this distribution list with CL_BCS.

If the distribution list is not helpful it still recommend the class CL_BCS for sending emails with attachments.

Former Member
0 Kudos

Hi Sachin,

Please refer to this link: Send email from ABAP with class CL_BCS - Code Gallery - SCN Wiki

You can add all recipients you want.

Regards.