Send Report output as Email attachment (PDF)

Hi Experts,
  i am trying to send the contents of an internal table from my report as email using PDF attachment. I have coded the logic and i get the attachment in the email. When i try to open the attachement, i cannot open it.
The message i get is "_Adobe reader could not open the attachment "attach.pdf" because it is either not a supported file type or the file has been damaged(for example, it was sent as an email attachment and wasn't correctly decoded )._
Not sure where i went wrong.
  ld_email   = p_email.
  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.
  ld_sender_address      = p_sender_address.
  ld_sender_address_type = p_sender_addres_type.
Fill the document data.
  w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
  ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_attach[].
Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.
Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.
Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.
  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = w_doc_data
      put_in_outbox              = 'X'
      sender_address             = ld_sender_address
      sender_address_type        = ld_sender_address_type
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = w_sent_all
    TABLES
      packing_list               = t_packing_list
      contents_bin               = t_attachment
      contents_txt               = it_message
      receivers                  = t_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.
Populate zerror return code
  ld_error = sy-subrc.
Populate zreceiver return code
  LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.                    "send_file_as_email_attachment

Hello RnB,
You can check the mentioned link for the same:
[Simple Program to generate PDF from ABAP List Output.|http://www.abapmadeeasy.com/2011/02/sap-abap-simple-program-to-generate-pdf.html]
Regards,
Uttam Agrawal

Similar Messages

  • Send report as an email attachment from a page

    Hi
    I have page which generates a report based on two filters. After the report is generated, 'I want to send that report as an email attachment from that page, when button is clicked "Send Email"
    Thanks a lot in advance.'

    I accomplished functionality I believe similar to what you are looking for in an application once by querying a report into an html e-mail message. This approach gives you all kinds of flexibility. At least this would be one way of doing it. I am going to include a simplified sample here of what the script looked like. I hope this is at least helpful.
    DECLARE
    l_body_html CLOB;
    BEGIN
    l_body_html :=
    '<html>
    <head>
    <style type="text/css">
    body{font-family: Arial, Helvetica, sans-serif;
    font-size:9pt;
    margin:30px;
    background-color:#ffffff;}
    </style>
    </head><body>
    ' || UTL_TCP.crlf;
    l_body_html :=
    l_body_html || '<table border="1"><tr bgcolor="#999999">
    <th width="75" scope="col">
    Department
    </th>
    <th width="75" scope="col">
    Course
    </th>
    </tr>' || UTL_TCP.crlf;
    FOR c1 IN (SELECT some_table.DEPARTMENT, some_table.COURSE FROM some_table)
    LOOP
    l_body_html :=
    l_body_html || '<tr><td>
    ' || c1.DEPARTMENT || '
    </td>' || UTL_TCP.crlf;
    l_body_html := l_body_html || '<td>
    ' || c1.COURSE || '
    </td>' || UTL_TCP.crlf;
    l_body_html := l_body_html || '</tr>' || UTL_TCP.crlf;
    END LOOP;
    l_body_html := l_body_html || '</table>' || UTL_TCP.crlf;
    apex_mail.send(
    p_to => '<some email address>',
    p_from => '<desired from address here>',
    p_body => NULL,
    p_body_html => l_body_html,
    p_subj => '<desired subject line here>');
    END loop;
    apex_mail.push_queue;
    END;
    Edited by: stbrownOSU on Dec 8, 2009 2:53 PM
    I think something must have happened when I copied and pasted the code from TOAD. I have corrected the above code. Please try it again.

  • Send report output via email as zipped attachment

    Is it possible for the report output to be zipped before being attached to an email when running on a windows reports_server? On unix we theoretically have the ability to modify the mail.sh shell script that performs the mail operation for reports.

    Hi Richard
    This is a Reports 9i solution.
    You may create a batch file that runs the report, compresses the file and invokes, say, a Java application that mails the given .zip file.
    More "advanced" options would be:
    You may create a pluggable destination that captures report output. Next, your code does the compresses the output file and mails it.
    A simpler solution would be to run two reports. First, that creates the reports output file. In its AFTER_REPORT trigger, call Java method (thru. Java Importer), that picks up the output file and compresses it. Second, that uses XML distribution feature of Reports 9i and mails the .zip file as a file attachment using appropriate construct.
    Regard
    Sripathy

  • Sending smartform output as mail attachment (PDF)

    Hi,
    I am trying to send a smartform output in PDF format as a mail attachment. This has to be fired in the save of a Invoice.. configured by the output type.
    Here is the code which i have .. and it does not work.
    DATA: ls_bil_invoice TYPE lbbil_invoice.
    tables: nast.
    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_form_name TYPE rs38l_fnam,
    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.
    call function 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname           = 'ZSDDLB_BIL_INVOICE'
      IMPORTING
        fm_name            = v_form_name
      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 v_form_name
      EXPORTING
        control_parameters = w_ctrlop
        output_options     = w_compop
        user_settings      = 'X'
        is_bil_invoice     = ls_bil_invoice
        is_nast            = nast
        is_repeat          = 'X'
      IMPORTING
        job_output_info    = w_return
      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
      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 EQ 0.
    endif.
    Convert PDF from 132 to 255.
    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.
    refresh:
    i_reclist,
    i_objtxt,
    i_objbin,
    i_objpack.
    clear wa_objhead.
    Object with PDF.
    i_objbin[] = i_record[].
    DESCRIBE TABLE i_objbin LINES v_lines_bin.
    Object with main text of the mail.
    i_objtxt = 'Find attached the output of the smart form.'.
    APPEND i_objtxt.
    DESCRIBE TABLE i_objtxt LINES v_lines_txt.
    Document information.
    wa_doc_chng-obj_name = 'Smartform'.
    wa_doc_chng-expiry_dat = sy-datum + 10.
    wa_doc_chng-obj_descr = 'Smart form output'.
    wa_doc_chng-sensitivty = 'F'. "Functional object
    wa_doc_chng-doc_size = v_lines_txt * 255.
    Pack to main body as RAW.
    Obj. to be transported not in binary form
    CLEAR i_objpack-transf_bin.
    Start line of object header in transport packet Smart Forms
    i_objpack-head_start = 1.
    Number of lines of an object header in object packet
    i_objpack-head_num = 0.
    Start line of object contents in an object packet
    i_objpack-body_start = 1.
    Number of lines of the object contents in an object packet
    i_objpack-body_num = v_lines_txt.
    Code for document class
    i_objpack-doc_type = 'RAW'.
    APPEND i_objpack.
    Packing as PDF.
    i_objpack-transf_bin = 'X'.
    i_objpack-head_start = 1.
    i_objpack-head_num = 1.
    i_objpack-body_start = 1.
    i_objpack-body_num = v_lines_bin.
    i_objpack-doc_type = 'PDF'.
    i_objpack-obj_name = 'Smartform'.
    CONCATENATE 'Smartform_output' '.pdf'
    INTO i_objpack-obj_descr.
    i_objpack-doc_size = v_lines_bin * 255.
    APPEND i_objpack.
    Document information.
    CLEAR i_reclist.
    e-mail receivers.
    i_reclist-receiver = '[email protected]'.
    i_reclist-express = 'X'.
    i_reclist-rec_type = 'U'. "Internet address
    APPEND i_reclist.
    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = wa_doc_chng
        put_in_outbox              = '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 EQ 0.
    ENDIF.

    Hi Aviroop,
      Compare your part of code with the below given code.
    *& Report  YSSN_SIMPLE_SMARTFORM                                       *
    report  zhr_bhaskar_pdf_to_email                   message-id zmsg.
    parameters: p_vbeln type vbak-vbeln default '35'.
    data: it_items type table of vbap,
          v_fm_name type  rs38l_fnam,
          v_tot_lines type i,
          v_sy_tabix           type i,
          output_data        type ssfcrescl. " To hold Output information
    constants:
      c_sep                type c value '-',  " Value -
      c_x                  type c value 'X',  " Value X
      c_space              type c value ' '.  " Space
    *****MAIL START
    include .
    data: g_mail_rec_obj type swotobjid,
          g_mail_sen_obj type swotobjid,
          g_mail_app_obj type swotobjid,
          g_cont_par type  ssfctrlop,
          folder type swc_object,
      begin of sofmfol_key,
          foldertype like sofm-foltp,
          folderyear like sofm-folyr,
          foldernumber like sofm-folno,
          type like sofm-doctp,
          year like sofm-docyr,
          number like sofm-docno,
          forwarder like soub-usrnam,
      end of sofmfol_key,
          bor_key like swotobjid-objkey,
         g_mail TYPE  ppfdmailad VALUE '[email protected]',
          g_mail type  so_name value '[email protected]',
        g_mail TYPE  ppfdmailad VALUE '[email protected]' ,
        g_mail TYPE  ppfdmailad VALUE '[email protected]' ,
          g_rectype type  so_escape value 'U'. " 'B'.
    data: job_output_info type ssfcrescl,
          hotfdata like itcoo  occurs 1 with header line,
          htline like tline    occurs 1 with header line,
          x_objcont like soli  occurs 1 with header line,
          ld_packing_list like soxpl occurs 1 with header line,
          x_object_hd_change like sood1 occurs 1 with header line,
          x_objhead like soli           occurs 1 with header line,
          x_receivers like soos1 occurs 1 with header line,
          format_pdf(10) value 'PDF',
          doc_size(12) type c,
          hltlines type i,
          htabix like sy-tabix,
          fle1(2) type p,
          fle2(2) type p,
          off1 type p,
          hfeld(500) type c.
    tables: soud.
    *****MAIL END
    select *
    into table it_items
    from vbap
    where vbeln = p_vbeln.
    if  it_items[] is initial.
       exit.
    endif.
    perform call_smartform.
    *&      Form  call_smartform
          text
    -->  p1        text
    <--  p2        text
    form call_smartform .
    *DATA: lx_control_parameters TYPE SSFCTRLOP,
         lx_OUTPUT_OPTIONS type SSFCOMPOP.
         lx_OUTPUT_OPTIONS-TDIMMED = ' '.
         lx_OUTPUT_OPTIONS-TDfinal = 'X'.
         lx_OUTPUT_OPTIONS-TDDELETE = 'X'.
         lx_CONTROL_PARAMETERS-NO_CLOSE = 'X'.
         lx_CONTROL_PARAMETERS-NO_OPEN = ' '.
      data: x_ssfcompop type ssfcompop,
            x_ssfctrlop like ssfctrlop,
            x_ssfcrescl type ssfcrescl.
    **MAIL
      g_cont_par-langu = sy-langu.
      g_cont_par-no_dialog = 'X'.
      g_cont_par-getotf = 'X'.
      g_cont_par-device = 'MAIL'.
    Get BOR-Objects for Recipient, Sender und Applikation
      perform mail_recipient_object changing g_mail_rec_obj.
      perform mail_sender_object changing g_mail_sen_obj.
      perform mail_appl_object changing g_mail_app_obj.
    **MAIL
    *--Internal table is having more than 1 record
      if v_tot_lines  gt 1.
        if  v_sy_tabix = 1.
    *--For first record of table
          x_ssfctrlop-no_open  = c_space.
          x_ssfctrlop-no_close = c_x.
        elseif v_sy_tabix = v_tot_lines.
    *--For last record of table
          x_ssfctrlop-no_open  = c_x.
          x_ssfctrlop-no_close = c_space.
        else.
          x_ssfctrlop-no_open  = c_x.
          x_ssfctrlop-no_close = c_x.
        endif.
      endif.
    IF r_previ = c_x.
        x_ssfctrlop-preview  =  c_x.
        x_ssfctrlop-getotf   =  c_x.
    ENDIF.
    call function 'SSF_FUNCTION_MODULE_NAME'
       exporting
         formname                 = 'YSSN_SMARTFORM'
       VARIANT                  = ' '
       DIRECT_CALL              = ' '
      importing
        fm_name                  = v_fm_name
    EXCEPTIONS
       NO_FORM                  = 1
       NO_FUNCTION_MODULE       = 2
       OTHERS                   = 3
    if sy-subrc <> 0.
       message i000 with 'Smart form module name failure'.
       exit.
    endif.
    CALL FUNCTION '/1BCDWB/SF00000199'
    call function v_fm_name
       exporting
       ARCHIVE_INDEX              =
       ARCHIVE_INDEX_TAB          =
       ARCHIVE_PARAMETERS         =
       control_parameters         = g_cont_par
       mail_appl_obj              = g_mail_app_obj
       mail_recipient             = g_mail_rec_obj
       mail_sender                 = g_mail_sen_obj
      OUTPUT_OPTIONS             = lx_OUTPUT_OPTIONS
       USER_SETTINGS              = 'X'
         t_vbap                     = it_items
    IMPORTING
       DOCUMENT_OUTPUT_INFO       =
        job_output_info            = job_output_info
       JOB_OUTPUT_OPTIONS         =
    EXCEPTIONS
       FORMATTING_ERROR           = 1
       INTERNAL_ERROR             = 2
       SEND_ERROR                 = 3
       USER_CANCELED              = 4
       OTHERS                     = 5
      perform send_pdf_mail.
    endform.                    " call_smartform
    *&      Form  send_pdf_mail
          text
    -->  p1        text
    <--  p2        text
    form send_pdf_mail .
      data ld_binfile type xstring.
              pdf_table type  rcl_bag_tline,
      data: ld_originator like soos1-recextnam.
    convert form
      loop at job_output_info-otfdata into hotfdata.
        append hotfdata.
      endloop.
      call function 'CONVERT_OTF'
           exporting
                format                = format_pdf
                max_linewidth         = 132
           importing
                bin_filesize          = doc_size
                bin_file              = ld_binfile
           tables
                otf                   = output_data-otfdata
                lines                 = htline
           exceptions
                err_max_linewidth     = 1
                err_format            = 2
                err_conv_not_possible = 3
                others                = 4.
    *-Itab 134 Zeichen nach 255 Zeichen überführen
      describe table htline    lines  hltlines.
      describe field htline    length fle1 in character mode.
      describe field x_objcont length fle2 in character mode.
      loop at htline.
        htabix = sy-tabix.
        move htline to hfeld+off1.
        if htabix = hltlines.
          fle1 = strlen( htline ).
        endif.
        off1 = off1 + fle1.
        if off1 ge fle2.
          clear x_objcont.
          x_objcont = hfeld(fle2).
          append x_objcont.
          shift hfeld by fle2 places.
          off1 = off1 - fle2.
        endif.
        if htabix = hltlines.
          if off1 gt 0.
            clear x_objcont.
            x_objcont = hfeld(off1).
            append x_objcont.
          endif.
        endif.
      endloop.
      x_object_hd_change-objnam    = 'EMAIL'.
      x_object_hd_change-objdes    = 'Smart Form'.
      x_object_hd_change-objla     = sy-langu.
      x_object_hd_change-objsns    = 'O'.
      x_object_hd_change-objlen    = doc_size.
      x_object_hd_change-file_ext  = 'TXT'.
      ld_packing_list-transf_bin = 'X'.
      ld_packing_list-head_start = 1.
      ld_packing_list-head_num = 0.
      ld_packing_list-body_start = 1.
      describe table x_objcont lines    ld_packing_list-body_num.
      ld_packing_list-objtp = 'EXT'.
      ld_packing_list-objdes    = 'Smart Form'.
      ld_packing_list-objla     = sy-langu.
      ld_packing_list-objlen    = doc_size.
      ld_packing_list-file_ext  = 'PDF'.
      append ld_packing_list.
      x_receivers-recextnam    = g_mail.
      x_receivers-recesc       = 'E'.
      x_receivers-sndart       = 'INT'.
      append x_receivers.
      ld_originator = '[email protected]'.
    ld_originator = FSABE-USRNAM.
      call function 'SO_OBJECT_SEND'
           exporting
                object_hd_change           = x_object_hd_change
                object_type                = 'RAW'
                originator_type            = 'B'  "Einfügen
                originator                 =   ld_originator  "Einfügen
           tables
               objcont                    = ld_text
                receivers                  = x_receivers
                packing_list               = ld_packing_list
                att_cont                   = x_objcont
                att_head                   = x_objhead
           exceptions
                active_user_not_exist      = 1
                communication_failure      = 2
                component_not_available    = 3
                folder_not_exist           = 4
                folder_no_authorization    = 5
                forwarder_not_exist        = 6
                note_not_exist             = 7
                object_not_exist           = 8
                object_not_sent            = 9
                object_no_authorization    = 10
                object_type_not_exist      = 11
                operation_no_authorization = 12
                owner_not_exist            = 13
                parameter_error            = 14
                substitute_not_active      = 15
                substitute_not_defined     = 16
                system_failure             = 17
                too_much_receivers         = 18
                user_not_exist             = 19
                x_error                    = 20
                others                     = 21.
    endform.                    " send_pdf_mail
    *& Form mail_sender_object
    text
    <--P_G_MAIL_SEN_OBJ text
    form mail_sender_object changing p_mail_sen_obj.
      call function 'CREATE_SENDER_OBJECT_PPF'
           exporting
                ip_sender      = sy-uname
           importing
                ep_sender_id   = p_mail_sen_obj
           exceptions
                invalid_sender = 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.
    endform. " mail_sender_object
    *& Form mail_appl_object
    text
    <--P_G_MAIL_APP_OBJ text
    form mail_appl_object changing p_mail_app_obj.
    SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
    ENDSELECT.
    IF sy-subrc NE 0.
        call function 'SO_USER_AUTOMATIC_INSERT'
             exporting
                  sapname        = sy-uname
             exceptions
                  no_insert      = 1
                  sap_name_exist = 2
                  x_error        = 3
                  others         = 4.
        if sy-subrc ne 0.
          clear soud.
        else.
          select * from soud where sapnam like sy-uname and deleted = ' '.
          endselect.
        endif.
    ENDIF.
      clear sofmfol_key.
      sofmfol_key-type = 'FOL'.
      sofmfol_key-year = soud-inbyr.
      sofmfol_key-number = soud-inbno.
      bor_key = sofmfol_key.
      if not bor_key is initial.
        swc_create_object folder 'SOFMFOL' bor_key.
        if sy-subrc = 0.
          swc_object_to_persistent folder p_mail_app_obj.
          if sy-subrc ne 0.
            clear p_mail_app_obj.
          endif.
        endif.
      else.
        clear p_mail_app_obj.
      endif.
    endform. " mail_appl_object
    *& Form mail_recipient_object
    text
    <--P_G_MAIL_REC_OBJ text
    form mail_recipient_object changing p_mail_rec_obj.
      call function 'CREATE_RECIPIENT_OBJ_PPF'
      exporting
    IP_COUNTRY =
    IP_FAXNO =
       ip_mailaddr = g_mail
       ip_type_id = g_rectype         " 'U'
      importing
        ep_recipient_id = p_mail_rec_obj
    EP_ADDRESS =
    ET_RECIPIENT =
      exceptions
        invalid_recipient = 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.
    endform. " mail_recipient_object
    I hope this code should definitely work and helps you a lot.
    Do reward me if it helps you.
    Cheers,
    Sampath

  • Send report query as email attachment

    Hi,
    I have created a multireport query under Shared Components that allows users to print several sql queries to a pdf file in a prefefined format. Is it possible to generate an email out of Apex with this report query pdf as an attachment (without having the users save the pdf to their hard drive and and manually attach to an email)?
    Thanks,
    Forrest

    Hello RnB,
    You can check the mentioned link for the same:
    [Simple Program to generate PDF from ABAP List Output.|http://www.abapmadeeasy.com/2011/02/sap-abap-simple-program-to-generate-pdf.html]
    Regards,
    Uttam Agrawal

  • Sending reports output to email

    Hi ,
    I would like to send output of a report to email insted of printer. Are there any setting to be done. We are running on 11i.
    Thanks
    Kiran

    Please see the user manual.
    Oracle Alert User's Guide
    http://download.oracle.com/docs/cd/B25516_18/current/acrobat/115alrug.pdf
    Also, see old threads which discuss the same topic -- http://forums.oracle.com/forums/search.jspa?threadID=&q=Send+AND+E-mail+AND+Alert&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • Report output as email

    Hi All,
    I need to send report output as email text. is anybody has done this sort of work or any function module for this.
    Please help if anyone knows it.
    Cheers,
    Lokesh

    Hi
      Check the code for similar requirement I was faced earlier.
    Type for binary attachment table.
      types: l_ty_tab_objbin type solisti1 occurs 0.
      data: l_objbin type l_ty_tab_objbin.
    Tables to hold PDF data
      data: t_doctab type docs occurs 0,
            t_line  type tline occurs 0.
      tables : soli.             "SAPoffice: line, length 255
      tables : zpsdsalrep.       "ZPSDSALREP
      data: l_email type soli-line.
      data: l_email1 type soli-line.
      data: l_adrnr like kna1-adrnr.
      data: l_objky type nast-objky.
      data: l_zzterrmg type zpsdsalrep-zzterrmg.
      data: l_zsupervisor type zpsdsalrep-zsupervisor.
      data: l_kunnr type kna1-kunnr.
      data: l_kunnr1 type vbak-kunnr.
      data: l_reclist like somlreci1 occurs 0 with header line.
      data: l_objtxt    like solisti1 occurs   0 with header line.
      data: l_objpack   like sopcklsti1 occurs 0 with header line.
      data: l_doc_chng  like sodocchgi1.
      data: l_objhead   like solisti1 occurs   0 with header line.
      data: l_tab_lines like sy-tabix.
      constants: k_true type boolean_flg value 'X'.
      data: l_mail type somlreci1-receiver.
      data: l_mail1 type somlreci1-receiver.
      data:
    l_l_mail2 TYPE somlreci1-receiver.
    l_l_mail type somlreci1-receiver.
      data: l_zzsalesrep type zpsdsalrep-zzsalesrep.
      data: l_recipents type somlreci1-receiver.
      constants: k_x(1) type c value 'X',
                 k_u(1) type c value 'U',
                 k_raw(3) type c value 'RAW'.
      call function 'CONVERT_OTF_2_PDF'
    EXPORTING
      USE_OTF_MC_CMD               = 'X'
      ARCHIVE_INDEX                =
    IMPORTING
      BIN_FILESIZE                 =
        tables
          otf                          = t_otfdata
          doctab_archive               = t_doctab
          lines                        = t_line
          exceptions
         err_conv_not_possible        = 1
         err_otf_mc_noendmarker       = 2
         others                       = 3.
      if sy-subrc <> 0.
        write: / 'error', sy-subrc.
      endif.
    ***/ Convert the PDF format to the table type required for the
    **attachment.
      call function 'QCE1_CONVERT'
        tables
          t_source_tab         = t_line
          t_target_tab         = l_objbin
        exceptions
          convert_not_possible = 1
          others               = 2.
      if sy-subrc <> 0.
        write: / 'error', sy-subrc.
      endif.
      select single kunnr from vbak into l_kunnr1
             where vbeln = nast-objky.
      select single adrnr from kna1 into l_adrnr
             where kunnr = l_kunnr1.
      check sy-subrc is initial.
      select single smtp_addr from adr6 into l_email
             where addrnumber = l_adrnr.
    SELECT SINGLE zzterrmg FROM zpsdsalrep INTO l_zzterrmg
            WHERE zzsalesrep = l_kunnr1.
    SELECT SINGLE zsupervisor FROM zpsdsalrep INTO l_zsupervisor
         WHERE  zzterrmg = l_zzterrmg.
    SELECT SINGLE kunnr FROM kna1 INTO l_kunnr
           WHERE sortl = l_zsupervisor.
    SELECT SINGLE zsupervisor FROM zpsdsalrep INTO l_zsupervisor
           WHERE  zzsalesrep = l_kunnr1.
    SELECT SINGLE zzsalesrep FROM zpsdsalrep INTO l_zzsalesrep
           WHERE zzterrmg = l_zsupervisor.
    SELECT SINGLE adrnr FROM kna1 INTO l_adrnr
              WHERE kunnr = l_zzsalesrep.
    CHECK sy-subrc IS INITIAL.
    SELECT SINGLE smtp_addr FROM adr6 INTO l_email1
            WHERE addrnumber = l_adrnr.
    SELECT SINGLE adrnr FROM kna1 INTO l_adrnr
            WHERE kunnr = l_kunnr.
    CHECK sy-subrc IS INITIAL.
    SELECT SINGLE smtp_addr FROM adr6 INTO l_email1
            WHERE addrnumber = l_adrnr.
      l_mail = l_email.
    l_mail1 = l_email1.
    l_l_mail2 = text-006.
      l_l_mail = text-007.
    Creation of the document to be sent
    File Name
      l_doc_chng-obj_name = 'SENDFILE'.
    Mail Subject
      concatenate text-001 nast-objky into l_doc_chng-obj_descr.
    l_doc_chng-obj_descr = text-001.
    Completing the recipient list
      l_reclist-receiver = l_mail.
      l_reclist-rec_type = k_u.
      append l_reclist.
    l_reclist-receiver = l_mail1.
    l_reclist-rec_type = 'U'.
    APPEND l_reclist.
      l_reclist-receiver = l_l_mail.
      l_reclist-rec_type = k_u.
      append l_reclist.
    l_reclist-receiver = l_l_mail2.
    l_reclist-rec_type = 'U'.
    APPEND l_reclist.
    Mail Contents
      l_objtxt = text-002.
      append l_objtxt.
      clear l_objtxt.     " put in a blank line
      append l_objtxt.
      data: l_subject type solisti1.
      concatenate text-003 '-' nast-objky into l_subject.
      l_objtxt = l_subject.
      append l_objtxt.
      l_objtxt = text-004 .
      append l_objtxt.
    Calculate email size in bytes
      describe table l_objtxt lines l_tab_lines.
      read table l_objtxt index l_tab_lines.
      l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + strlen( l_objtxt ).
    Creation of the entry for the compressed document
    for the email text
      clear l_objpack-transf_bin.
      l_objpack-head_start = 1.
      l_objpack-head_num = 0.
      l_objpack-body_start = 1.
      l_objpack-body_num = l_tab_lines.
      l_objpack-doc_type = k_raw.
      append l_objpack.
    Creation of the document attachment
    (Assume that the data in OBJBIN is in BMP format)
      describe table l_objbin lines l_tab_lines.
      l_objhead = text-001  .
      append l_objhead.
      clear l_objpack.
    **/ Creation of the entry for the compressed/attached document
      l_objpack-transf_bin = k_true.
      l_objpack-head_start = 1.
      l_objpack-head_num = 1.
      l_objpack-body_start = 1.
      l_objpack-body_num = l_tab_lines.
      l_objpack-doc_type = 'PDF'.
      l_objpack-obj_name = text-005.
      l_objpack-obj_descr = text-001.
      l_objpack-doc_size = l_tab_lines * 255.
      append l_objpack. "/ .
      delete  l_reclist where receiver = ''.
    Sending the document
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1' " IN UPDATE TASK "/ .
        exporting
          document_data              = l_doc_chng
          put_in_outbox              = k_x
        tables
          packing_list               = l_objpack
          object_header              = l_objhead
          contents_bin               = l_objbin
          contents_txt               = l_objtxt
          receivers                  = l_reclist
        exceptions
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          others                     = 99.
      if sy-subrc <> 0.
        write: / 'unsuccessful', sy-subrc.
      else.
        concatenate l_mail ',' l_mail1 ',' l_l_mail into l_recipents.
        syst-msgid = '8I'.
        syst-msgno = '000'.
        syst-msgty = 'S'.
        syst-msgv1 = text-008.
        skip.
        syst-msgv2 = text-009.
        syst-msgv3 = l_recipents.
        clear:  syst-msgv4. "syst-msgv2, syst-msgv3,
        perform protocol_update.
        write:  / 'successful'.
      endif.
    **/Take_note it is a requirement to do a commit work for the
    email to go into transaction SOST.
    COMMIT WORK.   "/Take_note .
    if sy-subrc eq 0.
    endif.
    Regards,
    Sreeram

  • To send output as email in PDF format

    I am using Function module <b>so_new_document_att_send_api1</b> to send my report output as Email.
    Please tell me how to send it in PDF format.

    1) FIRST GENERATE SPOOL REQUEST  for ur output THEN DOWNLOAD this spool request to a PDF file via REPORT PROGRAM  - RSTXPDFT4 .
    2) then use this program to send this PDf via mail (also see ur SCOT setttings) -
    *& Report  ZGILL_SENDMAIL_PDF                                          *
    REPORT  ZGILL_SENDMAIL_PDF                      .
    INCLUDE ZGILL_INCMAIL.  "SEE BELOW FOR INCLUDE PROGRAM CODE.
    DATA
    DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
    DATA : file_name TYPE string.
    data : path like PCFILE-PATH.
    data : extension(5) type c.
    data : name(100) type c.
    SELECTION SCREEN
    PARAMETERS : receiver TYPE somlreci1-receiver lower case DEFAULT '[email protected]'.
    PARAMETERS : p_file LIKE rlgrap-filename
    OBLIGATORY DEFAULT 'C:\TEMP\SALARY_SLIP1.PDF'.
    AT SELECTION SCREEN
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CLEAR p_file.
    CALL FUNCTION 'F4_FILENAME'
    IMPORTING
    file_name = p_file.
    START-OF-SELECTION
    START-OF-SELECTION.
    PERFORM ml_customize USING 'Tst' 'Testing'.
    PERFORM ml_addrecp USING receiver 'U'.
    PERFORM upl.
    PERFORM doconv TABLES itab objbin.
    PERFORM ml_prepare USING 'X' extension name.
    PERFORM ml_dosend.
    SUBMIT rsconn01
    WITH mode EQ 'INT'
    AND RETURN.
    FORM
    FORM upl.
    file_name = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = file_name
    filetype = 'BIN'
    TABLES
    data_tab = itab
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17.
    path = file_name.
    CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
    EXPORTING
    complete_filename = path
    CHECK_DOS_FORMAT =
    IMPORTING
    DRIVE =
    EXTENSION = extension
    NAME = name
    NAME_WITH_EXT =
    PATH =
    EXCEPTIONS
    INVALID_DRIVE = 1
    INVALID_EXTENSION = 2
    INVALID_NAME = 3
    INVALID_PATH = 4
    OTHERS = 5
    ENDFORM. "upl
    *********************iNCLUDE pROGRAM********************************************
    *&  Include           ZGILL_INCMAIL                                    *
    Data
    DATA: docdata LIKE sodocchgi1,
    objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
    objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
    objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
    objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
    objhex LIKE solix OCCURS 10 WITH HEADER LINE,
    reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
    DATA: tab_lines TYPE i,
    doc_size TYPE i,
    att_type LIKE soodk-objtp.
    DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
    FORM
    FORM ml_customize USING objname objdesc.
    Clear Variables
    CLEAR docdata.
    REFRESH objpack.
    CLEAR objpack.
    REFRESH objhead.
    REFRESH objtxt.
    CLEAR objtxt.
    REFRESH objbin.
    CLEAR objbin.
    REFRESH objhex.
    CLEAR objhex.
    REFRESH reclist.
    CLEAR reclist.
    REFRESH listobject.
    CLEAR listobject.
    CLEAR tab_lines.
    CLEAR doc_size.
    CLEAR att_type.
    Set Variables
    docdata-obj_name = objname.
    docdata-obj_descr = objdesc.
    ENDFORM. "ml_customize
    FORM
    FORM ml_addrecp USING preceiver prec_type.
    CLEAR reclist.
    reclist-receiver = preceiver.
    reclist-rec_type = prec_type.
    APPEND reclist.
    ENDFORM. "ml_customize
    FORM
    FORM ml_addtxt USING ptxt.
    CLEAR objtxt.
    objtxt = ptxt.
    APPEND objtxt.
    ENDFORM. "ml_customize
    FORM
    FORM ml_prepare USING bypassmemory whatatt_type whatname.
    IF bypassmemory = ''.
    Fetch List From Memory
    CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
    listobject = listobject
    EXCEPTIONS
    OTHERS = 1.
    IF sy-subrc <> 0.
    MESSAGE ID '61' TYPE 'E' NUMBER '731'
    WITH 'LIST_FROM_MEMORY'.
    ENDIF.
    CALL FUNCTION 'TABLE_COMPRESS'
    IMPORTING
    COMPRESSED_SIZE =
    TABLES
    in = listobject
    out = objbin
    EXCEPTIONS
    OTHERS = 1
    IF sy-subrc <> 0.
    MESSAGE ID '61' TYPE 'E' NUMBER '731'
    WITH 'TABLE_COMPRESS'.
    ENDIF.
    ENDIF.
    Header Data
    Already Done Thru FM
    Main Text
    Already Done Thru FM
    Packing Info For Text Data
    DESCRIBE TABLE objtxt LINES tab_lines.
    READ TABLE objtxt INDEX tab_lines.
    docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
    CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num = 0.
    objpack-body_start = 1.
    objpack-body_num = tab_lines.
    objpack-doc_type = 'TXT'.
    APPEND objpack.
    Packing Info Attachment
    att_type = whatatt_type..
    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 = whatname.
    APPEND objpack.
    Receiver List
    Already done thru fm
    ENDFORM. "ml_prepare
    FORM
    FORM ml_dosend.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = docdata
    put_in_outbox = 'X'
    commit_work = 'X' "used from rel. 6.10
    IMPORTING
    SENT_TO_ALL =
    NEW_OBJECT_ID =
    TABLES
    packing_list = objpack
    object_header = objhead
    contents_bin = objbin
    contents_txt = objtxt
    CONTENTS_HEX = objhex
    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.
    MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
    WITH docdata-obj_name.
    ENDIF.
    ENDFORM. "ml_customize
    FORM
    FORM ml_spooltopdf USING whatspoolid.
    DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.
    Call Function
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
    EXPORTING
    src_spoolid = whatspoolid
    TABLES
    pdf = pdf
    EXCEPTIONS
    err_no_otf_spooljob = 1
    OTHERS = 12.
    Convert
    PERFORM doconv TABLES pdf objbin.
    ENDFORM. "ml_spooltopdf
    FORM
    FORM doconv TABLES
    mypdf STRUCTURE tline
    outbin STRUCTURE solisti1.
    Data
    DATA : pos TYPE i.
    DATA : len TYPE i.
    Loop And Put Data
    LOOP AT mypdf.
    pos = 255 - len.
    IF pos > 134. "length of pdf_table
    pos = 134.
    ENDIF.
    outbin+len = mypdf(pos).
    len = len + pos.
    IF len = 255. "length of out (contents_bin)
    APPEND outbin.
    CLEAR: outbin, len.
    IF pos < 134.
    outbin = mypdf+pos.
    len = 134 - pos.
    ENDIF.
    ENDIF.
    ENDLOOP.
    IF len > 0.
    APPEND outbin.
    ENDIF.
    ENDFORM. "doconv
    **********************INCLUDE END********************************

  • Reg : Sending Script output to email

    Hi,
    I need to send script output to email.I have written the code for this functionality.
    Functional guy has created output type ,but that output type is red in clor and when I click process log " it says Parameter DEVICE= is invalid "
    Is there anything to be done from abap point for this error.
    Actually I used these 2 fun.modules
    DATA: LVF_DEVICE LIKE ITCPP-TDDEVICE.
    DATA: LVS_ITCPO TYPE ITCPO,
    LVF_DIALOG(1) TYPE C VALUE ' ',
    LVS_RECIPIENT LIKE SWOTOBJID,
    LVS_SENDER LIKE SWOTOBJID,
    LVS_SNAST TYPE SNAST,
    LVF_PROGRAM LIKE SY-REPID,
    LVS_COMM_TYPE TYPE AD_COMM,
    LVS_COMM_VALUES TYPE SZADR_COMM_VALUES.
    DATA:
    W_DEPT LIKE KNVK-ABTNR, "Department
    W_PRSNR LIKE KNVK-PRSNR. "Person number
    reset return code
    RETCODE = 0.
    IF NOT NAST-TCODE IS INITIAL AND NAST-NACHA EQ '5'.
    SELECT SINGLE * FROM USR21 WHERE BNAME = SY-UNAME.
    CALL FUNCTION 'ADDR_GET_NEXT_COMM_TYPE'
    EXPORTING
    strategy = nast-tcode
    address_number = Kna1-adrnr
    IMPORTING
    comm_type = lvs_comm_type
    comm_values = lvs_comm_values
    TABLES
    STRATEGY_TABLE =
    EXCEPTIONS
    address_not_exist = 1
    person_not_exist = 2
    no_comm_type_found = 3
    internal_error = 4
    parameter_error = 5
    OTHERS = 6.
    convert communication data
    Always INT
    LVS_COMM_TYPE = 'INT'.
    clear LVS_COMM_VALUES-ADSMTP-SMTP_ADDR.
    Get Contact persons number from KNVK
    SELECT SINGLE * FROM KNVK WHERE KUNNR EQ NAST-PARNR
    AND ABTNR EQ W_DEPT.
    Get it from ADR6 table always
    Select single * from adr6 where addrnumber = kna1-adrnr
    AND PERSNUMBER = KNVK-PRSNR.
    IF SY-SUBRC EQ 0 AND adr6-Smtp_addr NE ' '.
    LVS_COMM_VALUES-ADSMTP-SMTP_ADDR = adr6-Smtp_addr.
    ENDIF.
    ENDIF.
    MOVE-CORRESPONDING nast TO LVS_SNAST .
    MOVE sy-repid TO LVF_PROGRAM.
    CALL FUNCTION 'CONVERT_COMM_TYPE_DATA'
    EXPORTING
    pi_comm_type = lvs_comm_type
    pi_comm_values = lvs_comm_values
    pi_country = kna1-land1
    pi_repid = LVF_PROGRAM
    pi_snast = LVS_SNAST
    IMPORTING
    pe_itcpo = lvs_itcpo
    pe_device = lvf_device
    pe_mail_recipient = lvs_recipient
    pe_mail_sender = lvs_sender
    EXCEPTIONS
    comm_type_not_supported = 1
    recipient_creation_failed = 2
    sender_creation_failed = 3
    OTHERS = 4.
    fill structure itcpo
    ITCPO = LVS_ITCPO.
    CALL FUNCTION 'OPEN_FORM'
    EXPORTING
    APPLICATION = 'TX'
    ARCHIVE_INDEX = TOA_DARA
    ARCHIVE_PARAMS = ARC_PARAMS
    DEVICE = LVF_DEVICE
    DIALOG = ' '
    FORM = TNAPR-FONAM
    LANGUAGE = NAST-SPRAS
    OPTIONS = LVS_ITCPO
    MAIL_SENDER = LVS_SENDER
    MAIL_RECIPIENT = LVS_RECIPIENT
    MAIL_APPL_OBJECT = ' '
    RAW_DATA_INTERFACE = '*'
    IMPORTING
    LANGUAGE =
    NEW_ARCHIVE_PARAMS =
    RESULT =
    EXCEPTIONS
    CANCELED = 1
    DEVICE = 2
    FORM = 3
    OPTIONS = 4
    UNCLOSED = 5
    MAIL_OPTIONS = 6
    ARCHIVE_ERROR = 7
    OTHERS = 8.
    IF SY-SUBRC NE 0.
    CASE SY-SUBRC.
    WHEN 7.
    RETCODE = SY-SUBRC.
    SYST-MSGID = 'VN'.
    SYST-MSGNO = '096'.
    SYST-MSGTY = 'E'.
    SYST-MSGV1 = NAST-KSCHL.
    SYST-MSGV2 = NAST-KAPPL.
    PERFORM PROTOCOL_UPDATE.
    WHEN OTHERS.
    RETCODE = SY-SUBRC.
    PERFORM PROTOCOL_UPDATE.
    ENDCASE.
    ENDIF.
    and one more query is :
    I want to know weather
    "Are there any settings need to be done by BASIS people."
    If Anyone has any idea plz reply.

    Hi
    Use the below peace of code,I was used to send sales order confirmation script output as email.
    Change History
    Programmer   Date     Change Request Description
    FKHURRAM     9/16/02  DU1K920151     Upgrade changes.
                                         Use ADRC for Address Data
                 Print of an order confirmation by SAPscript
    REPORT rvador01 LINE-COUNT 100 MESSAGE-ID vn.
    TABLES: komk,                          "Communicationarea for conditions
            komp,                          "Communicationarea for conditions
            komvd,                         "Communicationarea for conditions
            vbco3,                         "Communicationarea for view
            vbdka,                         "Headerview
            vbdpa,                         "Itemview
            vbdpau,                        "Subitemnumbers
            conf_out,                      "Configuration data
            sadr,                          "Addresses
            tvag,                          "Reason for rejection
            vedka,                         "Servicecontract head data
            vedpa,                         "Servicecontract position data
            vedkn,                         "Servicecontract head notice data
            vedpn,                         "Servicecontract pos. notice data
            vbpa,                          "Sales Document: Partner
            kna1,                          "General Data in Customer Master
            riserls,                       "Serialnumbers
            komser,                        "Serialnumbers for print
            tvbur,                         "Sales office
            tvko,                          "Sales organisation
            adrs,                          "Communicationarea for Address
            fpltdr.                        "billing schedules
    INCLUDE yzrvadtabl.
    *INCLUDE RVADTABL.
    INCLUDE yzrvdirekt.
    *INCLUDE RVDIREKT.
    INCLUDE yzvedadata.
    *INCLUDE VEDADATA.
    DATA: retcode   LIKE sy-subrc.         "Returncode
    DATA: repeat(1) TYPE c.
    DATA: xscreen(1) TYPE c.               "Output on printer or screen
    DATA: BEGIN OF steu,                   "Controldata for output
            vdkex(1) TYPE c,
            vdpex(1) TYPE c,
            kbkex(1) TYPE c,
            kbpex(1) TYPE c,
          END OF steu.
    DATA: BEGIN OF tvbdpa OCCURS 0.        "Internal table for items
            INCLUDE STRUCTURE vbdpa.
    DATA: END OF tvbdpa.
    DATA: BEGIN OF tkomv OCCURS 50.
            INCLUDE STRUCTURE komv.
    DATA: END OF tkomv.
    DATA: BEGIN OF tkomvd OCCURS 50.
            INCLUDE STRUCTURE komvd.
    DATA: END OF tkomvd.
    DATA: BEGIN OF tvbdpau OCCURS 5.
            INCLUDE STRUCTURE vbdpau.
    DATA: END   OF tvbdpau.
    DATA: BEGIN OF tkomcon OCCURS 50.
            INCLUDE STRUCTURE conf_out.
    DATA: END   OF tkomcon.
    DATA: BEGIN OF tkomservh OCCURS 1.
            INCLUDE STRUCTURE vedka.
    DATA: END   OF tkomservh.
    DATA: BEGIN OF tkomservp OCCURS 5.
            INCLUDE STRUCTURE vedpa.
    DATA: END   OF tkomservp.
    DATA: BEGIN OF tkomservhn OCCURS 5.
            INCLUDE STRUCTURE vedkn.
    DATA: END   OF tkomservhn.
    DATA: BEGIN OF tkomservpn OCCURS 5.
            INCLUDE STRUCTURE vedpn.
    DATA: END   OF tkomservpn.
    DATA: BEGIN OF tkomser OCCURS 5.
            INCLUDE STRUCTURE riserls.
    DATA: END   OF tkomser.
    DATA: BEGIN OF tkomser_print OCCURS 5.
            INCLUDE STRUCTURE komser.
    DATA: END   OF tkomser_print.
    DATA: BEGIN OF tfpltdr OCCURS 5.
            INCLUDE STRUCTURE fpltdr.
    DATA: END   OF tfpltdr.
    DATA: pr_kappl(01)   TYPE c VALUE 'V'. "Application for pricing
    DATA: BEGIN OF char_val OCCURS 0,
            atnam LIKE cabn-atnam,
            atwrt LIKE ausp-atwrt,
          END OF char_val.
    FORM entry USING return_code us_screen.
      CLEAR retcode.
      xscreen = us_screen.
      PERFORM processing.
      IF retcode NE 0.
        return_code = 1.
      ELSE.
        return_code = 0.
      ENDIF.
    ENDFORM.                    "ENTRY
          FORM PROCESSING                                               *
    FORM processing.
      PERFORM get_data.
      CHECK retcode = 0.
      PERFORM form_open USING xscreen vbdka-land1.
      CHECK retcode = 0.
      PERFORM logo_selection.
      PERFORM form_title_print.
      CHECK retcode = 0.
      PERFORM write_header_info.
      PERFORM validity_print.
      CHECK retcode = 0.
      PERFORM header_data_print.
      CHECK retcode = 0.
      PERFORM header_serv_print.
      CHECK retcode = 0.
      PERFORM header_notice_print.
      CHECK retcode = 0.
      PERFORM header_inter_print.
      CHECK retcode = 0.
      PERFORM header_text_print.
      CHECK retcode = 0.
      PERFORM item_print.
      CHECK retcode = 0.
      PERFORM end_print.
      CHECK retcode = 0.
      PERFORM form_close.
      CHECK retcode = 0.
    *********************changes on 12/04/2007****************
      TABLES: tsp01.
      TYPES: BEGIN OF t_spool,
             rqident TYPE tsp01-rqident,
            END OF t_spool.
      DATA: i_spool TYPE STANDARD TABLE OF t_spool,
            wa_spool TYPE t_spool.
      SELECT  rqident FROM tsp01
      INTO TABLE i_spool
    WHERE rqowner = sy-uname.
      SORT i_spool DESCENDING BY rqident.
      LOOP AT i_spool INTO wa_spool.
      ENDLOOP.
    data: l_rqident type tsp01-rqident.
    SELECT SINGLE rqident FROM tsp01 INTO l_rqident
    WHERE rqowner = sy-uname.
    DATA: l_spoolno LIKE tsp01-rqident VALUE '0000024884'.
      TYPES: l_ty_tab_pdf TYPE tline OCCURS 0.
      DATA: l_pdf TYPE l_ty_tab_pdf,
            l_spool TYPE tsp01-rqident.
    Type for binary attachment table.
      TYPES: l_ty_tab_objbin TYPE solisti1 OCCURS 0.
      DATA: l_objbin TYPE l_ty_tab_objbin.
    l_spool = l_spoolno.
      l_spool = l_rqident.
      l_spool = wa_spool-rqident.
    **/ Call the standard function
      CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'             "#EC ARGCHECKED
          EXPORTING
            src_spoolid                    = l_spool
            no_dialog                      = ' '
          DST_DEVICE                     =
          PDF_DESTINATION                =
         IMPORTING
           pdf_bytecount                  = numbytes
           pdf_spoolid                    = pdfspoolid
          LIST_PAGECOUNT                 =
           btc_jobname                    = jobname
           btc_jobcount                   = jobcount
          TABLES
            pdf                            = l_pdf
          EXCEPTIONS
            err_no_abap_spooljob           = 1
            err_no_spooljob                = 2
            err_no_permission              = 3
            err_conv_not_possible          = 4
            err_bad_destdevice             = 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.
      IF sy-subrc <> 0.
        WRITE: / 'error', sy-subrc.
      ENDIF.
    **/ Convert the PDF format to the table type required for the
    *attachment.
      CALL FUNCTION 'QCE1_CONVERT'
        TABLES
          t_source_tab         = l_pdf
          t_target_tab         = l_objbin
        EXCEPTIONS
          convert_not_possible = 1
          OTHERS               = 2.
      IF sy-subrc <> 0.
        WRITE: / 'error', sy-subrc.
      ENDIF.
      TABLES : soli.
      TABLES : zpsdsalrep.
      DATA: v_email TYPE soli-line.
      DATA: v_email1 TYPE soli-line.
      DATA: l_adrnr LIKE kna1-adrnr.
      DATA: l_objky TYPE nast-objky.
      DATA: l_zzterrmg TYPE zpsdsalrep-zzterrmg.
      DATA: l_zsupervisor TYPE zpsdsalrep-zsupervisor.
      DATA: l_kunnr TYPE kna1-kunnr.
      DATA: l_kunnr1 TYPE vbak-kunnr.
      SELECT SINGLE kunnr FROM vbak INTO l_kunnr1
             WHERE vbeln = nast-objky.
      SELECT SINGLE adrnr FROM kna1 INTO l_adrnr
             WHERE kunnr = l_kunnr1.
      CHECK sy-subrc IS INITIAL.
      SELECT SINGLE smtp_addr FROM adr6 INTO v_email
             WHERE addrnumber = l_adrnr.
      SELECT SINGLE zzterrmg FROM zpsdsalrep INTO l_zzterrmg
             WHERE zzsalesrep = l_kunnr1.
      SELECT SINGLE zsupervisor FROM zpsdsalrep INTO l_zsupervisor
          WHERE  zzterrmg = l_zzterrmg.
      SELECT SINGLE kunnr FROM kna1 INTO l_kunnr
            WHERE sortl = l_zsupervisor.
      SELECT SINGLE adrnr FROM kna1 INTO l_adrnr
             WHERE kunnr = l_kunnr.
      CHECK sy-subrc IS INITIAL.
      SELECT SINGLE smtp_addr FROM adr6 INTO v_email1
             WHERE addrnumber = l_adrnr.
      DATA: l_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
      DATA: l_objtxt    LIKE solisti1 OCCURS   0 WITH HEADER LINE.
      DATA: l_objpack   LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
      DATA: l_doc_chng  LIKE sodocchgi1.
      DATA: l_objhead   LIKE solisti1 OCCURS   0 WITH HEADER LINE.
      DATA: l_tab_lines LIKE sy-tabix.
      CONSTANTS: k_true TYPE boolean_flg VALUE 'X'.
      DATA: l_mail TYPE somlreci1-receiver.
      DATA: l_mail1 TYPE somlreci1-receiver.
      DATA: k_mail2 TYPE somlreci1-receiver.
      DATA: k_mail TYPE somlreci1-receiver.
      l_mail = v_email.
      l_mail1 = v_email1.
      k_mail2 = text-006.
      k_mail = text-007.
    Creation of the document to be sent
    File Name
      l_doc_chng-obj_name = 'SENDFILE'.
    Mail Subject
      l_doc_chng-obj_descr = text-001.
    Completing the recipient list
      l_reclist-receiver = l_mail.
      l_reclist-rec_type = 'U'.
      APPEND l_reclist.
      l_reclist-receiver = l_mail1.
      l_reclist-rec_type = 'U'.
      APPEND l_reclist.
      l_reclist-receiver = k_mail.
      l_reclist-rec_type = 'U'.
      APPEND l_reclist.
      l_reclist-receiver = k_mail2.
      l_reclist-rec_type = 'U'.
      APPEND l_reclist.
    Mail Contents
      l_objtxt = text-002.
      APPEND l_objtxt.
      CLEAR l_objtxt.     " put in a blank line
      APPEND l_objtxt.
      l_objtxt = text-003.
      APPEND l_objtxt.
      l_objtxt = text-004 .
      APPEND l_objtxt.
    Calculate email size in bytes
      DESCRIBE TABLE l_objtxt LINES l_tab_lines.
      READ TABLE l_objtxt INDEX l_tab_lines.
      l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_objtxt ).
    Creation of the entry for the compressed document
    for the email text
      CLEAR l_objpack-transf_bin.
      l_objpack-head_start = 1.
      l_objpack-head_num = 0.
      l_objpack-body_start = 1.
      l_objpack-body_num = l_tab_lines.
      l_objpack-doc_type = 'RAW'.
      APPEND l_objpack.
    Creation of the document attachment
    (Assume that the data in OBJBIN is in BMP format)
      DESCRIBE TABLE l_objbin LINES l_tab_lines.
      l_objhead = text-001  .
      APPEND l_objhead.
      CLEAR l_objpack.
    **/ Creation of the entry for the compressed/attached document
      l_objpack-transf_bin = k_true.
      l_objpack-head_start = 1.
      l_objpack-head_num = 1.
      l_objpack-body_start = 1.
      l_objpack-body_num = l_tab_lines.
      l_objpack-doc_type = 'PDF'.
      l_objpack-obj_name = text-005.
      l_objpack-obj_descr = text-001.
      l_objpack-doc_size = l_tab_lines * 255.
      APPEND l_objpack. "/ .
    Sending the document
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' "/ .
        EXPORTING
          document_data              = l_doc_chng
          put_in_outbox              = 'X'
        TABLES
          packing_list               = l_objpack
          object_header              = l_objhead
          contents_bin               = l_objbin
          contents_txt               = l_objtxt
          receivers                  = l_reclist
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
      IF sy-subrc <> 0.
        WRITE: / 'unsuccessful', sy-subrc.
      ELSE.
        WRITE:  / 'successful'.
      ENDIF.
    **/Take_note it is a requirement to do a commit work for the
    email to go into transaction SOST.
      COMMIT WORK.   "/Take_note .
    ENDFORM.                    "PROCESSING
          S U B R O U T I N E S                                         *
          FORM ALTERNATIVE_ITEM                                         *
          A text is printed, if the item is an alternative item.        *
    FORM alternative_item.
      CHECK vbdpa-grpos CN '0'.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'ALTERNATIVE_ITEM'
        EXCEPTIONS
          element = 1
          window  = 2.
      IF sy-subrc NE 0.
        PERFORM protocol_update.
      ENDIF.
    ENDFORM.                    "ALTERNATIVE_ITEM
          FORM CHECK_REPEAT                                             *
          A text is printed, if it is a repeat print for the document.  *
    FORM check_repeat.
      CLEAR repeat.
      SELECT * INTO *nast FROM nast WHERE kappl = nast-kappl
                                    AND   objky = nast-objky
                                    AND   kschl = nast-kschl
                                    AND   spras = nast-spras
                                    AND   parnr = nast-parnr
                                    AND   parvw = nast-parvw
                                    AND   nacha BETWEEN '1' AND '4'.
        CHECK *nast-vstat = '1'.
        repeat = 'X'.
        EXIT.
      ENDSELECT.
    ENDFORM.                    "CHECK_REPEAT
          FORM DELIVERY_DATE                                            *
          If the delivery date in the item is different to the header   *
          date and there are no scheduled quantities, the delivery date *
          is printed in the item block.                                 *
    FORM delivery_date.
      IF vbdka-lfdat =  space AND
         vbdpa-lfdat NE space AND
         vbdpa-etenr_da = space.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            element = 'ITEM_DELIVERY_DATE'
          EXCEPTIONS
            element = 1
            window  = 2.
        IF sy-subrc NE 0.
          PERFORM protocol_update.
        ENDIF.
      ENDIF.
    ENDFORM.                    "DELIVERY_DATE
          FORM DIFFERENT_CONSIGNEE                                      *
          If the consignee in the item is different to the header con-  *
          signee, it is printed by this routine.                        *
    FORM different_consignee.
      CHECK vbdka-name1_we NE vbdpa-name1_we
        OR  vbdka-name2_we NE vbdpa-name2_we
        OR  vbdka-name3_we NE vbdpa-name3_we
        OR  vbdka-name4_we NE vbdpa-name4_we.
      CHECK vbdpa-name1_we NE space
        OR  vbdpa-name2_we NE space
        OR  vbdpa-name3_we NE space
        OR  vbdpa-name4_we NE space.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'ITEM_CONSIGNEE'
        EXCEPTIONS
          element = 1
          window  = 2.
      IF sy-subrc NE 0.
        PERFORM protocol_update.
      ENDIF.
    ENDFORM.                    "DIFFERENT_CONSIGNEE
          FORM DIFFERENT_REFERENCE_NO                                   *
          If the reference number in the item is different to the header*
          reference number, it is printed by this routine.              *
    FORM different_reference_no.
      CHECK vbdpa-vbeln_vang NE vbdka-vbeln_vang
        OR  vbdpa-vbtyp_vang NE vbdka-vbtyp_vang.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'ITEM_REFERENCE_NO'
        EXCEPTIONS
          element = 1
          window  = 2.
      IF sy-subrc NE 0.
        PERFORM protocol_update.
      ENDIF.
    ENDFORM.                    "DIFFERENT_REFERENCE_NO
          FORM DIFFERENT_TERMS                                          *
          If the terms in the item are different to the header terms,   *
          they are printed by this routine.                             *
    FORM different_terms.
      DATA: us_vposn   LIKE vedpa-vposn.
      DATA: us_text(1) TYPE c.             "Flag for Noticetext was printed
      IF vbdpa-zterm NE vbdka-zterm AND
         vbdpa-zterm NE space.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            element = 'ITEM_TERMS_OF_PAYMENT'
          EXCEPTIONS
            element = 1
            window  = 2.
        IF sy-subrc NE 0.
          PERFORM protocol_update.
        ENDIF.
      ENDIF.
      IF vbdpa-inco1 NE space.
        IF vbdpa-inco1 NE vbdka-inco1 OR
           vbdpa-inco2 NE vbdka-inco2.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'ITEM_TERMS_OF_DELIVERY'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        ENDIF.
      ENDIF.
    Print different validity-data for the position
      READ TABLE tkomservp WITH KEY vbdpa-posnr.
      IF sy-subrc EQ 0.
        vedpa = tkomservp.
        IF vedpa-vbegdat NE space       AND
           vedpa-venddat NE space       AND
           NOT vedpa-vbegdat IS INITIAL AND
           NOT vedpa-venddat IS INITIAL.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'ITEM_TERMS_OF_SERV1'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        ELSEIF vedpa-vbegdat NE space AND
               NOT vedpa-vbegdat IS INITIAL.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'ITEM_TERMS_OF_SERV2'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        ELSE.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'ITEM_TERMS_OF_SERV3'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        ENDIF.
      ENDIF.
    Notice-rules for the positions.
      MOVE vbdpa-posnr TO us_vposn.
      CLEAR us_text.
      LOOP AT tkomservpn WHERE vposn = us_vposn.
        vedpn = tkomservpn.
        IF us_text IS INITIAL.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'ITEM_TERMS_OF_NOTTXT'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
          us_text = charx.
        ENDIF.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            element = 'ITEM_TERMS_OF_NOTICE'
          EXCEPTIONS
            element = 1
            window  = 2.
        IF sy-subrc NE 0.
          PERFORM protocol_update.
        ENDIF.
      ENDLOOP.
      IF NOT us_text IS INITIAL.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            element = 'EMPTY_LINE'
          EXCEPTIONS
            element = 1
            window  = 2.
        IF sy-subrc NE 0.
          PERFORM protocol_update.
        ENDIF.
      ENDIF.
    ENDFORM.                    "DIFFERENT_TERMS
          FORM END_PRINT                                                *
    FORM end_print.
      PERFORM get_header_prices.
      CALL FUNCTION 'CONTROL_FORM'
        EXPORTING
          command = 'PROTECT'.
      PERFORM header_price_print.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'END_VALUES'.
      CALL FUNCTION 'CONTROL_FORM'
        EXPORTING
          command = 'ENDPROTECT'.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'SUPPLEMENT_TEXT'
        EXCEPTIONS
          element = 1
          window  = 2.
      IF sy-subrc NE 0.
        PERFORM protocol_update.
      ENDIF.
    ENDFORM.                    "END_PRINT
          FORM FORM_CLOSE                                               *
          End of printing the form                                      *
    FORM form_close.
      CALL FUNCTION 'CLOSE_FORM'
        EXCEPTIONS
          OTHERS = 1.
      IF sy-subrc NE 0.
        PERFORM protocol_update.
        retcode = 1.
      ENDIF.
      SET COUNTRY space.
    ENDFORM.                    "FORM_CLOSE
          FORM FORM_OPEN                                                *
          Start of printing the form                                    *
    -->  US_SCREEN  Output on screen                                   *
                     ' ' = printer                                      *
                     'X' = screen                                       *
    -->  US_COUNTRY County for telecommunication and SET COUNTRY       *
    FORM form_open USING us_screen us_country.
      INCLUDE yzrvadopfo.
    INCLUDE RVADOPFO.
    ENDFORM.                    "FORM_OPEN
          FORM FORM_TITLE_PRINT                                         *
          Printing of the form title depending of the field VBTYP       *
    FORM form_title_print.
      CASE vbdka-vbtyp.
        WHEN 'A'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_A'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'B'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_B'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'C'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_C'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'E'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_E'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'F'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_F'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'G'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_F'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'H'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_H'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'K'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_K'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN 'L'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_L'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        WHEN OTHERS.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TITLE_OTHERS'
              window  = 'TITLE'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
      ENDCASE.
      IF repeat NE space.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            element = 'REPEAT'
            window  = 'REPEAT'
          EXCEPTIONS
            element = 1
            window  = 2.
        IF sy-subrc NE 0.
          PERFORM protocol_update.
        ENDIF.
      ENDIF.
    ENDFORM.                    "FORM_TITLE_PRINT
          FORM GET_DATA                                                 *
          General provision of data for the form                        *
    FORM get_data.
      DATA: us_veda_vbeln     LIKE veda-vbeln.
      DATA: us_veda_posnr_low LIKE veda-vposn.
      CALL FUNCTION 'RV_PRICE_PRINT_REFRESH'
        TABLES
          tkomv = tkomv.
      CLEAR komk.
      CLEAR komp.
      vbco3-mandt = sy-mandt.
      vbco3-spras = nast-spras.
      vbco3-vbeln = nast-objky.
      vbco3-kunde = nast-parnr.
      vbco3-parvw = nast-parvw.
      CALL FUNCTION 'RV_DOCUMENT_PRINT_VIEW'
        EXPORTING
          comwa = vbco3
        IMPORTING
          kopf  = vbdka
        TABLES
          pos   = tvbdpa.
    Fetch servicecontract-data and notice-data for head and position.
      us_veda_vbeln     = vbdka-vbeln.
      us_veda_posnr_low = posnr_low.
      CALL FUNCTION 'SD_VEDA_GET_PRINT_DATA'
        EXPORTING
          i_document_number = us_veda_vbeln
          i_language        = sy-langu
          i_posnr_low       = us_veda_posnr_low
        TABLES
          print_data_pos    = tkomservp
          print_data_head   = tkomservh
          print_notice_pos  = tkomservpn
          print_notice_head = tkomservhn.
      PERFORM get_controll_data.
      PERFORM sender.
      PERFORM check_repeat.
      PERFORM tvbdpau_create.
    ENDFORM.                    "GET_DATA
          FORM GET_ITEM_BILLING_SCHEDULES                               *
          In this routine the billing schedules are fetched from the    *
          database.                                                     *
    FORM get_item_billing_schedules.
      REFRESH tfpltdr.
      CHECK NOT vbdpa-fplnr IS INITIAL.
      CALL FUNCTION 'BILLING_SCHED_PRINTVIEW_READ'
        EXPORTING
          i_fplnr    = vbdpa-fplnr
          i_language = nast-spras
        TABLES
          zfpltdr    = tfpltdr.
    ENDFORM.                    "GET_ITEM_BILLING_SCHEDULES
    *&      Form  ITEM_BILLING_SCHEDULES_PRINT
          This routine prints the billing shedules of a salesdocument    *
          position.                                                      *
    FORM  item_billing_schedules_print.
      DATA: first_line(1) TYPE c.
      first_line = charx.
      LOOP AT tfpltdr.
        fpltdr = tfpltdr.
      Output of the following printlines
        IF NOT fpltdr-perio IS INITIAL.
        periodische Fakturen
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'ITEM_BILLING_SCHEDULE_PERIODIC'
            EXCEPTIONS
              element = 1
              window  = 2.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        bei periodischen nur eine Zeile
          EXIT.
        ELSEIF fpltdr-fareg CA '14'.
        prozentuale Teilfakturierung
          IF NOT first_line IS INITIAL.
            CLEAR first_line.
            CALL FUNCTION 'WRITE_FORM'
              EXPORTING
                element = 'ITEM_BILLING_SCHEDULE_PERCENT_HEADER'
              EXCEPTIONS
                element = 1
                window  = 2.
            IF sy-subrc NE 0.
              PERFORM protocol_update.
            ENDIF.
          ELSE.
            CALL FUNCTION 'WRITE_FORM'
              EXPORTING
                element = 'ITEM_BILLING_SCHEDULE_PERCENT'
              EXCEPTIONS
                element = 1
                window  = 2.
            IF sy-subrc NE 0.
              PERFORM protocol_update.
            ENDIF.
          ENDIF.
        ELSEIF fpltdr-fareg CA '235'.
        wertmäßige  Teilfakturierung
          IF NOT first_line IS INITIAL.
            CLEAR first_line.
            CALL FUNCTION 'WRITE_FORM'
              EXPORTING
                element = 'ITEM_BILLING_SCHEDULE_VALUE_HEADER'
              EXCEPTIONS
                element = 1
                window  = 2.
            IF sy-subrc NE 0.
              PERFORM protocol_update.
            ENDIF.
          ELSE.
            CALL FUNCTION 'WRITE_FORM'
              EXPORTING
                element = 'ITEM_BILLING_SCHEDULE_VALUE'
              EXCEPTIONS
                element = 1
                window  = 2.
            IF sy-subrc NE 0.
              PERFORM protocol_update.
            ENDIF.
          ENDIF.
        ELSEIF fpltdr-fareg CA '3'.
        Schlußrechnung
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "ITEM_BILLING_SCHEDULES_PRINT
    *eject
          FORM GET_ITEM_CHARACTERISTICS                                 *
          In this routine the configuration data item is fetched from   *
          the database.                                                 *
    FORM get_item_characteristics.
      REFRESH tkomcon.
      CHECK NOT vbdpa-cuobj IS INITIAL.
      CALL FUNCTION 'CUD0_GET_CONFIGURATION'                    "#EC EXISTS
        EXPORTING
          instance      = vbdpa-cuobj
          language      = nast-spras
        TABLES
          configuration = tkomcon
        EXCEPTIONS
          OTHERS        = 4.
    ENDFORM.                    "GET_ITEM_CHARACTERISTICS
          FORM GET_ITEM_PRICES                                          *
          In this routine the price data for the item is fetched from   *
          the database.                                                 *
    FORM get_item_prices.
      CLEAR: komp,
             tkomv.
      IF komk-knumv NE vbdka-knumv.
        CLEAR komk.
        komk-mandt = sy-mandt.
        komk-kalsm = vbdka-kalsm.
        komk-kappl = pr_kappl.
        komk-waerk = vbdka-waerk.
        komk-knumv = vbdka-knumv.
        komk-vbtyp = vbdka-vbtyp.
      ENDIF.
      komp-kposn = vbdpa-posnr.
      CALL FUNCTION 'RV_PRICE_PRINT_ITEM'
        EXPORTING
          comm_head_i = komk
          comm_item_i = komp
          language    = nast-spras
        IMPORTING
          comm_head_e = komk
          comm_item_e = komp
        TABLES
          tkomv       = tkomv
          tkomvd      = tkomvd.
    ENDFORM.                    "GET_ITEM_PRICES
          FORM GET_HEADER_PRICES                                        *
          In this routine the price data for the header is fetched from *
          the database.                                                 *
    FORM get_header_prices.
      CALL FUNCTION 'RV_PRICE_PRINT_HEAD'
        EXPORTING
          comm_head_i = komk
          language    = nast-spras
        IMPORTING
          comm_head_e = komk
        TABLES
          tkomv       = tkomv
          tkomvd      = tkomvd.
    ENDFORM.                    "GET_HEADER_PRICES
    *&      Form  HEADER_DATA_PRINT
          Printing of header data like terms, weights ....               *
    FORM header_data_print.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'HEADER_DATA'
        EXCEPTIONS
          element = 1
          window  = 2.
      IF sy-subrc NE 0.
        PERFORM protocol_update.
      ENDIF.
    ENDFORM.                               " HEADER_DATA_PRINT
          FORM HEADER_PRICE_PRINT                                       *
          Printout of the header prices                                 *
    FORM header_price_print.
      LOOP AT tkomvd.
        AT FIRST.
          IF komk-supos NE 0.
            CALL FUNCTION 'WRITE_FORM'
              EXPORTING
                element = 'ITEM_SUM'.
          ELSE.
            CALL FUNCTION 'WRITE_FORM'
              EXPORTING
                element = 'UNDER_LINE'
              EXCEPTIONS
                element = 1
                window  = 2.
            IF sy-subrc NE 0.
              PERFORM protocol_update.
            ENDIF.
          ENDIF.
        ENDAT.
        komvd = tkomvd.
        IF komvd-koaid = 'D'.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'TAX_LINE'.
        ELSE.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'SUM_LINE'.
        ENDIF.
      ENDLOOP.
      DESCRIBE TABLE tkomvd LINES sy-tfill.
      IF sy-tfill = 0.
        CALL FUNCTION 'WRITE_FORM'
          EXPORTING
            element = 'UNDER_LINE'
          EXCEPTIONS
            element = 1
            window  = 2.
        IF sy-subrc NE 0.
          PERFORM protocol_update.
        ENDIF.
      ENDIF.
    ENDFORM.                    "HEADER_PRICE_PRINT
          FORM HEADER_TEXT_PRINT                                        *
          Printout of the headertexts                                   *
    FORM header_text_print.
      CALL FUNCTION 'WRITE_FORM'
        EXPORTING
          element = 'HEADER_TEXT'
        EXCEPTIONS
          element = 1
          window  = 2.
      IF sy-subrc NE 0.
        PERFORM protocol_update.
      ENDIF.
    ENDFORM.                    "HEADER_TEXT_PRINT
          FORM ITEM_CHARACERISTICS_PRINT                                *
          Printout of the item characteristics -> configuration         *
    FORM item_characteristics_print.
      LOOP AT tkomcon.
        conf_out = tkomcon.
        IF sy-tabix = 1.
          CALL FUNCTION 'WRITE_FORM'
            EXPORTING
              element = 'ITEM_LINE_CONFIGURATION_HEADER'
            EXCEPTIONS
              OTHERS  = 1.
          IF sy-subrc NE 0.
            PERFORM protocol_update.
          ENDIF.
        ELSE.
          CALL FUNCTION 'WRITE_FORM'
            EXPOR

  • Error while sending PO output through mail in PDF format - Urgent

    Dear friends,
    Developed program to send sapscript output through mail in pdf format, the program running properly, even function module SO_NEW_DOCUMENT_ATT_SEND_API1 returning sy-subrc 0. But the external mail is not going to user lying in SAP outbox with message <b>"Wait for communications service"</b> . SCOT is properly configured, tested mails sending through SAP office.
    Find below the source code:
    REPORT  zmm_porder_gm
                NO STANDARD PAGE HEADING.
    TABLES: ekko, ekpa, t161t, t052, komv, j_1imocomp, t001, esll.
    Internal Tables
    DATA : txt LIKE tline-tdline,  "HEADER LINE
           your_ref LIKE ekko-ihrez, "your ref
           our_ref  LIKE ekko-unsez, "our ref
           mcompname  LIKE  t001-butxt,
           itemname   LIKE  ekpo-txz01,
           del_text LIKE tline-tdline, "delivery text
           mat_po_text LIKE tline-tdline. "material po text
    DATA: g_ind TYPE i.
    DATA: it_esll LIKE esll OCCURS 0 WITH HEADER LINE.
    DATA: sub_packno LIKE esll-sub_packno.
    DATA : po_flag(1) TYPE c.
    DATA : it_erev LIKE erev OCCURS 0 WITH HEADER LINE.
    DATA : nmebeln LIKE thead-tdname,
           obj LIKE thead-tdname.
    DATA : tline LIKE tline OCCURS 0 WITH HEADER LINE.  "HEADER TEXT
    DATA  : it_ekko LIKE ekko OCCURS 0 WITH HEADER LINE.
    DATA  : it_ekpo LIKE ekpo OCCURS 0 WITH HEADER LINE.
    DATA  : it_zmm_porder  LIKE zmm_porder OCCURS 0 WITH HEADER LINE.
    DATA  : it_konv        LIKE konv OCCURS 0 WITH HEADER LINE.
    DATA  : it_konv_ftr    LIKE konv OCCURS 0 WITH HEADER LINE.
    DATA  : it_konv_rate   LIKE konv OCCURS 0 WITH HEADER LINE.
    DATA  : it_komv_tax    LIKE komv OCCURS 0 WITH HEADER LINE.           " For Tax Calculation
    DATA  : it_zmm_house_bank LIKE zmm_house_bank OCCURS 0 WITH HEADER LINE.
    *DATA  : mrate TYPE konv-kbetr VALUE 0, mrate1(15).  rmoved by ganes and added following logic
    DATA  : mrate TYPE p VALUE 0 DECIMALS 2, mrate1(15).
    DATA  : mrate_gm TYPE p  DECIMALS 2.
    DATA  : BEGIN OF it_konv1 OCCURS 0,
                  knumv LIKE konv-knumv,
                  kschl LIKE konv-kschl,
    END OF it_konv1.
    DATA : BEGIN OF it_t052u OCCURS 0.
            INCLUDE STRUCTURE t052u.
    DATA : END OF it_t052u.
    DATA  : mpay_terms LIKE t052u-text1.
    DATA  : mwaers     LIKE konv-waers.
    DATA : BEGIN OF xt052 OCCURS 0.
            INCLUDE STRUCTURE t052.
    DATA : END OF xt052.
    DATA : it_t16ct LIKE t16ct OCCURS 0 WITH HEADER LINE.
    DATA : BEGIN OF ztext OCCURS 0.
            INCLUDE STRUCTURE ttext.
    DATA : END OF ztext.
    DATA  : it_t001      LIKE t001 OCCURS 0 WITH HEADER LINE.
    DATA  : mtext(15)    TYPE c.
    DATA  : it_adrc      LIKE adrc OCCURS 0 WITH HEADER LINE.
    DATA  : it_adrc_ven  LIKE adrc OCCURS 0 WITH HEADER LINE.
    DATA  : it_adrc_plt  LIKE adrc OCCURS 0 WITH HEADER LINE.
    DATA :  it_makt      LIKE makt OCCURS 0 WITH HEADER LINE.
    DATA :  it_eket      LIKE eket OCCURS 0 WITH HEADER LINE.               " Schedulling
    DATA :  it_eikp      LIKE eikp OCCURS 0 WITH HEADER LINE.               " Export
    DATA :  it_t001w     LIKE t001w OCCURS 0 WITH HEADER LINE.
    DATA  : it_t685t     LIKE t685t OCCURS 0 WITH HEADER LINE.
    DATA  : it_t618t     LIKE t618t OCCURS 0 WITH HEADER LINE.
    DATA  : it_t685t_ftr LIKE t685t OCCURS 0 WITH HEADER LINE.
    DATA  : it_lfa1  LIKE lfa1 OCCURS 0 WITH HEADER LINE.
    DATA : it_bapi_mltx_ga LIKE bapi_mltx_ga OCCURS 0 WITH HEADER LINE. "Material long text
    DATA : mfirst   TYPE i  VALUE 0,
           mpay_flag(1) TYPE c VALUE 'X',
           mwerks   LIKE    t001w-werks,
           msr      TYPE i  VALUE 0,
           l_rate   TYPE p  DECIMALS 2  VALUE 0,
           l_amt    TYPE p  DECIMALS 2  VALUE 0,
           mflag(1) TYPE c,
           mlctr    TYPE i  VALUE 0,
           mfamt    TYPE p DECIMALS 2 VALUE 0,
           mcfamt(15) TYPE c,
           mfword(100) TYPE c,
           mkschl   LIKE konv-kschl,
           mchgamt  TYPE p  DECIMALS 2 VALUE 0,
           mkbetr   TYPE p  DECIMALS 2 VALUE 0,
           mkwert   TYPE p  DECIMALS 2 VALUE 0.
    DATA : j_1iexcd     TYPE  j_1imocomp-j_1iexcd,
           j_1icstno    TYPE  j_1imocomp-j_1icstno,
           j_1ilstno    TYPE  j_1imocomp-j_1ilstno.
    DATA : mjmop_r    TYPE p DECIMALS 2 VALUE 0,
           mjmoq_r    TYPE p DECIMALS 2 VALUE 0,
           mjecs_r    TYPE p DECIMALS 2 VALUE 0,
           mjvcs_r    TYPE p DECIMALS 2 VALUE 0,
           mjvrd_r    TYPE p DECIMALS 2 VALUE 0,
           mjsep_r    TYPE p DECIMALS 2 VALUE 0.
    DATA : mjmop_a    TYPE p DECIMALS 2 VALUE 0,
           mjmoq_a    TYPE p DECIMALS 2 VALUE 0,
           mjecs_a    TYPE p DECIMALS 2 VALUE 0,
           mjvcs_a    TYPE p DECIMALS 2 VALUE 0,
           mjvrd_a    TYPE p DECIMALS 2 VALUE 0,
           mjsep_a    TYPE p DECIMALS 2 VALUE 0.
    DATA  : mtitle   LIKE  t161t-batxt.
    DATA :         no_ammend(10),request_by(50),ver_txt(100),ver_reason(100),stext(200).
    begin of Email data declarations**************
    DATA: BEGIN OF otf OCCURS 0.
            INCLUDE STRUCTURE itcoo .
    DATA: END OF otf.
    DATA: itcpo LIKE itcpo.
    DATA: itcpp LIKE itcpp.
    DATA: it_docs  TYPE STANDARD TABLE OF docs,
          v_bin_filesize          TYPE i,
          it_lines TYPE STANDARD TABLE OF tline,
          wa_lines TYPE tline.
    DATA : i_pdf LIKE tline OCCURS 1000 WITH HEADER LINE,
    v_pdf_bytecount TYPE i,
    v_pdf_spoolid TYPE tsp01-rqident,
    v_otf_pagecount TYPE i,
    v_btc_jobname TYPE tbtcjob-jobname,
    v_btc_jobcount TYPE tbtcjob-jobcount.
    DATA: objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
    DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
    DATA: objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
    DATA: reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
    DATA: doc_chng LIKE sodocchgi1.
    DATA: tab_lines LIKE sy-tabix.
    DATA: vafilename(100) VALUE 'po_output.pdf'.
    DATA: jobdata TYPE sxjobdata.
    DATA arc_params TYPE arc_params.
    DATA print_params TYPE pri_params.
    DATA g_send_prog TYPE syrepid VALUE 'ZVF03_TEST_PROG'.
    DATA immediate TYPE btcchar1.
    DATA: i_jobname TYPE tbtcp-jobname,
    i_jobcount TYPE tbtcp-jobcount,
    i_jobstepcount TYPE tbtcp-stepcount.
    DATA recipient_obj LIKE swotobjid.
    CONSTANTS: sx_true TYPE sx_boolean VALUE 'X'.
    TABLES: tbtcp.
    end of Email data declarations**************
    SELECTION-SCREEN : BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS   : mebeln FOR ekko-ebeln OBLIGATORY .               " 75
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 12.
    SELECTION-SCREEN COMMENT (20) text-b01.
    PARAMETERS: b1 AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN : END OF BLOCK block1.
    SELECTION-SCREEN: BEGIN OF SCREEN 200 TITLE text-001 AS WINDOW.
    PARAMETERS :  p_email TYPE ad_smtpadr.     "E-Mail Address
    SELECTION-SCREEN: END OF SCREEN 200.
    INITIALIZATION.
      SET PF-STATUS 'ZMMPORD_STAT'.
    AT SELECTION-SCREEN.
      CASE sy-ucomm.
        WHEN 'EMAIL'.
          PERFORM zemail.
        WHEN '&IC1'.
          PERFORM load_data.
          PERFORM process.
          IF NOT p_email IS INITIAL.
            PERFORM send_mail.
          ENDIF.
      ENDCASE.
    *START-OF-SELECTION.
    PERFORM load_data.
    PERFORM process.
    FORM load_data .
      DATA : gindex LIKE sy-tabix.
      SELECT * FROM t16ct INTO TABLE it_t16ct WHERE spras = 'EN'.
      SELECT * FROM ekko INTO TABLE it_ekko WHERE ebeln IN mebeln.
      IF sy-subrc EQ 0.
        SELECT * FROM erev INTO CORRESPONDING FIELDS OF TABLE it_erev FOR ALL ENTRIES IN it_ekko
        WHERE edokn = it_ekko-ebeln AND rscod <> '' .
        SORT it_erev BY edokn revno DESCENDING.
        LOOP AT it_ekko.
          IF NOT ( it_ekko-frgke EQ 'O'  OR it_ekko-frgke EQ '0' ) .
            MESSAGE e000(zsd) WITH 'Purchase Order is not Realeased'.
          ENDIF.
        ENDLOOP.
        SELECT * FROM ekpo INTO TABLE it_ekpo WHERE ebeln IN mebeln.
        IF sy-subrc EQ 0.
          SELECT * INTO TABLE it_makt
          FROM   makt
          FOR    ALL ENTRIES IN it_ekpo
          WHERE  matnr EQ it_ekpo-matnr.
          SELECT * INTO TABLE it_lfa1
          FROM   lfa1
          FOR    ALL ENTRIES IN it_ekko
          WHERE  lifnr EQ it_ekko-lifnr.
        ENDIF.
        SELECT *
          INTO TABLE it_t052u
          FROM t052u
           FOR ALL ENTRIES IN it_ekko
         WHERE zterm EQ it_ekko-zterm
          AND  spras EQ 'EN'.
        IF sy-subrc EQ 0.
          SORT it_t052u BY zterm.
        ENDIF.
        SELECT * FROM eket INTO TABLE it_eket WHERE ebeln IN mebeln.
        IF sy-subrc EQ 0.
          SORT it_eket BY ebeln ebelp.
        ENDIF.
        SELECT  *
          INTO TABLE it_eikp
          FROM eikp
           FOR ALL ENTRIES IN it_ekko
         WHERE exnum EQ it_ekko-exnum.
        IF sy-subrc EQ 0.
          SORT it_eikp BY exnum.
          SELECT  *
            INTO TABLE it_t618t
            FROM t618t
             FOR ALL ENTRIES IN it_eikp
           WHERE expvz EQ it_eikp-expvz
             AND spras EQ 'E'
             AND land1 EQ 'IN'.
          IF sy-subrc EQ 0.
            SORT it_t618t BY expvz.
          ENDIF.
        ENDIF.
        REFRESH : it_zmm_porder.
        CLEAR   : it_zmm_porder.
        SELECT * INTO TABLE it_zmm_porder
          FROM zmm_porder
         WHERE flag EQ 'L'.
        IF sy-subrc EQ 0.
          SORT it_zmm_porder BY kschl.
        ENDIF.
        SELECT * FROM konv INTO TABLE it_konv
        FOR ALL ENTRIES IN it_ekko
        WHERE knumv = it_ekko-knumv
          AND  kwert NE 0.
        LOOP AT it_konv.
          gindex = sy-tabix.
          READ TABLE it_zmm_porder WITH KEY kschl = it_konv-kschl BINARY SEARCH.
          IF sy-subrc NE 0.
            DELETE it_konv INDEX gindex.
          ENDIF.
        ENDLOOP.
        IF sy-subrc EQ 0.
          SORT it_konv BY knumv kherk kschl.
        ENDIF.
        REFRESH : it_zmm_porder.
        CLEAR   : it_zmm_porder.
        SELECT * INTO TABLE it_zmm_porder
          FROM zmm_porder
         WHERE flag EQ 'F'.
        IF sy-subrc EQ 0.
          SORT it_zmm_porder BY kschl.
        ENDIF.
       SELECT * INTO TABLE IT_KONV_FTR FROM KONV
          FOR ALL ENTRIES IN IT_EKKO
         WHERE KNUMV = IT_EKKO-KNUMV
           AND  ( KSCHL = 'ZIN1'
              OR  KSCHL = 'ZIN2'
              OR  KSCHL = 'ZINS'
              OR  KSCHL = 'ZPF1'
              OR  KSCHL = 'ZPF2'
              OR  KSCHL = 'ZPF3'
              OR  KSCHL = 'ZPKG'
              OR  KSCHL = 'ZPKF'
              OR  KSCHL = 'FRA1'
              OR  KSCHL = 'FRB1'
              OR  KSCHL = 'FRC1'
              OR  KSCHL = 'FRD1'
              OR  KSCHL = 'FRD2'
              OR  KSCHL = 'FRD3'
              OR  KSCHL = 'FRD4'
              OR  KSCHL = 'FRD5'
    *****Added one condition type below ZFBC as on 05.06.2007 :Rajiv as per mail of Sadiq via mathew sir(RTDK906646)
              OR  KSCHL = 'ZFBC' )
           AND  KWERT NE 0
           AND  KPOSN GT '000000'.
          AND ( KRECH = 'B'                       " RTDK906167
           OR  KRECH = 'A' ).
        SELECT * INTO TABLE it_konv_ftr FROM konv
           FOR ALL ENTRIES IN it_ekko
          WHERE knumv = it_ekko-knumv
            AND  kwert NE 0
            AND  kposn GT '000000'.
        LOOP AT it_konv_ftr.
          gindex = sy-tabix.
          READ TABLE it_zmm_porder WITH KEY kschl = it_konv_ftr-kschl BINARY SEARCH.
          IF sy-subrc NE 0.
            DELETE it_konv_ftr INDEX gindex.
          ENDIF.
        ENDLOOP.
        IF it_konv_ftr[] IS NOT INITIAL.
          SORT it_konv_ftr BY knumv kschl.
        ENDIF.
       SELECT  KNUMV KSCHL INTO CORRESPONDING FIELDS OF TABLE IT_KONV1 FROM KONV
       FOR ALL ENTRIES IN IT_EKKO
       WHERE KNUMV = IT_EKKO-KNUMV
           and kherk = 'D'
         AND  ( KSCHL = 'ZIN1'
            OR  KSCHL = 'ZIN2'
            OR  KSCHL = 'ZINS'
            OR  KSCHL = 'ZPF1'
            OR  KSCHL = 'ZPF2'
            OR  KSCHL = 'ZPF3'
            OR  KSCHL = 'ZPKG'
            OR  KSCHL = 'ZPKF'
            OR  KSCHL = 'FRA1'
            OR  KSCHL = 'FRB1'
            OR  KSCHL = 'FRC1'
            OR  KSCHL = 'FRD1'
            OR  KSCHL = 'FRD2'
            OR  KSCHL = 'FRD3'
            OR  KSCHL = 'FRD4'
            OR  KSCHL = 'FRD5'
    *****Added one condition type below ZFBC as on 05.06.2007 :Rajiv as per mail of Sadiq via mathew sir(RTDK906646)
            OR  KSCHL = 'ZFBC' )
         AND  KWERT NE 0.
           AND ( KRECH = 'B'                       RTDK906167
            OR  KRECH = 'A' ).
        SELECT  knumv kschl INTO CORRESPONDING FIELDS OF TABLE it_konv1 FROM konv
        FOR ALL ENTRIES IN it_ekko
        WHERE knumv = it_ekko-knumv
          AND  kwert NE 0.
        DELETE ADJACENT DUPLICATES FROM it_konv1 COMPARING knumv kschl.
        LOOP AT it_konv1.
          gindex = sy-tabix.
          READ TABLE it_zmm_porder WITH KEY kschl = it_konv1-kschl BINARY SEARCH.
          IF sy-subrc NE 0.
            DELETE it_konv1 INDEX gindex.
          ENDIF.
        ENDLOOP.
        IF sy-subrc EQ 0.
          SORT it_konv1 BY knumv kschl.
        ENDIF.
        SELECT * INTO TABLE it_t685t
        FROM   t685t
        FOR    ALL ENTRIES IN it_konv
        WHERE  kschl EQ it_konv-kschl
          AND  kappl EQ it_konv-kappl
          AND  spras EQ 'E'.
        SELECT * INTO TABLE it_t685t_ftr
        FROM   t685t
        FOR    ALL ENTRIES IN it_konv_ftr
        WHERE  kschl EQ it_konv_ftr-kschl
          AND  kappl EQ it_konv_ftr-kappl
          AND  spras EQ 'E'.
        it_t685t_ftr-kschl = 'JVCS'.
        it_t685t_ftr-vtext = 'IN CST in vat'.
        APPEND it_t685t_ftr.
        SELECT * INTO TABLE it_zmm_house_bank
          FROM zmm_house_bank
         WHERE ebeln IN mebeln.
      ELSE.
        MESSAGE e899(mm) WITH 'Data not found for selection criteria...'.
      ENDIF.
    ENDFORM.                    " Load_data
    FORM process .
      DATA : mctr   TYPE i VALUE 1.
      DATA : gindex LIKE sy-tabix.
      DATA : mline(75) TYPE c.
      DATA : mlifn2    LIKE ekpa-lifn2.
      DATA :  mv_name LIKE lfa1-name1,
             madrnr  LIKE lfa1-adrnr.
      CLEAR itcpo.
      itcpo-tdgetotf = 'X'.
      CALL FUNCTION 'OPEN_FORM'
        EXPORTING
          form     = 'ZMM_PORDER'
          language = sy-langu
          OPTIONS  = itcpo
          dialog   = ' '
        EXCEPTIONS
          OTHERS   = 1.
      LOOP AT it_ekko.
        CALL FUNCTION 'START_FORM'
          EXPORTING
            form = 'ZMM_PORDER'.
        SELECT SINGLE *
         FROM  t001
         INTO  it_t001
        WHERE  bukrs EQ it_ekko-bukrs.
        mcompname = it_t001-butxt.
        TRANSLATE mcompname TO UPPER CASE.
        Document Type
        SELECT SINGLE batxt
          INTO mtitle
          FROM t161t
         WHERE bstyp EQ 'F'
         AND   spras EQ 'E'
         AND   bsart EQ it_ekko-bsart.
        REFRESH it_adrc.
        SELECT SINGLE werks
          INTO mwerks
          FROM ekpo
         WHERE ebeln EQ it_ekko-ebeln.
        SELECT SINGLE *
          INTO it_t001w
          FROM t001w
         WHERE werks EQ mwerks.
        REFRESH it_adrc.
        SELECT SINGLE *
          INTO it_adrc_plt
          FROM adrc
         WHERE addrnumber EQ it_t001w-adrnr.
        REFRESH : xt052.
        mfamt  = 0.
        msr    = 0.
    in 500c this statement failed.
       SELECT SINGLE * FROM T052 INTO XT052 WHERE ZTERM = IT_EKKO-ZTERM.
       CALL FUNCTION 'FI_TEXT_ZTERM'
         EXPORTING
           I_T052  = XT052
         TABLES
           T_ZTEXT = ZTEXT.
        As per Preeti... Shipment address should be shown on top as purchase order company address. 27.04.
        PERFORM writeform USING 'PLANT' 'PLANT'.
        SELECT  SINGLE name1 adrnr
          INTO  (mv_name,madrnr)
          FROM  lfa1
         WHERE  lifnr EQ it_ekko-lifnr.
        REFRESH it_adrc[].
        CLEAR   it_adrc[].
        FREE it_adrc[].
        SELECT SINGLE *
          INTO it_adrc_ven
          FROM adrc
         WHERE addrnumber EQ madrnr.
        READ TABLE it_lfa1 WITH KEY lifnr = it_ekko-lifnr.
        PERFORM writeform USING 'VENDOR' 'VENDOR'.
         Shipment
        SELECT SINGLE werks
          INTO mwerks
          FROM ekpo
         WHERE ebeln EQ it_ekko-ebeln.
           up to 1 rows.
        SELECT SINGLE *
          INTO it_t001w
          FROM t001w
         WHERE werks EQ mwerks.
        SELECT SINGLE j_1iexcd j_1icstno j_1ilstno
                 INTO (j_1iexcd,j_1icstno,j_1ilstno)
               FROM    j_1imocomp
                WHERE  werks  = mwerks.
        REFRESH it_adrc.
        SELECT SINGLE *
          INTO it_adrc
          FROM adrc
         WHERE addrnumber EQ it_t001w-adrnr.
        PERFORM writeform USING 'SHIPMNT' 'SHIPMNT'.
        READ TABLE it_eikp WITH KEY exnum = it_ekko-exnum.
        IF sy-subrc EQ 0.
          READ TABLE it_t618t WITH KEY expvz = it_eikp-expvz.
        ENDIF.
        your_ref = it_ekko-ihrez.
        our_ref  = it_ekko-unsez.
        READ TABLE it_erev WITH KEY edokn = it_ekko-ebeln.
        IF sy-subrc = 0.
          no_ammend  = it_erev-revno.
          request_by = it_erev-crnam.
          ver_txt    = it_erev-txz01.
          READ TABLE it_t16ct WITH KEY rscod = it_erev-rscod.
          IF sy-subrc = 0.
            ver_reason = it_t16ct-rstxt.
          ELSE.
            ver_reason = ''.
          ENDIF.
        ELSE.
          no_ammend  = ''.
          request_by = ''.
          ver_txt    = ''.
          ver_reason = ''.
        ENDIF.
        PERFORM writeform USING 'PO_INFO' 'PO_INFO'.
        IF it_zmm_house_bank[] IS NOT INITIAL.
          READ TABLE it_zmm_house_bank INDEX 1.
          PERFORM writeform USING 'BANKDTL' 'BANKDTL'.
        ENDIF.
        PERFORM writeform USING 'HDR_INFO' 'HDR_INFO'.
        PERFORM writeform USING 'BRK_TTL' 'MAIN'.
        msr     = 1.
        mlctr   = 1.
    *added by ganesh to prevent deleted items to appear in print out
       LOOP AT IT_EKPO WHERE EBELN EQ IT_EKKO-EBELN.
        LOOP AT it_ekpo WHERE ebeln EQ it_ekko-ebeln AND loekz NE 'L'.
    *end of change
          CLEAR: mrate, mrate1.
          SELECT * FROM konv INTO TABLE it_konv_rate
                   WHERE knumv EQ it_ekko-knumv
                   AND   kposn EQ it_ekpo-ebelp
                   AND  ( kschl EQ 'PBXX' OR kschl EQ 'PB00'  OR kschl EQ 'P001' ).
          LOOP AT it_konv_rate.
           IF it_konv_rate-kpein > 0.             " added by ganesh as per sudhir 12.10.2007
             mrate_gm = it_konv_rate-kbetr / it_konv_rate-kpein.
             mrate  = mrate + mrate_gm. " added by ganesh as per sudhir 12.10.2007
           ELSE.
            mrate  = mrate + it_konv_rate-kbetr.
           ENDIF.
            IF it_konv_rate-waers IS NOT INITIAL.
              mwaers = it_konv_rate-waers.
            ENDIF.
          ENDLOOP.
        For Japanies Yen   "RTDK906759
          IF it_ekko-waers = 'JPY'.
            mrate = mrate * 100.
          ENDIF.
        End for japanies Yen
          mrate1 = mrate.
               End rate
          mfirst  = 0.
                MFAMT  = MFAMT + ( IT_EKPO-NETPR * IT_EKPO-MENGE ).
          mfamt  = mfamt + ( mrate * it_ekpo-menge ).
          PERFORM get_mat_long_text.
          DATA: lt_ctr TYPE i VALUE 0,lt_ctr1 TYPE i, lt_count TYPE i VALUE 0. " Long text counter
          DESCRIBE TABLE it_bapi_mltx_ga LINES lt_count.
          CLEAR it_bapi_mltx_ga.
    *Added by Rajiv 10.05.2007 Read and if condition RTDK906165
          READ TABLE it_konv WITH KEY knumv = it_ekko-knumv
                                      kposn = it_ekpo-ebelp.
          mkbetr  = 0.
          mkwert  = 0.
          IF sy-subrc EQ 0.
            LOOP AT it_konv  WHERE knumv EQ it_ekko-knumv
                               AND kposn EQ it_ekpo-ebelp.
              IF it_konv-krech EQ 'A'.
                mkbetr  = it_konv-kbetr / 10.
              ELSE.
                mkbetr  = it_konv-kbetr.
              ENDIF.
            For Japanies Yen "RTDK906759
              IF it_ekko-waers = 'JPY'.
                mkbetr = mkbetr * 100.
              ENDIF.
            End for japaies Yen
              IF mkbetr LT '0'.
                mkbetr = mkbetr * ( -1 ).
              ENDIF.
              mkwert   = it_konv-kwert.
            For Japanies Yen "RTDK906759
              IF it_ekko-waers = 'JPY'.
                mkwert = mkwert * 100.
              ENDIF.
            End for japaies Yen
              mfamt  = mfamt + mkwert.
              IF mkwert LT '0'.
                mkwert = mkwert * ( -1 ).
              ENDIF.
              IF it_ekpo-matnr IS INITIAL.
                itemname = it_ekpo-txz01.
              ELSE.
                READ TABLE it_makt  WITH KEY matnr = it_ekpo-matnr.
                itemname = it_makt-maktx.
              ENDIF.
              READ TABLE it_t685t WITH KEY kschl = it_konv-kschl BINARY SEARCH.
              READ TABLE it_eket  WITH KEY ebeln = it_ekpo-ebeln
                                           ebelp = it_ekpo-ebelp BINARY SEARCH.
              IF mfirst EQ 0.
                PERFORM writeform USING 'BRK_INFO' 'MAIN'.
                mfirst = 1.
              ELSE.
                ADD 1 TO lt_ctr.
                CLEAR it_bapi_mltx_ga.
                READ  TABLE it_bapi_mltx_ga INDEX lt_ctr. "For long text
                IF sy-subrc NE 0.
                  CLEAR it_bapi_mltx_ga.
                ENDIF.
                PERFORM writeform USING 'BRK_INFO1' 'MAIN'.
              ENDIF.
              mlctr = mlctr + 1.
            ENDLOOP.               "   it_konv.
          ELSE.
            IF it_ekpo-matnr IS INITIAL.
              itemname = it_ekpo-txz01.
            ELSE.
              READ TABLE it_makt  WITH KEY matnr = it_ekpo-matnr.
              itemname = it_makt-maktx.
            ENDIF.
                        READ TABLE IT_T685T WITH KEY KSCHL = IT_KONV-KSCHL BINARY SEARCH.
            READ TABLE it_eket  WITH KEY ebeln = it_ekpo-ebeln
                                         ebelp = it_ekpo-ebelp BINARY SEARCH.
            mfirst = 0.
            IF mfirst EQ 0.
              PERFORM writeform USING 'BRK_INFO' 'MAIN'.
              mfirst = 1.
            ELSE.
              ADD 1 TO lt_ctr.
              CLEAR it_bapi_mltx_ga.
              READ  TABLE it_bapi_mltx_ga INDEX lt_ctr. "For long text
              IF sy-subrc NE 0.CLEAR it_bapi_mltx_ga.ENDIF.
              PERFORM writeform USING 'BRK_INFO1' 'MAIN'.
            ENDIF.
          ENDIF.
    *Commented by rajiv 10.05.2007 used this code in above condition.
    added by ganesh on 260407 to print record
                if it_konv is initial.
                        READ TABLE IT_MAKT  WITH KEY MATNR = IT_EKPO-MATNR.
                        READ TABLE IT_T685T WITH KEY KSCHL = IT_KONV-KSCHL BINARY SEARCH.
                        READ TABLE IT_EKET  WITH KEY EBELN = IT_EKPO-EBELN
                                                     EBELP = IT_EKPO-EBELP BINARY SEARCH.
                        mFirst = 0.
                        if mFirst eq 0.
                             PERFORM WRITEFORM USING 'BRK_INFO' 'MAIN'.
                             mFirst = 1.
                        else.
                             add 1 to lt_ctr.
                             clear it_bapi_mltx_ga.
                             read  table IT_BAPI_MLTX_GA index lt_ctr. "For long text
                             if sy-subrc ne 0.clear it_bapi_mltx_ga.endif.
                             PERFORM WRITEFORM USING 'BRK_INFO1' 'MAIN'.
                        Endif.
                endif.
    end of change
          REFRESH it_komv_tax.
          PERFORM get_tax_cal USING it_ekpo-ebeln
                                    it_ekpo-ebelp.
                                 Changing it_komv_tax.
          REFRESH : it_zmm_porder.
          CLEAR   : it_zmm_porder.
          SELECT * INTO TABLE it_zmm_porder
            FROM zmm_porder
           WHERE flag EQ 'T'.
          IF sy-subrc EQ 0.
            SORT it_zmm_porder BY kschl.
          ENDIF.
          LOOP AT it_komv_tax.
            gindex = sy-tabix.
            READ TABLE it_zmm_porder WITH KEY kschl = it_komv_tax-kschl BINARY SEARCH.
            IF sy-subrc NE 0.
              DELETE it_komv_tax INDEX gindex.
            ENDIF.
          ENDLOOP.
          LOOP AT it_komv_tax WHERE kwert IS NOT INITIAL.
           IF ( IT_KOMV_TAX-KSCHL EQ 'JMOP' OR
                IT_KOMV_TAX-KSCHL EQ 'JECS' OR
                IT_KOMV_TAX-KSCHL EQ 'JSEP' OR
                IT_KOMV_TAX-KSCHL EQ 'JMOQ' OR
                IT_KOMV_TAX-KSCHL EQ 'JVCS' OR
                IT_KOMV_TAX-KSCHL EQ 'JVRD' OR
                IT_KOMV_TAX-KSCHL EQ 'JMIP' OR
    *             IT_KOMV_TAX-KSCHL EQ 'JEIP' OR
                IT_KOMV_TAX-KSCHL EQ 'JSEI' OR
                IT_KOMV_TAX-KSCHL EQ 'JSRT' OR
                IT_KOMV_TAX-KSCHL EQ 'JEC3' OR
                IT_KOMV_TAX-KSCHL EQ 'JVRN' )
                AND IT_KOMV_TAX-KWERT IS NOT INITIAL.
            SELECT SINGLE vtext
                   INTO   mtext
                   FROM   t685t
                  WHERE   kschl EQ it_komv_tax-kschl
                    AND   spras EQ 'E'.
            l_rate    = it_komv_tax-kbetr / 10.
            l_amt     = it_komv_tax-kwert.
            For Japanies Yen "RTDK906759
            IF it_ekko-waers = 'JPY'.
              l_amt = l_amt * 100.
            ENDIF.
            End for japaies Yen
            ADD l_amt TO mfamt.
            IF lt_ctr LT lt_count. "Long text
              ADD 1 TO lt_ctr.
              READ TABLE it_bapi_mltx_ga INDEX lt_ctr.
            ELSE.
              CLEAR it_bapi_mltx_ga.
            ENDIF.
            IF l_rate EQ 0 OR l_amt EQ 0.
              l_rate = ''.
              l_amt  = ''.
            ENDIF.
            PERFORM writeform USING 'TAX_LINE_ITEM' 'MAIN'.
           ENDIF.
          ENDLOOP.
          IF lt_ctr LT lt_count.
            DATA mbal_line TYPE i.
            mbal_line = ( lt_count - lt_ctr ).
            DO mbal_line TIMES.
              ADD 1 TO lt_ctr.
              READ TABLE it_bapi_mltx_ga INDEX lt_ctr.
              IF sy-subrc = 0.
                PERFORM writeform USING 'LTEXT' 'MAIN'.
              ENDIF.
            ENDDO.
          ENDIF.
          CONCATENATE it_ekko-ebeln it_ekpo-ebelp INTO nmebeln.
          REFRESH tline.
          CALL FUNCTION 'READ_TEXT'
            EXPORTING
              id                      = 'F04'
              language                = sy-langu
              name                    = nmebeln
              object                  = 'EKPO'
            TABLES
              lines                   = tline
            EXCEPTIONS
              id                      = 1
              language                = 2
              name                    = 3
              not_found               = 4
              object                  = 5
              reference_check         = 6
              wrong_access_to_archive = 7
              OTHERS                  = 8.
          IF sy-subrc <> 0.
          ENDIF.
          LOOP AT tline.
            IF tline-tdline IS NOT INITIAL.
              del_text = tline-tdline.
            ENDIF.
            CONDENSE del_text.
          ENDLOOP.
          CONCATENATE it_ekko-ebeln it_ekpo-ebelp INTO nmebeln.
          REFRESH tline.
          CALL FUNCTION 'READ_TEXT'
            EXPORTING
              id                      = 'F03'
              language                = sy-langu
              name                    = nmebeln
              object                  = 'EKPO'
            TABLES
              lines                   = tline
            EXCEPTIONS
              id                      = 1
              language                = 2
              name                    = 3
              not_found               = 4
              object                  = 5
              reference_check         = 6
              wrong_access_to_archive = 7
              OTHERS                  = 8.
          IF sy-subrc <> 0.
                 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
               refresh.
          CLEAR : po_flag, mat_po_text.
          LOOP AT tline.
            IF tline-tdline IS NOT INITIAL.
              MOVE tline-tdline TO mat_po_text.
              CONDENSE mat_po_text.
              PERFORM writeform USING 'MTRL_PO_TEXT' 'MAIN'.
              po_flag = 'X'.
              CLEAR : mat_po_text.
            ENDIF.
          ENDLOOP.
    *Added lines below for Schedule delivery for line item on 09.05.2007:Rajiv
          CLEAR g_ind.
          READ TABLE it_eket  WITH KEY ebeln = it_ekpo-ebeln
                                       ebelp = it_ekpo-ebelp BINARY SEARCH.
          g_ind = sy-tabix.
          LOOP AT it_eket FROM g_ind.
            IF it_eket-ebeln EQ it_ekpo-ebeln AND it_eket-ebelp = it_ekpo-ebelp.
              PERFORM writeform USING 'SCHEDULE' 'MAIN'.
            ELSE.
              EXIT.
            ENDIF.
          ENDLOOP.
    *End Addition:Rajiv
          PERFORM writeform USING 'REQSLP' 'MAIN'.
          mlctr = mlctr + 1.
          msr = msr + 1.
          CLEAR: lt_ctr, lt_ctr1.
      following lines added by ganesh to add service po details as per Mr. sadiq 21.08.2007
          IF it_ekpo-packno IS NOT INITIAL.
            CLEAR sub_packno.
            SELECT SINGLE sub_packno INTO sub_packno FROM esll WHERE packno = it_ekpo-packno.
            IF sub_packno IS NOT INITIAL.
              CLEAR it_esll.
              REFRESH it_esll.
              SELECT * FROM esll INTO CORRESPONDING FIELDS OF TABLE it_esll
              WHERE packno = sub_packno.
              IF sy-subrc = 0.
                PERFORM writeform USING 'SERVICE_PO_TEXT' 'MAIN'.
              ENDIF.
              LOOP AT it_esll.
                CONCATENATE sub_packno it_esll-introw INTO obj.
                CALL FUNCTION 'READ_TEXT'   "4500002446  C300
                  EXPORTING
                    id       = 'LTXT'
                    language = sy-langu
                    name     = obj
                    object   = 'ESLL'
                  TABLES
                    lines    = tline
                  EXCEPTIONS
                    id                      = 1
                    language                = 2
                    name                    = 3
                    not_found               = 4
                    object                  = 5
                    reference_check         = 6
                    wrong_access_to_archive = 7
                    OTHERS                  = 8.
                IF sy-subrc <> 0.
                ENDIF.
                CLEAR stext.
                LOOP AT tline.
                  CONCATENATE stext tline-tdline  INTO stext SEPARATED BY space.
                ENDLOOP.
                FREE tline.
                CLEAR tline.
                REFRESH tline.
                PERFORM writeform USING 'SERVICE_PO' 'MAIN'.
                PERFORM writeform USING 'SERVICE_TEXT' 'MAIN'.
              ENDLOOP.
            ENDIF.
          ENDIF.
        end of change
        ENDLOOP.             " it_ekpo.
        IF mlctr < 15.
          DO 5 TIMES.
            PERFORM writeform USING 'LINEFEED' 'MAIN'.
          ENDDO.
        ENDIF.
        added by ganesh  for allding line before ECC No.
        IF it_ekko-bsart NE 'ZIM'.               " IF EXPORT NO NEED TO PRINT ECC.
          PERFORM writeform USING 'LIN' 'MAIN'.
          PERFORM writeform USING 'WERKS_TAX_DETAIL' 'MAIN'.
        ENDIF.
        end of change
         MFLAG = 'Y'.
        PERFORM writeform USING 'TERMS_VAL' 'MAIN'.
        LOOP AT it_konv1 WHERE knumv EQ it_ekko-knumv.
          mkschl = it_konv1-kschl.
          mchgamt = 0.
          LOOP AT it_konv_ftr  WHERE knumv EQ it_konv1-knumv
                               AND kschl EQ mkschl.
            mchgamt = mchgamt + it_konv_ftr-kwert.
          ENDLOOP.
            For Japanies Yen "RTDK906759
          IF it_ekko-waers = 'JPY'.
            mchgamt = mchgamt * 100.
          ENDIF.
            End for japaies Yen
          mfamt = mfamt + mchgamt.
          IF mchgamt LT '0'.
            mchgamt = mchgamt * ( -1 ).
          ENDIF.
          READ TABLE it_t685t_ftr WITH KEY kschl = mkschl.
          PERFORM writeform USING 'TERMS_FTR_VAL' 'MAIN'.
          mlctr = mlctr + 1.
        ENDLOOP.
        mflag = 'T'.
        CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
          EXPORTING
            amt_in_num         = mfamt
          IMPORTING
            amt_in_words       = mfword
          EXCEPTIONS
            data_type_mismatch = 1
            OTHERS             = 2.
        CONDENSE mebeln.
        nmebeln = it_ekko-ebeln.
        REFRESH tline.
        CALL FUNCTION 'READ_TEXT'
          EXPORTING
            id                      = 'F01'
            language                = sy-langu
            name                    = nmebeln
            object                  = 'EKKO'
          TABLES
            lines                   = tline
          EXCEPTIONS
            id                      = 1
            language                = 2
            name                    = 3
            not_found               = 4
            object                  = 5
            reference_check         = 6
            wrong_access_to_archive = 7
            OTHERS                  = 8.
        IF sy-subrc <> 0.
        ENDIF.
    *---- CHANGED BY MATHEW BECAUSE THIS STATMENT WORKING FINE IN 300 BUT NOT IN 500C.
       LOOP AT ZTEXT.
         IF ZTEXT-TEXT1 IS NOT INITIAL.
           PERFORM WRITEFORM USING 'TERMS_COND_VAL_PAY' 'MAIN'.
         ENDIF.
         MPAY_FLAG = 'Y'.
       ENDLOOP.
        READ TABLE it_t052u WITH KEY zterm = it_ekko-zterm.
        LOOP AT it_t052u WHERE zterm EQ it_ekko-zterm.
          IF it_t052u-text1 IS NOT INITIAL.
            PERFORM writeform USING 'TERMS_COND_VAL_PAY' 'MAIN'.
          ENDIF.
          mpay_flag = 'Y'.
        ENDLOOP.
        PERFORM writeform USING 'TERMS_COND_VAL' 'MAIN'.
        LOOP AT tline.
          IF tline-tdline IS NOT INITIAL.
            PERFORM writeform USING 'TERMS_COND_VAL_HDR' 'MAIN'.
          ENDIF.
          CONDENSE txt.
        ENDLOOP.
        PERFORM writeform USING 'FTR' 'FTR_LIN3'.
        PERFORM writeform USING 'FTR_LIN1' 'FTR_LIN1'.
        CALL FUNCTION 'END_FORM'.
      ENDLOOP.                    "   It_ekko.
      CALL FUNCTION 'CLOSE_FORM'
       IMPORTING
       RESULT                         = itcpp
      RDI_RESULT                     =
       TABLES
         otfdata                        = otf
       EXCEPTIONS
         unopened                       = 1
         bad_pageformat_for_print       = 2
         send_error                     = 3
         spool_error                    = 4
         codepage                       = 5
         OTHERS                         = 6.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " Process
    *&      Form  WRITEFORM
          text
         -->P_0150   text
         -->P_0151   text
    FORM writeform  USING    value(p_0150)
                             value(p_0151).
      CALL FUNCTION 'WRITE_FORM'

    Hi
    I think some basis related configuartions to be done
    Try like this and inform me
    A cyclic job runs, which processes the messages seen in the SOST queue.
    Are you sure it's not the frequency of the cyclic job, rather than the
    number of messages in the queue, that you are observing? In messages
    that are queued and before the cyclic job runs, "wait for comm. service"
    is the normal status.
    If you mean that there are always 4 items queued in SOST regardless of
    the cyclic send job, then I have no ideas. I would have thought there
    was no way to do that.
    when the send job runs it just never
    picks them up & sends them, while it picks up many others. The send job
    is somehow blind to these; no error message occurs. In this case, I
    'delete' them from the queue (in SOST) and then 'undelete' (drop down
    menu -> /Go to /Deleted Items) them and then re-queue them. THEN they
    actually get picked up & sent when the next cyclic send job executes.
    Regards
    Pavan

  • Very urjent how to send report output in mail

    hi experts,
    how to send report output in mail which function module should i use wht parameters should i pass.
    thanks in addavnce,
    points to be awarded.

      CALL FUNCTION 'GET_PRINT_PARAMETERS'
           EXPORTING
                destination    = '026c'
                copies         = count
                list_name      = 'VATS_ASBUILT'
                list_text      = v_list
                immediately    = 'X'
                release        = 'X'
                new_list_id    = 'X'
                expiration     = days
                line_size      = 132
                line_count     = 65
                layout         = 'X_65_132'
    *            sap_cover_page = 'X'
    *            cover_page     = 'X'
                receiver       = 'SAP*'
                department     = 'VATS'
                no_dialog      = 'X'
           IMPORTING
                out_parameters = params
                valid          = valid.
      SUBMIT zppr_vats_asbuilt  WITH p_aufnr EQ v_aufnr
                   TO SAP-SPOOL WITHOUT SPOOL DYNPRO
                      SPOOL PARAMETERS params
                         AND RETURN.
      SELECT SINGLE rqident FROM tsp01 INTO l_spoolno
                         WHERE rqtitle = v_list .
    * convert report to PDF format
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid              = l_spoolno
                no_dialog                = 'X'
           TABLES
                pdf                      = l_ipdf
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 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.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        EXIT .
      ENDIF.
    Now comes the part to send the mail
      try.
    * -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
          clear document.
    * -------- create and set document with attachment ---------------
    * create document from internal table with text
          document = cl_document_bcs=>create_document(
          i_type = 'RAW'
          i_text = text
          i_length = '12'
          i_subject = '' ).
    *changing the content of the attachment
          binary_content[] = l_iobjbin[].
    *change the name of the PDF attachment
          concatenate 'Build ID' s_buildid_i 'Rev' v_buildid_rev
                              into i_att_sub separated by space.
    * add attachment to document
          call method document->add_attachment
            exporting
              i_attachment_type    = 'PDF'
              i_attachment_subject = i_att_sub
              i_att_content_hex    = binary_content.
    *setting the option to send an e-mail more than 50 characters
          call method send_request->set_message_subject
            exporting
              ip_subject = t_sub.
    * add document to send request
          call method send_request->set_document
            exporting
              i_document = document.
    * --------- set sender -------------------------------------------
    * note: this is necessary only if you want to set the sender
    * different from actual user (SY-UNAME). Otherwise sender is
    * set automatically with actual user.
          sender = cl_sapuser_bcs=>create( 'VATSUPPORT' ).
          call method send_request->set_sender
            exporting
              i_sender = sender.
    *Send the list based on receivers list obtained
          loop at l_ireclist.
            AD_SMTPADR = l_ireclist-receiver.
    * --------- add recipient (e-mail address) -----------------------
    * create recipient - please replace e-mail address !!!
          recipient = cl_cam_address_bcs=>create_internet_address(
          AD_SMTPADR ).
    * add recipient with its respective attributes to send request
          call method send_request->add_recipient
            exporting
              i_recipient = recipient
              i_express   = 'X'.
          ENDLOOP.
          call method send_request->set_status_attributes
            exporting
              i_requested_status = 'E'
              i_status_mail      = 'E'.
    * To send the mail immediately
          call method send_request->set_send_immediately( 'X' ).
    * ---------- send document ---------------------------------------
          call method send_request->send( ).
          commit work.

  • Mail and email attachement : .pdf - .pdfpdf or .doc - .docc

    Hello,
    I have been using Mail since I bought my Mac but I have a recurrent problem.
    When I send a Mail with email attachement, it duplicates the extension. For instance : .doc become .docc, or .pdf become .pdfpdf.
    I tried some manipulations such as : Check or not : "Mask File Extension" in "File Information", and :"Send email attachement Windows compatible" in Mail : the results are the same.
    The last straw ? When I try with Gmail or Orange in Safari, the attachements work well and my contacts can read them.
    I don't understand.
    I will appreciate any answer.
    Thanks
    (Sorry for my English )

    Are you sure it is Mail sending them wrong and not their email client mangling them when they arrive?
    It is apparently Mail's fault. It has to do with sending attachments with accented characters. While this a poor workaround for you, don't use accented characters in attachment names until Apple fixes it. Or add a message to your email to save the attachment and fix the extension. If they do that, it will open just fine.
    Message was edited by: Barney-15E

  • Changing the seeded rdf report output from text to PDF

    Hi All,
    I am trying to change the seeded report "Print Requisition Report" output from text to PDF. I changed the output format in the concurrent program definition from text to pdf. The report is now getting displayed in pdf format, but the alignment of the fields are changed. The output is not printing as it was printing while in the text output format. The output looks very sloppy, with uneven fonts and too much of text wrapping.
    I tried some formatting and fields are somehow getting displayed but doesnt look in proper format. I am not able to change the font style in the report builder 6i, even if i change it is printing in the same font style with uneven font size. I think reducing the font size might help, but i am unable to change.We are on 11.5.10.2. Please provide your valuable suggestions on how to go about.
    Thanks
    Sarvesh

    Hi Hussein,
    Thanks for the information. After the adjustments in the layout and the font change the report is now getting displayed without any clipping when clicked on view output. But when the same report is printed some characters on the left and and right side is getting clipped. Please help on how to solve this issue.
    Thanks,
    Sarvesh

  • How do I save my exported doc in order to send it as an email attachment?

    how do I save my exported doc in order to send it as an email attachment?

    Plug your ipod in and pull up itunes. Then click on the device name in the left hand side. Click the restore option. When it goes all the way through and says "your device has been restored and is restarting, once it restarts you want to choose the option that says "setup as a new device"

  • Can you send slideshows as an email attachment?

    can you send slideshows as an email attachment? Please provide the steps if it is possible, thank you

    Yes, but you shouldn't.
    Here's how.
    Export the Slideshow to the FInder - a process that will make a QuickTime movie of it.
    Attach that movie to the email. Send
    Why not? Videos are very large files. Most Internet providers have a limit on the largest file you can send. Sending one too large means it can bounce back to you. ALso, even if the other person can receive it, downloading large files via email is slow, and can even cause crashes on some email apps on older systems.
    Intead of emailing it, upload it to DropBox, YouTube, Vimeo, or any other sharing site and send the person a link.
    Then they can download it themselves
    Regards
    TD

