cancel
Showing results for 
Search instead for 
Did you mean: 

SAPscript as mail dispatch

alexgiedt
Explorer
0 Kudos
275

Hello everyone,

I am slightly desperate and hope that someone here can help me, as I have no idea how to solve this problem.

It's about the following:

We have a Z programme that delivers consignment messages with SAPscript expression. Now the created SAPscricpt should also be sent by email. If this option is desired, the user selects "send via email" in the programme and enters the desired email address of the recipient

In the program code, I check which medium is available (i.e. print, fax or email)

case xmedium.<br>
    when '1'.<br>
      nast-nacha = '1'.<br>
      lf_device = 'PRINTER'.<br>
    when '2'.<br>
      nast-nacha = '2'.<br>
      lf_device = 'TELEFAX'.<br>
      cs_itcpo-tdtelenum  = lfa1-telfx.<br>
      cs_itcpo-tdteleland = lfa1-land1.<br>
      cs_itcpo-tdsenddate = sy-datum.<br>
      cs_itcpo-tdsendtime = sy-uzeit.<br>
      cs_itcpo-tdfaxuser  = sy-uname.<br>
      if not p_faxnr is initial.<br>
        cs_itcpo-tdtelenum = p_faxnr.<br>
      endif.<br>
      nast-telfx = cs_itcpo-tdtelenum.<br>
      nast-tland = cs_itcpo-tdteleland.<br>
 <br>
      when '5'.<br>
        nast-nacha = '5'.<br>
        lf_device = 'MAIL'.<br>
        cs_itcpo-tdgetotf = 'X'.<br>
  endcase.<br>
  if x_spcarc = 'X' and p_armod <> '1' and xmedium = '1'.<br>
    cs_toa-function = 'DARA'.<br>
    cs_toa-mandant = sy-mandt.<br>
    cs_toa-sap_object = 'BKPF'.<br>
    cs_toa-ar_object = p_docart.<br>
    cs_toa-reserve = 'COMMIT'.<br>
    cs_toa-object_id    = i_tab-bukrs.<br>
    cs_toa-object_id+4  = i_tab-belnr.<br>
    cs_toa-object_id+14 = i_tab-gjahr.<br>
    move-corresponding cs_toa to cs_arc.<br>
    cs_itcpo-tdarmod = p_armod.<br>
  endif.<br>
<br>
  cs_itcpo-tdnewid    = new_spool.<br>
  cs_itcpo-tdpreview  = pr_view.       "For testing<br>
  cs_itcpo-tdreceiver = p_prrec.<br>
  cs_itcpo-tdautority = p_prber.<br>
  cs_itcpo-tdcopies   = n_pcopy.<br>
  cs_itcpo-tdimmed    = x_pimme.<br>
  cs_itcpo-tddelete   = x_prele.<br>
  cs_itcpo-tdsenddate = sy-datum.<br>
  cs_itcpo-tdsendtime = sy-uzeit.<br>
  cs_itcpo-tdprogram  = sy-repid..<br>
  cs_itcpo-tdcovtitle = p_title.<br>
  cs_itcpo-tddest     = p_ldest.<br>
<br>
  perform set_covtitle<br>
    using zzbc_printf lfa1-lifnr i_tab-werks<br>
    changing cs_itcpo-tdcovtitle.<br>

Next I check with nast-nacha <> 5 that everything is done as before (i.e. print and fax run as before).

However, if email is now used, i.e. nast-nacha = 5, then the new logic is applied.

elseif nast-nacha = '5'.<br>
<br>
data: p_mail_sen_obj type swotobjid,<br>
      p_mail_rec_obj type swotobjid,<br>
      lt_otfdata type table of itcoo with header line,<br>
      options like itcpo,<br>
      ls_itcpp like itcpp,<br>
      gt_otf_data type table of itcoo,<br>
      gt_pdf_data type table of tline,<br>
      gw_comm_values type  szadr_comm_values,<br>
      lt_packlist      type table of sopcklsti1,<br>
      ls_packlist      type sopcklsti1,<br>
      ls_docdata       type sodocchgi1,<br>
      mv_subject      type so_obj_des.<br>
<br>
<br>
<br>
<br>
* *Internal table to get vendor name and address number<br>
    data : begin of it_vname occurs 0,<br>
           lfnr like lfa1-lifnr,<br>
           end of it_vname.<br>
*Internal table to get email_if with address number<br>
    data : begin of it_vemail occurs 0,<br>
           email type so_name,<br>
           end of it_vemail.<br>
<br>
  data : begin of it_nast occurs 0,<br>
           parnr like nast-parnr,<br>
           end of it_nast.<br>
<br>
    select single parnr from nast into it_nast<br>
             where parnr eq lfa1-lifnr.<br>
<br>
*Accessing name and address number of a vendor<br>
    select single lifnr from lfa1 into it_vname<br>
      where lifnr eq it_nast-parnr.<br>
