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: 

Sending mail different vendors

Former Member
0 Kudos

Hi All,

There is a company that has a sap standard report to send(using email) a pdf file to multiple vendors and there are more than 60 vendors on that pdf file. It's one pdf file with more than 60 vendors so the problem is this document must be divided into a number of vendors available on that file so the email must send more than 60 emails to more than 60 vendors and each vendor must receive an email about his/her own information.

In short the email must sent more than 60 mails separately each vendor receiving it own information. May you please help me out on this one.

Regards,

Fred.

3 REPLIES 3

Former Member
0 Kudos

Hi Fred,

You can do like this

Loop at data_tab.

  • At each loop take one vendor and his details.

Use function module SO_DOCUMENT_SEND_API1

Pass Content_txt with vendor details.

Pass receivers with single vendor.

Endloop.

Hope this will help you.

Reward if this helps,

Satish

Former Member
0 Kudos

Hi Fred,

First u store the vendor's data in an int table.(say ITAB)

2nd u separately store all the vendors email address in other int table.(say it_mail).

(lifnr, email_id)

Then

Loop at it_mail.

loop at itab where lifnr = it_mail-lifnr.

*******************structure ur mail body content***********

*************

*************

*************

append t_mail_text.

endloop.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

object_content = t_mail_txt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

IF sy-subrc EQ 0.

COMMIT WORK.

ENDIF.

CLEAR reclist.

REFRESH reclist.

CLEAR it_mail.

endloop.

I think it will work fine.

If it is helpfull reward pts pls.

Regards

srimanta

0 Kudos

May you please check this coding and tell me where have i gone wrong? because it can send email 90 pages to specified mails so i need to send e-mail to vendors on the pdf file separately each vendor receiving his own page. this means 90 pages must be send separately to each vendor.

************************************************************************

  • *

  • Überweisungsträgerprogramm RFFOZA_A (Südafrika) *

  • Program for bank transfer RFFOZA_A (South Africa) *

  • *

************************************************************************

*----


*

  • Das Programm includiert: *

  • *

  • RFFORI0M Makrodefinition für den Selektionsbildaufbau *

  • RFFORI00 Deklarationsteil der Zahlungsträger-Druckprogramme *

  • RFFORIZ8 Datenträgeraustausch Inland - ACB Format für ZA *

  • RFFORI06 Avis *

  • RFFORI07 Zahlungsbegleitliste *

  • RFFORI99 Allgemeine Unterroutinen der Zahlungsträger-Druckprogramme *

*----


*

  • The program includes: *

  • *

  • RFFORI0M Definition of macros *

  • RFFORI00 international data definitions *

  • ZFFORIZ8 inland transfer (DME) : ACB format for ZA *

  • this was RFFORIZ8 *

  • RFFORI06 remittance advice *

  • RFFORI07 payment summary list *

  • RFFORI99 international subroutines *

*----


*

*----


*

  • Report Header *

*----


*

report rffoza_a

line-size 132

message-id f0

no standard page heading.

*----


*

  • Segments *

*----


*

tables:

reguh,

regup,

thoci.

*----


*

  • Makrodefinitionen *

*----


*

include rffori0m.

initialization.

*----


*

  • Parameters / Select-Options *

*----


*

block 1.

select-options:

sel_zawe for reguh-rzawe, "Zahlwege / payment methods

sel_uzaw for reguh-uzawe, "Zahlwegzusatz

sel_hbki for reguh-hbkid, "house bank short key

sel_hkti for reguh-hktid, "account data short key

sel_vbln for reguh-vblnr. "payment document number

selection-screen end of block 1.

block 2.

auswahl: xdta w, avis a, begl b.

spool_authority. "Spoolberechtigung

selection-screen end of block 2.

block 3.

parameters:

par_unix like rfpdo2-fordnamd, "file name

par_dtyp like rfpdo-forddtyp, "output medium

par_anzp like rfpdo-fordanzp, "number of test prints

par_maxp like rfpdo-fordmaxp, "number of items in summary list

par_belp like rfpdo-fordbelp, "payment doc. validation

par_espr like rfpdo-fordespr. "texts in recipient's lang.

selection-screen end of block 3.

block 4.

parameters:

par_inid like rfpdo2-fordinid obligatory, "Installation Id

par_usid like rfpdo2-fordusid obligatory, "User Id

  • PAR_SERV LIKE RFPDO2-FORDSERV OBLIGATORY, "Type of service