Maybe you are looking for

  • Hp Laserjet 8150n will not install on windows xp

    computer went to the shop and operating system was replaced and now my printer will not reinstall. windows xp and a hp laserjet 8150n printer. printer is on the network and recognized by 3 other computers. cabled network loaded printer software to 64

  • Horizontal Scrolling - Illustrator CC

    Hello, I just updated from illustrator CS6 to CC but now i can´t do horizontal scrolling, instead of going horizontaly it goes verticaly but faster than the normal horizontal scroll. Is there a way to reactivate horizontal scrolling without pressing

  • HDMI Info screen pops-up every 5 seconds

    I have a Dynex 42" TV I bought last fall.  No problems until I connected it to me Media Center PC, which has a nVidia card.  When playing a recorded movie, I get the annoying grey announcement box that I'm on HDMI 1 about every 5 seconds.  I tried sw

  • Bootcamp Question? Should I update bootcamp before installing Vista SP1

    Hi, I am about to install Vista SP1 on iMac, Leopard 10.5.4. About a month back, there was a bootcamp update that had been posted on support download website. The question is; Do I need to install the Update before installing Vista or is that needs t

  • Camileo charging problem (solved) and a general question!

    Hi all! First of all, I was going to ask for help as to why the Camileo S10 was not charging (the orange light wasn't flashing), and I'd seen a few people with similar problems. The solution? Give the contacts on the battery a clean. The insulation s