*Accessing mail id of a vendor<br>
    select single intad from lfb1 into it_vemail where lifnr eq it_vname-lfnr<br>
      and bukrs eq rkwa-bukrs.<br>
    if sy-subrc = 0.<br>
<br>
*    lv_ip_mailaddr = <ls_intad>.<br>
*    lv_et_recipient = conv #( ls_mail_recipient ).<br>
<br>
        call function 'CREATE_RECIPIENT_OBJ_PPF'<br>
         exporting<br>
*           IP_COUNTRY              =<br>
*           IP_FAXNO                =<br>
           ip_mailaddr             =  it_vemail-email<br>
           ip_type_id              = 'U'<br>
         importing<br>
           ep_recipient_id         = p_mail_rec_obj<br>
         exceptions<br>
           invalid_recipient       = 1<br>
           others                  = 2<br>
                  .<br>
        if sy-subrc <> 0.<br>
* Implement suitable error handling here<br>
        endif.<br>
        endif.<br>
<br>
    call function 'CREATE_SENDER_OBJECT_PPF'<br>
     exporting<br>
       ip_sender            = sy-uname<br>
     importing<br>
       ep_sender_id         = p_mail_sen_obj<br>
     exceptions<br>
       invalid_sender       = 1<br>
       others               = 2<br>
              .<br>
    if sy-subrc <> 0.<br>
* Implement suitable error handling here<br>
        message id sy-msgid type sy-msgty number sy-msgno<br>
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.<br>
    endif.<br>
<br>
*p_mail_rec_obj = conv #( it_vemail-email ).<br>
<br>
<br>
gw_comm_values-adsmtp = conv #( it_vemail-email ).<br>
<br>
call function 'CONVERT_COMM_TYPE_DATA'<br>
 exporting<br>
   pi_comm_type                    = 'INT'<br>
   pi_comm_values                  = gw_comm_values<br>
*   PI_SCREEN                       =<br>
*   PI_NEWID                        =<br>
*   PI_COUNTRY                      =<br>
   pi_repid                        = sy-repid<br>
*   PI_SNAST                        =<br>
   pi_mail_sender                  = sy-uname<br>
*   PI_USE_MAILDEVICE_FOR_FAX       = ' '<br>
 importing<br>
   pe_itcpo                        = cs_itcpo<br>
   pe_mail_recipient               = p_mail_rec_obj<br>
   pe_mail_sender                  = p_mail_sen_obj<br>
* EXCEPTIONS<br>
*   COMM_TYPE_NOT_SUPPORTED         = 1<br>
*   RECIPIENT_CREATION_FAILED       = 2<br>
*   SENDER_CREATION_FAILED          = 3<br>
*   OTHERS                          = 4<br>
          .<br>
if sy-subrc <> 0.<br>
* Implement suitable error handling here<br>
endif.<br>
<br>
<br>
<br>
  call function 'OPEN_FORM'<br>
    exporting<br>
      archive_index  = cs_toa     "RER, 20.01.2010<br>
      archive_params = cs_arc     "RER, 20.01.2010<br>
      form           = frm_name<br>
      device         = lf_device<br>
      dialog         = space<br>
      mail_sender    = p_mail_sen_obj<br>
      mail_recipient = p_mail_rec_obj<br>
      language       = lfa1-spras<br>
      options        = cs_itcpo<br>
    exceptions<br>
      canceled       = 1<br>
      device         = 2<br>
      form           = 3<br>
      options        = 4<br>
      unclosed       = 5<br>
      mail_options   = 6<br>
      archive_error  = 7<br>
      others         = 8.<br>
<br>
<br>
    call function 'CLOSE_FORM'<br>
    importing<br>
      result = ls_itcpp<br>
      tables<br>
        otfdata = gt_otf_data[]<br>
    exceptions<br>
      others = 1.<br>
<br>
    commit work.<br>

And this is exactly the problem. I've tried so many things, but no matter what I do, I get an error or short dump. I just don't know what to do..... Can anyone here please help me. I've searched Google etc. but I haven't found anything that solves my problem.

I would be so grateful if someone here could help me.

Thanks so much

Alex

abo
Active Contributor

First fix the formatting, then add the dump info, it helps.

FredericGirod
Active Contributor

Did you search about using CL_BCS class to send email ?

Sandra_Rossi
Active Contributor
0 Kudos

You don't say what exact problem you have (error? short dump?)

You don't say what you have checked precisely.

You are using PPF, does the transaction use PPF?

Mark_W
Product and Topic Expert
Product and Topic Expert
0 Kudos

Removing Asset Accounting tag as no relevance to this query.

Sandra_Rossi
Active Contributor

Note that your code snippet is full of <br>.

abo
Active Contributor
0 Kudos

That happens because the code is copied when the editor is in change mode: switching to display before copying prevents the issue.

Sandra_Rossi
Active Contributor

c5e08e0478aa4727abc4482f5be390b2 Interesting, I'll check it. I guess it concerns the backend editor (SE38). Also, Ctrl+Shift+V (unformatted paste) may help.

Accepted Solutions (0)

Answers (0)