par_usre like rfpdo2-fordusre obligatory, "User Reference

par_nacc like rfpdo2-fordnacc obligatory, "Nominated Account Name

par_cale like thoci-ident obligatory, "Bank Calender

par_acdt like reguh-zaldt, "Action date put into ACB file

par_test like rfpdo1-allgtest, "Generate tape for ACB to test

par_geno(4) type n. "Generation Number note #310776

selection-screen end of block 4.

parameters:

par_zdru like rfpdo-fordzdru no-display,

par_priz like rfpdo-fordpriz no-display,

par_sofz like rfpdo1-fordsofz no-display,

par_isoc like rfpdo-fordisoc no-display,

par_vari(12) type c no-display,

par_sofo(1) type c no-display.

block 5.

  • SELECTION-SCREEN BEGIN OF LINE.

  • SELECTION-SCREEN COMMENT 10(25) TEXT-069 FOR FIELD P_HUMRS.

parameters: p_humrs like rfpdo1-allgtest.

  • SELECTION-SCREEN END OF LINE.

selection-screen end of block 5.

*----


*

  • Vorbelegung der Parameter und Select-Options *

  • default values for parameters and select-options *

*----


*

perform init.

sel_zawe-low = 'A'.

sel_zawe-option = 'EQ'.

sel_zawe-sign = 'I'.

append sel_zawe.

par_belp = space.

par_zdru = space.

par_xdta = 'X'.

par_dtyp = '1'.

par_avis = 'X'.

par_begl = 'X'.

par_anzp = 2.

par_espr = space.

par_isoc = space.

par_maxp = 9999.

  • PAR_SERV = '5'.

*----


*

  • tables / fields / field-groups / at selection-screen *

*----


*

include zffori00.

*- special checks for South African ACB----

-


at selection-screen on zw_zbukr.

describe table zw_zbukr lines sy-tfill.

if sy-tfill ne 1.

message e405.

else.

if zw_zbukr-option ne 'EQ' or zw_zbukr-sign ne 'I'.

message e405.

endif.

endif.

*AT SELECTION-SCREEN ON PAR_SERV.

  • IF PAR_SERV NA '0125'. "ACB service = immediate, 1,2 day and 5 day

  • MESSAGE E186 WITH '0, 1, 2, 5'.

  • ENDIF.

at selection-screen on par_usre.

data: up_char.

perform dta_text_aufbereiten using par_usre.

if par_usre cn 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./-&,() '.

up_char = par_usre+sy-fdpos(1).

message e406 with up_char.

endif.

at selection-screen on par_nacc.

data: up_char.

perform dta_text_aufbereiten using par_nacc.

if par_nacc cn 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./-&,() '.

up_char = par_nacc+sy-fdpos(1).

message e406 with up_char.

endif.

at selection-screen on par_cale.

select single * from thoci where ident eq par_cale.

if sy-subrc ne 0.

message e407.

endif.

at selection-screen on par_dtyp.

if par_dtyp na '01'.

set cursor field 'PAR_DTYP'.

message e068.

endif.

*----


*

  • Kopfzeilen (nur bei der Zahlungsbegleitliste) *

  • batch heading (for the payment summary list) *

*----


*

top-of-page.

if flg_begleitl eq 1.

perform kopf_zeilen. "RFFORI07

endif.

*----


*

  • Felder vorbelegen *

  • preparations *

*----


*

start-of-selection.

hlp_temse = '0----

-


'. "Reportspezif. TemSe-Parameter

perform vorbereitung.

*----


*

  • Daten prüfen und extrahieren *

  • check and extract data *

*----


*

get reguh.

check sel_zawe.

check sel_uzaw.

check sel_hbki.

check sel_hkti.

check sel_vbln.

perform pruefung.

perform extract_vorbereitung.

get regup.

perform extract.

*----


*

  • Bearbeitung der extrahierten Daten *

  • print DME, remittance advices and lists *

*----


*

end-of-selection.

if flg_selektiert ne 0.

if par_xdta eq 'X'.

perform dta_inland. "RFFORIZ8

endif.

if par_avis eq 'X'.

perform avis. "RFFORI06

*>> MN Cele

perform convert_to_pdf.

perform send_mail.

*<< MN Cele

endif.

if par_begl eq 'X' and par_maxp gt 0.

flg_bankinfo = 2.

perform begleitliste. "RFFORI07

endif.

endif.

perform fehlermeldungen.

perform information.

*----


*

  • Unterprogramm Datenträgeraustausch Inland (Band) *

  • subroutine for DME inland (tape) *

*----


*

include zfforiz8.

*----


*

  • Unterprogramm Avis ohne Allongeteil *

  • subroutine for remittance advices *

*----


*

  • include rffori06.

include zrffori06.

*----


*

  • Unterprogramm Begleitliste *

  • subroutine for the summary list *

*----


*

include rffori07.

*----


*

  • Allgemeine Unterprogramme *

  • international subroutines *

*----


*

include rffori99.

*&----


*

*& Form convert_to_pdf

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form convert_to_pdf.

data: lv_spool_no type tsp01-rqident.

data: lwa_spoolrequests type rsporq.

data: lt_spoolrequests type table of rsporq.

data: lv_numbytes type i,

lv_pdfspoolid like tsp01-rqident,

lv_jobname like tbtcjob-jobname,

lv_jobcount like tbtcjob-jobcount,

lv_spoolid type tsp01_sp0r-rqid_char.

call function 'RSPO_FIND_SPOOL_REQUESTS'

exporting

allclients = sy-mandt

  • AUTHORITY = ' '

  • DATATYPE = '*'

  • HAS_OUTPUT_REQUESTS = '*'

  • RQ0NAME = '*'

  • RQ1NAME = '*'

  • RQ2NAME = '*'

  • RQDEST = '*'

  • RQIDENT = 0

rqowner = sy-uname

tables

spoolrequests = lt_spoolrequests

  • EXCEPTIONS

  • NO_PERMISSION = 1

  • OTHERS = 2

.

  • if sy-subrc <> 0.

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

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

  • endif.

*Only read the latest spool number and make sure it is for the customer statement.

sort lt_spoolrequests descending.

delete lt_spoolrequests from 2.

delete lt_spoolrequests where rqtitle <> 'Payment advices'.

loop at lt_spoolrequests into lwa_spoolrequests.

lv_spool_no = lwa_spoolrequests-rqident.

lv_spoolid = lwa_spoolrequests-rqident.

endloop.

clear: it_pdf,

wa_doc_chng,

i_objtxt,

i_objpack,

i_reclist.

refresh: it_pdf,

i_objtxt,

i_objpack,

i_reclist,

i_objbin.

lv_numbytes = 0.

call function 'CONVERT_OTFSPOOLJOB_2_PDF'

exporting

src_spoolid = lv_spool_no

no_dialog = space

  • DST_DEVICE =

  • PDF_DESTINATION =

importing

pdf_bytecount = lv_numbytes

pdf_spoolid = lv_pdfspoolid

  • otf_pagecount =

btc_jobname = lv_jobname

btc_jobcount = lv_jobcount

tables

pdf = it_pdf

exceptions

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

others = 12.

wf_numbytes = lv_numbytes.

if sy-subrc <> 0.

case sy-subrc.

when 1.

message i000(z001).

exit.

when 2.

message i001(z001).

exit.

when 3.

message i002(z001).

exit.

when others.

message i003(z001).

exit.

endcase.

endif.

call function 'RSPO_R_RDELETE_SPOOLREQ'

exporting

spoolid = lv_spoolid

  • IMPORTING

  • RC =

  • STATUS =

.

  • Transfer the contents of itpdf into the objbin table, so that we have

  • the PDF data in a format ready to be attached to an email.

  • First, move the contents of ITPDF into a long string.

  • Cannot use the concatenate statement here, as trailing spaces are

  • ignored, and the trailing spaces within ITPDF are necessary !!

istringcounter = 0.

irecordcounter = 0.

flag_continue_looping = 'yes'.

while flag_continue_looping = 'yes'.

loop at it_pdf from irecordcounter.

sitpdfstring = it_pdf-tdformat.

sitpdfstring+2 = it_pdf-tdline.

clongstring+istringcounter = sitpdfstring.

istringcounter = istringcounter + 134.

if istringcounter >= 65526.

concatenate clongstring '%%EOF' into clongstring.

flag_continue_looping = 'yes'.

istringcounter = 0.

irecordcounter = sy-tabix + 1.

exit.

else.

flag_continue_looping = 'no'.

endif.

endloop.

  • Now that we have one long string, we can split it up into

  • the 255 character pieces, and assign them to OBJBIN table

istartposition = 0.

iendofstring = 0.

while iendofstring = 0 and istartposition < 65526.

  • There is an EOF Marker in the file, so we will loop until that

  • marker is found

search clongstring for '%%EOF' starting at istartposition.

iremaininglength = 65531 - istartposition.

if sy-subrc = 0 and sy-fdpos <= 255. " End of string is in site

iendofstring = sy-fdpos + 5. " Position of end of string marker

if iendofstring > iremaininglength.

i_objbin-line = clongstring+istartposition(iremaininglength).

else.

i_objbin-line = clongstring+istartposition(iendofstring).

endif.

else.

i_objbin-line = clongstring+istartposition(255).

endif.

append i_objbin.

  • Increment the start position so that the next segment can be obtained.

istartposition = istartposition + 255.

endwhile.

endwhile.

              • Create Message Body

        • Title and Description

i_objtxt = 'Payment advice'.

append i_objtxt.

describe table i_record lines v_lines_txt.

read table i_objtxt index v_lines_txt.

wa_doc_chng-obj_name = 'SAPSCRIPT'.

wa_doc_chng-obj_langu = sy-langu.

wa_doc_chng-obj_descr = 'Payment advice'.

wa_doc_chng-expiry_dat = sy-datum + 10.

wa_doc_chng-sensitivty = 'F'.

wa_doc_chng-doc_size =

( v_lines_txt - 1 ) * 255 + strlen( i_record ).

  • Describe the body of the message

clear i_objpack.

refresh i_objpack.

i_objpack-transf_bin = space.

i_objpack-head_start = 1.

i_objpack-head_num = 0.

i_objpack-body_start = 1.

describe table i_objtxt lines i_objpack-body_num.

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

i_objpack-body_start = 1.

describe table i_objbin lines i_objpack-body_num.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_descr = 'Payment advice'.

i_objpack-obj_name = 'SAPSCRIPT'.

i_objpack-doc_size = i_objpack-body_num * 255.

append i_objpack.

  • Add the recipients email address

clear i_reclist.

refresh i_reclist.

  • i_reclist-receiver = icust-smtp_addr.

i_reclist-receiver = 'fred.mogaadile@bcx.co.za'.

  • i_reclist-receiver = 'NICKD@centsys.co.za'.

i_reclist-rec_type = 'U'.

i_reclist-com_type = 'INT'.

i_reclist-notif_del = 'X'.

i_reclist-notif_ndel = 'X'.

append i_reclist.

************Fred edited*******************************

clear i_reclist.

refresh i_reclist.

  • i_reclist-receiver = icust-smtp_addr.

i_reclist-receiver = 'mogaadilefm@yahoo.com'.

  • i_reclist-receiver = 'NICKD@centsys.co.za'.

i_reclist-rec_type = 'U'.

i_reclist-com_type = 'INT'.

i_reclist-notif_del = 'X'.

i_reclist-notif_ndel = 'X'.

append i_reclist.

clear i_reclist.

refresh i_reclist.

  • i_reclist-receiver = icust-smtp_addr.

i_reclist-receiver = 'mathews.cele@bcx.co.za'.

  • i_reclist-receiver = 'NICKD@centsys.co.za'.

i_reclist-rec_type = 'U'.

i_reclist-com_type = 'INT'.

i_reclist-notif_del = 'X'.

i_reclist-notif_ndel = 'X'.

append i_reclist.

clear i_reclist.

refresh i_reclist.

  • i_reclist-receiver = icust-smtp_addr.

i_reclist-receiver = 'fmb@webmail.co.za'.

  • i_reclist-receiver = 'NICKD@centsys.co.za'.

i_reclist-rec_type = 'U'.

i_reclist-com_type = 'INT'.

i_reclist-notif_del = 'X'.

i_reclist-notif_ndel = 'X'.

append i_reclist.

*********************Fred edited*************************

endform. " convert_to_pdf

*&----


*

*& Form send_mail

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form send_mail.

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.

  • case sy-subrc.

  • when 0.

  • wa_sent_report-kunnr = icust-kunnr.

  • wa_sent_report-name1 = icust-name1.

  • wa_sent_report-smtp_addr = icust-smtp_addr.

  • wa_sent_report-fsize = wf_numbytes.

  • append wa_sent_report to it_sent_report.

  • endcase.

out_params-tddelete = 'X'.

endform. " send_mail